Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ineffassign #106

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v0.7.1
repos:
- repo: https://github.com/jessp01/pre-commit-golang.git
rev: v0.5.3
hooks:
- id: check-merge-conflict
- id: check-yaml
- id: end-of-file-fixer
- id: trailing-whitespace
- id: go-fmt
- id: go-imports
- id: go-vet
- id: go-lint
- id: go-critic
- id: go-ineffassign
6 changes: 6 additions & 0 deletions .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,9 @@
files: '\.go$'
language: 'script'
description: "Runs `go mod vendor`, requires golang"
- id: go-ineffassign
name: 'go ineffassign'
entry: run-go-ineffassign.sh
files: '\.go$'
language: 'script'
description: "Runs `ineffassign`, requires ineffassign"
24 changes: 24 additions & 0 deletions run-go-ineffassign.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash

set -eu -o pipefail

BIN=ineffassign
if ! command -v $BIN &> /dev/null ; then
echo "$BIN not installed or available in the PATH" >&2
echo "please run 'go install github.com/gordonklaus/ineffassign@latest'" >&2
exit 1
fi

failed=false

for file in "$@"; do
# redirect stderr so that violations and summaries are properly interleaved.
if ! $BIN "$file" 2>&1
then
failed=true
fi
done

if [[ $failed == "true" ]]; then
exit 1
fi
6 changes: 3 additions & 3 deletions run-go-vet.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env bash
set -e
set -ex
pkg=$(go list)
for dir in $(echo $@|xargs -n1 dirname|sort -u); do
go vet $pkg/$dir
for dir in $(echo "$@"|xargs -n1 dirname|sort -u); do
go vet "$pkg/$dir"
done