github.com/ungtb10d/cli/v2@v2.0.0-20221110210412-98537dd9d6a1/script/nolint-insert (about)

     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 ./...