Skip to content

Commit 0a6dc76

Browse files
authored
Merge pull request cli#5043 from cli/nolint-insert
Add `nolint-insert` script to mark current lint violations as allowed
2 parents a3f0940 + 9f46def commit 0a6dc76

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

script/nolint-insert

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
# Usage: script/nolint-insert
3+
# script/nolint-insert 'nolint:staticcheck // <explanation>'
4+
set -e
5+
6+
insert-line() {
7+
local n=$'\n'
8+
sed -i.bak "${2}i\\${n}${3}${n}" "$1"
9+
rm "$1.bak"
10+
}
11+
12+
reverse() {
13+
awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }'
14+
}
15+
16+
comment="${1}"
17+
18+
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
19+
directive="nolint:${linter} // $text"
20+
[ -z "$comment" ] || directive="$comment"
21+
insert-line "$filename" "$line" "//${directive}"
22+
done
23+
24+
go fmt ./...

0 commit comments

Comments
 (0)