golangci-lint: suppress one issue, demote others to "hints"

The voting in https://github.com/kubernetes/kubernetes/issues/117288 led to
one check that got rejected ("ifElseChain: rewrite if-else to switch
statement") and several that are "nice to know".

golangci-lint's support for issue "severity" is too limited to identify "nice
to know" issues in the output (filtering is only by linter without considering
the issue text; not part of text output). Therefore a third configuration gets
added which emits all issues (must fix and nits). The intention is to use
the "strict" configuration in pull-kubernetes-verify and the "hints"
configuration in a new non-blocking pull-kubernetes-linter-hints.

That way, "must fix" issues will block merging while issues that may be useful
will show up in a failed optional job. However, that job then also contains
"must fix" issues, partly because filtering out those would make the
configuration a lot larger and is likely to be unreliably (all "must fix"
issues would need to be identified and listed), partly because it may be useful
to have all issues in one place.

The previous approach of manually keeping two configs in sync with special
comments didn't scale to three configs. Now a single golangci.yaml.in with
text/template constructs contains the source for all three configs. A new
simple CLI frontend for text/template (cmd/gotemplate) is used by
hack/update-golangci-lint-config.sh to generate the three flavors.
This commit is contained in:
Patrick Ohly
2023-06-06 13:15:11 +02:00
parent 6a16c076e7
commit ce9e668a93
11 changed files with 696 additions and 51 deletions

View File

@@ -14,30 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.
# This script checks that golangci-strict.yaml and golangci.yaml remain in
# sync. Lines that are intentionally different must have a comment which
# mentions golangci.yaml or golangci-lint.yaml.
# This script checks that all generated golangci-lint configurations
# are up-to-date.
set -o errexit
set -o nounset
set -o pipefail
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
source "${KUBE_ROOT}/hack/lib/verify-generated.sh"
if differences=$(diff --context --ignore-blank-lines \
--ignore-matching-lines='^ *#' \
--ignore-matching-lines='#.*golangci\(-strict\)*.yaml' \
"${KUBE_ROOT}/hack/golangci.yaml" "${KUBE_ROOT}/hack/golangci-strict.yaml" ); then
echo "hack/golangci.yaml and hack/golangci-strict.yaml are synchronized."
else
cat >&2 <<EOF
Unexpected differences between hack/golangci.yaml and hack/golangci-strict.yaml:
${differences}
If these differences are intentional, then add comments at the end of each
different line in both files that mention golangci-strict.yaml or
golangci.yaml.
EOF
exit 1
fi
kube::verify::generated "" "Please run 'hack/update-golangci-lint-config.sh'" hack/update-golangci-lint-config.sh