Skip to content

Commit 5d9a2f3

Browse files
committed
golangci-lint: finish migration to v2
This finishes the work started in kubernetes#131113. Changes: - Remove TODOs for things that we don't have plans to fix. - Add issue for older TODO. - Reorganize and remove suppression rules so that the base check has no unused rules. - Document warn-unused, but don't enable it. - Remove disabling of statistics (they are useful) and ensure that they don't get the ERROR prefix. - Avoid ../ prefix in paths via `run.relative-path-mode: gomod`.
1 parent 9bada79 commit 5d9a2f3

File tree

4 files changed

+266
-352
lines changed

4 files changed

+266
-352
lines changed

hack/golangci-hints.yaml

Lines changed: 43 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@
1414
run:
1515
timeout: 30m
1616

17-
output:
18-
show-stats: false
17+
# The default is relative to the configuration, which is confusing because
18+
# then all paths start with ../ to move out of the "hack" directory.
19+
# `gomod` mirrors the current behavior of `golangci-lint.sh` changing into
20+
# the root of the repository. Because we are operating in a workspace,
21+
# the module picked by `gomod` is the main one
22+
relative-path-mode: gomod
1923

2024
version: "2"
2125

@@ -24,6 +28,11 @@ formatters:
2428
paths:
2529
- third_party
2630

31+
output:
32+
formats:
33+
text:
34+
path: stderr
35+
2736
issues:
2837
max-issues-per-linter: 0
2938
max-same-issues: 0
@@ -33,44 +42,17 @@ linters:
3342
paths:
3443
- third_party
3544

36-
# Excluding configuration per-path, per-linter, per-text and per-source
45+
# Log a warning if an exclusion rule is unused.
46+
#
47+
# Uncomment when investigating whether the configuration can be simplified,
48+
# but beware that golangci-lint then needs to be invoked for the entire
49+
# repository. Invoking it for individual packages may trigger these warning
50+
# when the rules are only needed elsewhere.
51+
#
52+
# warn-unused: true
53+
54+
# Excluding configuration per-path, per-linter, per-text and per-source.
3755
rules:
38-
- path: (.+)\.go$
39-
# staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
40-
text: ineffective break statement. Did you mean to break out of the outer loop
41-
42-
# exclude ineffassign linter for generated files for conversion
43-
- path: conversion\.go
44-
linters:
45-
- ineffassign
46-
47-
# SSA Extract calls are allowed in tests.
48-
- linters:
49-
- forbidigo
50-
text: should not be used because managedFields was removed
51-
path: _test.go$
52-
53-
# Adding unversioned feature gates is allowed in tests
54-
- linters:
55-
- forbidigo
56-
text: should not use Add, use AddVersioned instead
57-
path: _test.go$
58-
59-
# The Kubernetes naming convention for conversion functions uses underscores
60-
# and intentionally deviates from normal Go conventions to make those function
61-
# names more readable. Same for SetDefaults_*.
62-
#
63-
# https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507028627
64-
# https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1514201592
65-
- linters:
66-
- staticcheck
67-
- revive
68-
text: "(ST1003: should not use underscores in Go names; func (Convert_.*_To_.*|SetDefaults_)|exported: exported function (Convert|SetDefaults)_.* should be of the form)"
69-
70-
# This check currently has some false positives (https://github.com/nunnatsa/ginkgolinter/issues/91).
71-
- linters:
72-
- ginkgolinter
73-
text: use a function call in (Eventually|Consistently)
7456

7557
# https://github.com/kubernetes/kubernetes/issues/117288#issuecomment-1507012435
7658
- linters:
@@ -97,8 +79,27 @@ linters:
9779
- unused
9880
path: staging/src/k8s.io/client-go/util/workqueue/metrics.go
9981

100-
# Log a warning if an exclusion rule is unused.
101-
warn-unused: true
82+
# SSA Extract calls are allowed in tests.
83+
- linters:
84+
- forbidigo
85+
text: should not be used because managedFields was removed
86+
path: _test.go$
87+
88+
# Adding unversioned feature gates is allowed in tests
89+
- linters:
90+
- forbidigo
91+
text: should not use Add, use AddVersioned instead
92+
path: _test.go$
93+
94+
- path: (.+)\.go$
95+
# staticcheck: Developers tend to write in C-style with an explicit 'break' in a 'switch', so it's ok to ignore
96+
text: ineffective break statement. Did you mean to break out of the outer loop
97+
98+
# exclude ineffassign linter for generated files for conversion
99+
- path: conversion\.go
100+
linters:
101+
- ineffassign
102+
102103

103104
default: standard
104105
enable: # please keep this alphabetized
@@ -120,7 +121,7 @@ linters:
120121
custom:
121122
logcheck:
122123
# Installed there by hack/verify-golangci-lint.sh.
123-
path: ../_output/local/bin/logcheck.so
124+
path: _output/local/bin/logcheck.so
124125
description: structured logging checker
125126
original-url: k8s.io/logtools/logcheck
126127
settings:

0 commit comments

Comments
 (0)