Add nolint-insert script to auto-comment lint violations
Step 1: mark a function as deprecated Step 2: run `script/nolint-insert` Step 3: all callers of that function now have a `//nolint` directive
This commit is contained in:
parent
5c2ee024a2
commit
9f46def1a8
1 changed files with 24 additions and 0 deletions
24
script/nolint-insert
Executable file
24
script/nolint-insert
Executable file
|
|
@ -0,0 +1,24 @@
|
|||
#!/bin/bash
|
||||
# Usage: script/nolint-insert
|
||||
# script/nolint-insert 'nolint:staticcheck // <explanation>'
|
||||
set -e
|
||||
|
||||
insert-line() {
|
||||
local n=$'\n'
|
||||
sed -i.bak "${2}i\\${n}${3}${n}" "$1"
|
||||
rm "$1.bak"
|
||||
}
|
||||
|
||||
reverse() {
|
||||
awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }'
|
||||
}
|
||||
|
||||
comment="${1}"
|
||||
|
||||
golangci-lint run --out-format json | jq -r '.Issues[] | [.Pos.Filename, .Pos.Line, .FromLinter, .Text] | @tsv' | reverse | while IFS=$'\t' read -r filename line linter text; do
|
||||
directive="nolint:${linter} // $text"
|
||||
[ -z "$comment" ] || directive="$comment"
|
||||
insert-line "$filename" "$line" "//${directive}"
|
||||
done
|
||||
|
||||
go fmt ./...
|
||||
Loading…
Add table
Add a link
Reference in a new issue