Skip to content

Commit 31208a5

Browse files
committed
lint: enable revive with an explicit rule list, drop maintidx
Second half of #1991. These are the two you and Angelo were asked about and I have gone ahead and made the call on both, happy to change either. revive: enabled, but not with enable-all-rules. That reports 3452 issues over 688 files, which is not something anyone can review in one go. The config now lists 38 rules explicitly, all of which are already clean tree-wide, so revive lands as a ratchet against new code rather than as a backlog. Four fixes were needed to get there: one comment spacing in a zkatdlog test and three in txgen's error.go. The rules left out are named in a comment in the config with their current counts, so the next step does not have to re-measure. The big ones are exported (1568), unused-parameter (362), unused-receiver (334) and import-shadowing (328). Three more are left out because another enabled linter already covers them, line-length-limit by lll, imports-blocklist by depguard, file-header by goheader, and six because they are no-ops at their default settings. Dropping enable-all-rules also removes the nine "disabled: true" entries, which only existed to switch rules back off, and argument-limit and function-result-limit, which were tuned but have 103 and 49 violations and so belong with the deferred set. maintidx: settings block deleted rather than enabled. It reports 19 functions and every one of them would have to be suppressed: 12 are in _test.go, 4 are in the shared testutils and dbtest helpers, 1 is Prove in the CSP range proof, and 2 are the fungible suite entry point and its topology. The score is driven by Halstead volume, so a long table-driven test or a flat block of declarative topology wiring scores badly for being long rather than for being tangled, and table-driven tests are the style AGENTS.md asks for. A linter that starts at a 100% suppression rate is measuring the wrong thing here. gocognit is still configured and unenabled, and at min-complexity 15 it targets branching directly, which is the check actually wanted. golangci-lint is clean on all nine modules and make checks passes. That leaves gocognit and wrapcheck as the only settings blocks for linters that are not enabled. Signed-off-by: atharrva01 <atharvaborade568@gmail.com>
1 parent 7ec36f3 commit 31208a5

3 files changed

Lines changed: 60 additions & 39 deletions

File tree

.golangci.yml

Lines changed: 53 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ linters:
3030
- nolintlint # Reports ill-formed or insufficient nolint directives. [fast, auto-fix]
3131
- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative. [auto-fix]
3232
- reassign # Checks that package variables are not reassigned.
33+
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. [auto-fix]
3334
- rowserrcheck # Checks whether Rows.Err of rows is checked successfully.
3435
- sloglint # Ensure consistent code style when using log/slog. [auto-fix]
3536
- spancheck # Checks for mistakes with OpenTelemetry/Census spans.
@@ -126,47 +127,67 @@ linters:
126127
lll:
127128
# Max line length, lines longer will be reported.
128129
line-length: 240
129-
maintidx:
130-
under: 20
131130
nolintlint:
132131
require-specific: true
133132
revive:
134-
enable-all-rules: true
133+
# enable-all-rules was never on, because revive itself was never enabled. Turning it on
134+
# as-is reports 3452 issues over 688 files, so instead of one unreviewable change this
135+
# lists the rules explicitly. Everything below is already clean tree-wide, which makes
136+
# revive a ratchet against new code rather than a backlog.
137+
#
138+
# Deliberately not listed yet, with their current counts, each wants its own change:
139+
# exported (1568), unused-parameter (362), unused-receiver (334), import-shadowing (328),
140+
# unchecked-type-assertion (125), argument-limit (103), unexported-naming (62),
141+
# var-naming (59), defer (59), redundant-import-alias (51), function-result-limit (49).
142+
#
143+
# Not listed because another enabled linter already covers them: line-length-limit (lll),
144+
# imports-blocklist (depguard), file-header (goheader). Omitted as no-ops at their default
145+
# settings: comments-density, file-length-limit, enforce-map-style, enforce-slice-style,
146+
# enforce-repeated-arg-type-style, string-format.
135147
rules:
136-
- name: argument-limit
137-
arguments:
138-
- 5
139-
- name: line-length-limit
140-
arguments:
141-
- 240
142-
- name: file-header
143-
disabled: true
144-
- name: package-comments
145-
disabled: true
146-
- name: max-public-structs
147-
disabled: true
148-
- name: banned-characters
149-
disabled: true
150-
- name: cognitive-complexity
151-
disabled: true
152-
- name: cyclomatic
153-
disabled: true
154-
- name: function-length
155-
disabled: true
156-
- name: function-result-limit
148+
- name: atomic
149+
- name: bool-literal-in-expr
150+
- name: comment-spacings
157151
arguments:
158-
- 3
159-
- name: add-constant
160-
disabled: true
152+
- 'nolint:'
153+
- name: constant-logical-expr
154+
- name: context-keys-type
155+
- name: datarace
156+
- name: deep-exit
157+
- name: duplicated-imports
158+
- name: epoch-naming
159+
- name: error-return
160+
- name: errorf
161+
- name: filename-format
162+
- name: forbidden-call-in-wg-go
163+
- name: get-return
164+
- name: identical-ifelseif-conditions
165+
- name: identical-switch-conditions
166+
- name: inefficient-map-lookup
167+
- name: modifies-parameter
168+
- name: modifies-value-receiver
169+
- name: optimize-operands-order
170+
- name: range
171+
- name: range-val-address
172+
- name: range-val-in-closure
173+
- name: redundant-build-tag
174+
- name: redundant-test-main-exit
175+
- name: string-of-int
176+
- name: time-date
177+
- name: time-equal
178+
- name: time-naming
179+
- name: unconditional-recursion
161180
- name: unhandled-error
162181
arguments:
163182
- fmt.Printf
164183
- fmt.Println
165-
- name: confusing-naming
166-
disabled: true
167-
- name: comment-spacings
168-
arguments:
169-
- 'nolint:'
184+
- name: unnecessary-if
185+
- name: unreachable-code
186+
- name: unsecure-url-scheme
187+
- name: use-any
188+
- name: use-errors-new
189+
- name: useless-break
190+
- name: waitgroup-by-value
170191
rowserrcheck:
171192
packages:
172193
- github.com/jackc/pgx/v5

integration/nwo/txgen/model/api/error.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewBadRequestError(err error, message string) *AppError {
6969
Code: http.StatusBadRequest,
7070
Message: message,
7171
Cause: err,
72-
//Location: utils.FileWithLineNum(),
72+
// Location: utils.FileWithLineNum(),
7373

7474
}
7575
}
@@ -83,7 +83,7 @@ func NewNotFoundError(err error, message string) *AppError {
8383
Code: http.StatusNotFound,
8484
Message: message,
8585
Cause: err,
86-
//Location: utils.FileWithLineNum(),
86+
// Location: utils.FileWithLineNum(),
8787
}
8888
}
8989

@@ -96,7 +96,7 @@ func NewInternalServerError(err error, message string) *AppError {
9696
Code: http.StatusInternalServerError,
9797
Message: message,
9898
Cause: err,
99-
//Location: utils.FileWithLineNum(),
99+
// Location: utils.FileWithLineNum(),
100100
}
101101
}
102102

@@ -109,7 +109,7 @@ func NewDBError(err error, message string) *AppError {
109109
Code: http.StatusInternalServerError,
110110
Message: message,
111111
Cause: err,
112-
//Location: utils.FileWithLineNum(),
112+
// Location: utils.FileWithLineNum(),
113113
}
114114
}
115115

@@ -122,7 +122,7 @@ func NewAuthorizationError(err error, message string) *AppError {
122122
Code: http.StatusUnauthorized,
123123
Message: message,
124124
Cause: err,
125-
//Location: utils.FileWithLineNum(),
125+
// Location: utils.FileWithLineNum(),
126126
}
127127
}
128128

@@ -135,6 +135,6 @@ func NewForbiddenError(err error, message string) *AppError {
135135
Code: http.StatusForbidden,
136136
Message: message,
137137
Cause: err,
138-
//Location: utils.FileWithLineNum(),
138+
// Location: utils.FileWithLineNum(),
139139
}
140140
}

token/core/zkatdlog/nogh/v1/validator/validator_security_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func newSecurityTestEnv(t *testing.T) *testing2.Env {
7070
// ctx.Ledger.GetState() will cause a nil-function-pointer panic on the chaincode,
7171
// constituting a denial-of-service vector. The fix adds an explicit nil guard.
7272
func TestSecurityPanicNilBackendLedger(t *testing.T) {
73-
backend := common.NewBackend(logging.MustGetLogger(), nil /*nil ledger*/, nil, nil)
73+
backend := common.NewBackend(logging.MustGetLogger(), nil /* nil ledger */, nil, nil)
7474

7575
_, err := backend.GetState(token2.ID{TxId: "tx1", Index: 0})
7676
require.Error(t, err, "GetState with nil ledger must return an error, not panic")

0 commit comments

Comments
 (0)