
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.
92 lines
3.0 KiB
YAML
92 lines
3.0 KiB
YAML
# golangci-lint is used in Kubernetes with different configurations that
|
|
# enable an increasing amount of checks:
|
|
# - golangci.yaml is the most permissive configuration. All existing code
|
|
# passed.
|
|
# - golangci-strict.yaml adds checks that all new code in pull requests
|
|
# must pass.
|
|
# - golangci-hints.yaml adds checks for code patterns where developer
|
|
# and reviewer may decide whether findings should get addressed before
|
|
# merging. Beware that the golangci-lint output includes also the
|
|
# issues that must be fixed and doesn't indicate how severe each issue
|
|
# is (https://gophers.slack.com/archives/CS0TBRKPC/p1685721815275349).
|
|
#
|
|
# All three flavors are generated from golangci.yaml.in with
|
|
# hack/update-golangci-lint-config.sh.
|
|
|
|
run:
|
|
timeout: 30m
|
|
skip-files:
|
|
- "^zz_generated.*"
|
|
|
|
output:
|
|
sort-results: true
|
|
|
|
issues:
|
|
max-issues-per-linter: 0
|
|
max-same-issues: 0
|
|
# Excluding configuration per-path, per-linter, per-text and per-source
|
|
exclude-rules:
|
|
# exclude ineffassign linter for generated files for conversion
|
|
- path: conversion\.go
|
|
linters:
|
|
- ineffassign
|
|
|
|
# SSA Extract calls are allowed in tests.
|
|
- linters:
|
|
- forbidigo
|
|
text: should not be used because managedFields was removed
|
|
path: _test.go$
|
|
|
|
# The Kubernetes naming convention for conversion functions uses underscores
|
|
# and intentionally deviates from normal Go conventions to make those function
|
|
# names more readable. Same for SetDefaults_*.
|
|
#
|
|
# https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507028627
|
|
# https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1514201592
|
|
- linters:
|
|
- stylecheck
|
|
text: "ST1003: should not use underscores in Go names; func (Convert_.*_To_.*|SetDefaults_)"
|
|
|
|
# This check currently has some false positives (https://github.com/nunnatsa/ginkgolinter/issues/91).
|
|
- linters:
|
|
- ginkgolinter
|
|
text: use a function call in (Eventually|Consistently)
|
|
|
|
# https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507012435
|
|
- linters:
|
|
- gocritic
|
|
text: "ifElseChain: rewrite if-else to switch statement"
|
|
|
|
linters:
|
|
disable-all: false
|
|
enable: # please keep this alphabetized
|
|
- forbidigo
|
|
- ginkgolinter
|
|
- gocritic
|
|
- govet
|
|
- ineffassign
|
|
- logcheck
|
|
- staticcheck
|
|
- stylecheck
|
|
- unused
|
|
|
|
linters-settings: # please keep this alphabetized
|
|
custom:
|
|
logcheck:
|
|
# Installed there by hack/verify-golangci-lint.sh.
|
|
path: ../_output/local/bin/logcheck.so
|
|
description: structured logging checker
|
|
original-url: k8s.io/logtools/logcheck
|
|
forbidigo:
|
|
analyze-types: true
|
|
forbid:
|
|
- p: ^managedfields\.ExtractInto$
|
|
pkg: ^k8s\.io/apimachinery/pkg/util/managedfields$
|
|
msg: should not be used because managedFields was removed
|
|
- p: \.Extract
|
|
pkg: ^k8s\.io/client-go/applyconfigurations/
|
|
msg: should not be used because managedFields was removed
|
|
staticcheck:
|
|
checks:
|
|
- "all"
|