mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-26 04:36:00 +00:00
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:
@@ -26,6 +26,8 @@ Usage: $0 [-r <revision>|-a] [-s] [-c none|<config>] [-- <golangci-lint run flag
|
||||
-a: automatically select the common base of origin/master and HEAD
|
||||
as revision
|
||||
-s: select a strict configuration for new code
|
||||
-n: in addition to strict checking, also enable hints (aka nits) that may are may not
|
||||
be useful
|
||||
-g <github action file>: also write results with --out-format=github-actions
|
||||
to a separate file
|
||||
-c <config|"none">: use the specified configuration or none instead of the default hack/golangci.yaml
|
||||
@@ -65,8 +67,9 @@ golangci=(env LOGCHECK_CONFIG="${KUBE_ROOT}/hack/logcheck.conf" "${GOBIN}/golang
|
||||
golangci_config="${KUBE_ROOT}/hack/golangci.yaml"
|
||||
base=
|
||||
strict=
|
||||
hints=
|
||||
githubactions=
|
||||
while getopts "ar:sg:c:" o; do
|
||||
while getopts "ar:sng:c:" o; do
|
||||
case "${o}" in
|
||||
a)
|
||||
base="$(git merge-base origin/master HEAD)"
|
||||
@@ -83,6 +86,10 @@ while getopts "ar:sg:c:" o; do
|
||||
golangci_config="${KUBE_ROOT}/hack/golangci-strict.yaml"
|
||||
strict=1
|
||||
;;
|
||||
n)
|
||||
golangci_config="${KUBE_ROOT}/hack/golangci-hints.yaml"
|
||||
hints=1
|
||||
;;
|
||||
g)
|
||||
githubactions="${OPTARG}"
|
||||
;;
|
||||
@@ -192,9 +199,17 @@ else
|
||||
echo 'If the above warnings do not make sense, you can exempt this warning with a comment'
|
||||
echo ' (if your reviewer is okay with it).'
|
||||
if [ "$strict" ]; then
|
||||
echo 'The more strict golangci-strict.yaml was used. If you feel that this warns about issues'
|
||||
echo 'that should be ignored by default, then please discuss with your reviewer and propose'
|
||||
echo 'a change for hack/golangci-strict.yaml as part of your PR.'
|
||||
echo 'The more strict golangci-strict.yaml was used.'
|
||||
elif [ "$hints" ]; then
|
||||
echo 'The golangci-hints.yaml was used. Some of the reported issues may have to be fixed'
|
||||
echo 'while others can be ignored, depending on the circumstances and/or personal'
|
||||
echo 'preferences. To determine which issues have to be fixed, check the report that'
|
||||
echo 'uses golangci-strict.yaml.'
|
||||
fi
|
||||
if [ "$strict" ] || [ "$hints" ]; then
|
||||
echo 'If you feel that this warns about issues that should be ignored by default,'
|
||||
echo 'then please discuss with your reviewer and propose'
|
||||
echo 'a change for hack/golangci.yaml.in as part of your PR.'
|
||||
fi
|
||||
echo 'In general please prefer to fix the error, we have already disabled specific lints'
|
||||
echo ' that the project chooses to ignore.'
|
||||
|
Reference in New Issue
Block a user