Skip to content

Commit 55faa13

Browse files
committed
upgrade lint and lint action
1 parent a53311c commit 55faa13

File tree

4 files changed

+132
-183
lines changed

4 files changed

+132
-183
lines changed

.github/workflows/code-health.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ jobs:
1717
go-version-file: 'go.mod'
1818
cache: false # see https://github.com/golangci/golangci-lint-action/issues/807
1919
- name: golangci-lint
20-
uses: golangci/golangci-lint-action@v6.5.2
20+
uses: golangci/golangci-lint-action@v7.0.0
2121
with:
22-
version: v1.64.6
22+
version: v2.0.1
2323
unit-tests:
2424
env:
2525
COVERAGE: coverage.out

.golangci.yml

Lines changed: 128 additions & 179 deletions
Original file line numberDiff line numberDiff line change
@@ -1,185 +1,134 @@
1-
linters-settings:
2-
errorlint:
3-
comparison: false
4-
goconst:
5-
min-len: 2
6-
min-occurrences: 2
7-
gocyclo:
8-
min-complexity: 15
9-
misspell:
10-
locale: US
11-
ignore-words:
12-
- cancelled
13-
revive:
14-
# see https://github.com/mgechev/revive#available-rules for details.
15-
ignore-generated-header: true
16-
severity: warning
17-
max-open-files: 2048
18-
rules:
19-
- name: blank-imports
20-
- name: context-as-argument
21-
- name: context-keys-type
22-
- name: defer
23-
- name: dot-imports
24-
- name: error-return
25-
- name: error-strings
26-
- name: error-naming
27-
- name: early-return
28-
- name: errorf
29-
- name: exported
30-
- name: import-shadowing
31-
- name: indent-error-flow
32-
- name: if-return
33-
- name: increment-decrement
34-
- name: var-naming
35-
- name: var-declaration
36-
- name: package-comments
37-
- name: range
38-
- name: receiver-naming
39-
- name: time-naming
40-
- name: unexported-return
41-
- name: indent-error-flow
42-
- name: errorf
43-
- name: empty-block
44-
- name: superfluous-else
45-
- name: struct-tag
46-
- name: unused-parameter
47-
- name: unreachable-code
48-
- name: redefines-builtin-id
49-
- name: early-return
50-
- name: unused-receiver
51-
- name: constant-logical-expr
52-
- name: confusing-naming
53-
- name: unnecessary-stmt
54-
- name: use-any
55-
- name: imports-blocklist
56-
arguments:
57-
- "github.com/pkg/errors"
58-
gci:
59-
sections:
60-
- standard
61-
- default
62-
linters:
63-
disable-all: true
64-
enable:
65-
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f()) [fast: true, auto-fix: false]
66-
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases [fast: false, auto-fix: false]
67-
- errorlint # Errorlint is a linter that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13.
68-
- exhaustive # check exhaustiveness of enum switch statements [fast: false, auto-fix: false]
69-
- copyloopvar # copyloopvar is a linter detects places where loop variables are copied. Replaces exportloopref since Go1.22
70-
- gci # Gci controls golang package import order and makes it always deterministic. [fast: true, auto-fix: false]
71-
- gochecknoinits # Checks that no init functions are present in Go code [fast: true, auto-fix: false]
72-
- goconst # Finds repeated strings that could be replaced by a constant [fast: true, auto-fix: false]
73-
- gocritic # Provides diagnostics that check for bugs, performance and style issues. [fast: false, auto-fix: false]
74-
- gocyclo # Computes and checks the cyclomatic complexity of functions [fast: true, auto-fix: false]
75-
- godot # Check if comments end in a period [fast: true, auto-fix: true]
76-
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification [fast: true, auto-fix: true]
77-
- goimports # In addition to fixing imports, goimports also formats your code in the same style as gofmt. [fast: true, auto-fix: true]
78-
- mnd # An analyzer to detect magic numbers. [fast: true, auto-fix: false]
79-
- goprintffuncname # Checks that printf-like functions are named with `f` at the end [fast: true, auto-fix: false]
80-
- gosec # (gas) Inspects source code for security problems [fast: false, auto-fix: false]
81-
- gosimple # (megacheck) Linter for Go source code that specializes in simplifying code [fast: false, auto-fix: false]
82-
- govet # (vet, vetshadow) Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string [fast: false, auto-fix: false]
83-
- ineffassign # Detects when assignments to existing variables are not used [fast: true, auto-fix: false]
84-
- makezero # Finds slice declarations with non-zero initial length [fast: false, auto-fix: false]
85-
- misspell # Finds commonly misspelled English words in comments [fast: true, auto-fix: true]
86-
- nakedret # Finds naked returns in functions greater than a specified function length [fast: true, auto-fix: false]
87-
- noctx # noctx finds sending http request without context.Context [fast: false, auto-fix: false]
88-
- nolintlint # Reports ill-formed or insufficient nolint directives [fast: true, auto-fix: false]
89-
- prealloc # Finds slice declarations that could potentially be pre-allocated [fast: true, auto-fix: false]
90-
- predeclared # find code that shadows one of Go's predeclared identifiers [fast: true, auto-fix: false]
91-
- revive # Fast, configurable, extensible, flexible, and beautiful linter for Go. Drop-in replacement of golint. [fast: false, auto-fix: false]
92-
- rowserrcheck # checks whether Err of rows is checked successfully [fast: false, auto-fix: false]
93-
- staticcheck # (megacheck) It's a set of rules from staticcheck. It's not the same thing as the staticcheck binary. The author of staticcheck doesn't support or approve the use of staticcheck as a library inside golangci-lint. [fast: false, auto-fix: false]
94-
- stylecheck # Stylecheck is a replacement for golint [fast: false, auto-fix: false]
95-
- usetesting # Reports uses of functions with replacement inside the testing package. [auto-fix]
96-
- testifylint # Checks usage of github.com/stretchr/testify. [fast: false, auto-fix: false]
97-
- thelper # thelper detects golang test helpers without t.Helper() call and checks the consistency of test helpers [fast: false, auto-fix: false]
98-
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code [fast: false, auto-fix: false]
99-
- unconvert # Remove unnecessary type conversions [fast: false, auto-fix: false]
100-
- unparam # Reports unused function parameters [fast: false, auto-fix: false]
101-
- unused # (megacheck) Checks Go code for unused constants, variables, functions and types [fast: false, auto-fix: false]
102-
- usestdlibvars # A linter that detect the possibility to use variables/constants from the Go standard library. [fast: true, auto-fix: false]
103-
- wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false]
104-
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]
105-
106-
# don't enable:
107-
# - bodyclose # checks whether HTTP response body is closed successfully [fast: false, auto-fix: false]
108-
# - depguard # Go linter that checks if package imports are in a list of acceptable packages [fast: true, auto-fix: false]
109-
# - asasalint # check for pass []any as any in variadic func(...any) [fast: false, auto-fix: false]
110-
# - asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers [fast: true, auto-fix: false]
111-
# - bidichk # Checks for dangerous unicode character sequences [fast: true, auto-fix: false]
112-
# - containedctx # containedctx is a linter that detects struct contained context.Context field [fast: true, auto-fix: false]
113-
# - contextcheck # check the function whether use a non-inherited context [fast: false, auto-fix: false]
114-
# - cyclop # checks function and package cyclomatic complexity [fast: false, auto-fix: false]
115-
# - decorder # check declaration order and count of types, constants, variables and functions [fast: true, auto-fix: false]
116-
# - deadcode # [deprecated] Finds unused code [fast: false, auto-fix: false]
117-
# - dupl # Tool for code clone detection [fast: true, auto-fix: false]
118-
# - durationcheck # check for two durations multiplied together [fast: false, auto-fix: false]
119-
# - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions, where the check for the returned error can be omitted. [fast: false, auto-fix: false]
120-
# - errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`. [fast: false, auto-fix: false]
121-
# - errorlint # errorlint is a linter for that can be used to find code that will cause problems with the error wrapping scheme introduced in Go 1.13. [fast: false, auto-fix: false]
122-
# - execinquery # execinquery is a linter about query string checker in Query function which reads your Go src files and warning it finds [fast: false, auto-fix: false]
123-
# - exhaustivestruct #[deprecated]: Checks if all struct's fields are initialized [fast: false, auto-fix: false]
124-
# - exhaustruct # Checks if all structure fields are initialized [fast: false, auto-fix: false]
125-
# - forbidigo # Forbids identifiers [fast: true, auto-fix: false]
126-
# - forcetypeassert # finds forced type assertions [fast: true, auto-fix: false]
127-
# - funlen # Tool for detection of long functions [fast: true, auto-fix: false]
128-
# - gochecknoglobals # check that no global variables exist [fast: true, auto-fix: false]
129-
# - gocognit # Computes and checks the cognitive complexity of functions [fast: true, auto-fix: false]
130-
# - godox # Tool for detection of FIXME, TODO and other comment keywords [fast: true, auto-fix: false]
131-
# - goerr113 # Golang linter to check the errors handling expressions [fast: false, auto-fix: false]
132-
# - gofumpt # Gofumpt checks whether code was gofumpt-ed. [fast: true, auto-fix: true]
133-
# - goheader # Checks is file header matches to pattern [fast: true, auto-fix: false]
134-
# - golint #[deprecated]: Golint differs from gofmt. Gofmt reformats Go source code, whereas golint prints out style mistakes [fast: false, auto-fix: false]
135-
# - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod. [fast: true, auto-fix: false]
136-
# - gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. [fast: true, auto-fix: false]
137-
# - grouper # An analyzer to analyze expression groups. [fast: true, auto-fix: false]
138-
# - ifshort # [deprecated] Checks that your code uses short syntax for if-statements whenever possible [fast: true, auto-fix: false]
139-
# - importas # Enforces consistent import aliases [fast: false, auto-fix: false]
140-
# - interfacebloat # A linter that checks the number of methods inside an interface. [fast: true, auto-fix: false]
141-
# - interfacer # [deprecated]: Linter that suggests narrower interface types [fast: false, auto-fix: false]
142-
# - ireturn # Accept Interfaces, Return Concrete Types [fast: false, auto-fix: false]
143-
# - lll # Reports long lines [fast: true, auto-fix: false]
144-
# - logrlint # Check logr arguments. [fast: false, auto-fix: false]
145-
# - maintidx # maintidx measures the maintainability index of each function. [fast: true, auto-fix: false]
146-
# - maligned #[deprecated]: Tool to detect Go structs that would take less memory if their fields were sorted [fast: false, auto-fix: false]
147-
# - nestif # Reports deeply nested if statements [fast: true, auto-fix: false]
148-
# - nilerr # Finds the code that returns nil even if it checks that the error is not nil. [fast: false, auto-fix: false]
149-
# - nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false]
150-
# - nlreturn # nlreturn checks for a new line before return and branch statements to increase code clarity [fast: true, auto-fix: false]
151-
# - nonamedreturns # Reports all named returns [fast: false, auto-fix: false]
152-
# - nosnakecase #[deprecated]: nosnakecase is a linter that detects snake case of variable naming and function name. [fast: true, auto-fix: false]
153-
# - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL. [fast: true, auto-fix: false]
154-
# - paralleltest # paralleltest detects missing usage of t.Parallel() method in your Go test [fast: false, auto-fix: false]
155-
# - promlinter # Check Prometheus metrics naming via promlint [fast: true, auto-fix: false]
156-
# - reassign # Checks that package variables are not reassigned [fast: true, auto-fix: false]
157-
# - scopelint #[deprecated]: Scopelint checks for unpinned variables in go programs [fast: true, auto-fix: false]
158-
# - sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. [fast: false, auto-fix: false]
159-
# - structcheck # [deprecated] Finds unused struct fields [fast: false, auto-fix: false]
160-
# - tagliatelle # Checks the struct tags. [fast: true, auto-fix: false]
161-
# - testpackage # linter that makes you use a separate _test package [fast: true, auto-fix: false]
162-
# - tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes [fast: false, auto-fix: false]
163-
# - varcheck # [deprecated] Finds unused global variables and constants [fast: false, auto-fix: false]
164-
# - varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false]
165-
# - wrapcheck # Checks that errors returned from external packages are wrapped [fast: false, auto-fix: false]
166-
# - wsl # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false]
167-
1+
version: "2"
1682
run:
169-
tests: true
170-
timeout: 10m
1713
build-tags:
1724
- e2e
1735
- unit
1746
- integration
1757
modules-download-mode: readonly
176-
177-
issues:
178-
# Excluding configuration per-path, per-linter, per-text and per-source
179-
exclude-rules:
180-
- path: e2e # Don't check for cyclomatic complexity on e2e file.
181-
linters:
182-
- gocyclo
183-
- path: internal/test/fixture # Don't check for magic numbers on fixtures.
184-
linters:
185-
- mnd
8+
tests: true
9+
linters:
10+
default: none
11+
enable:
12+
- copyloopvar
13+
- dogsled
14+
- errcheck
15+
- errorlint
16+
- exhaustive
17+
- gochecknoinits
18+
- goconst
19+
- gocritic
20+
- gocyclo
21+
- godot
22+
- goprintffuncname
23+
- gosec
24+
- govet
25+
- ineffassign
26+
- makezero
27+
- misspell
28+
- mnd
29+
- nakedret
30+
- noctx
31+
- nolintlint
32+
- prealloc
33+
- predeclared
34+
- revive
35+
- rowserrcheck
36+
- staticcheck
37+
- testifylint
38+
- thelper
39+
- unconvert
40+
- unparam
41+
- unused
42+
- usestdlibvars
43+
- usetesting
44+
- wastedassign
45+
- whitespace
46+
settings:
47+
errorlint:
48+
comparison: false
49+
goconst:
50+
min-len: 2
51+
min-occurrences: 2
52+
gocyclo:
53+
min-complexity: 15
54+
misspell:
55+
locale: US
56+
ignore-rules:
57+
- cancelled
58+
revive:
59+
max-open-files: 2048
60+
severity: warning
61+
rules:
62+
- name: blank-imports
63+
- name: context-as-argument
64+
- name: context-keys-type
65+
- name: defer
66+
- name: dot-imports
67+
- name: error-return
68+
- name: error-strings
69+
- name: error-naming
70+
- name: early-return
71+
- name: errorf
72+
- name: exported
73+
- name: import-shadowing
74+
- name: indent-error-flow
75+
- name: if-return
76+
- name: increment-decrement
77+
- name: var-naming
78+
- name: var-declaration
79+
- name: package-comments
80+
- name: range
81+
- name: receiver-naming
82+
- name: time-naming
83+
- name: unexported-return
84+
- name: indent-error-flow
85+
- name: errorf
86+
- name: empty-block
87+
- name: superfluous-else
88+
- name: struct-tag
89+
- name: unused-parameter
90+
- name: unreachable-code
91+
- name: redefines-builtin-id
92+
- name: early-return
93+
- name: unused-receiver
94+
- name: constant-logical-expr
95+
- name: confusing-naming
96+
- name: unnecessary-stmt
97+
- name: use-any
98+
- name: imports-blocklist
99+
arguments:
100+
- github.com/pkg/errors
101+
exclusions:
102+
generated: lax
103+
presets:
104+
- comments
105+
- common-false-positives
106+
- legacy
107+
- std-error-handling
108+
rules:
109+
- linters:
110+
- gocyclo
111+
path: e2e
112+
- linters:
113+
- mnd
114+
path: internal/test/fixture
115+
paths:
116+
- third_party$
117+
- builtin$
118+
- examples$
119+
formatters:
120+
enable:
121+
- gci
122+
- gofmt
123+
- goimports
124+
settings:
125+
gci:
126+
sections:
127+
- standard
128+
- default
129+
exclusions:
130+
generated: lax
131+
paths:
132+
- third_party$
133+
- builtin$
134+
- examples$

internal/cli/output_opts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (opts *OutputOpts) IsJSONPathOutput() bool {
8383
}
8484

8585
func (opts *OutputOpts) IsPlainOutput() bool {
86-
return !(opts.IsJSONOutput() || opts.IsGoTemplate() || opts.IsJSONPathOutput())
86+
return !opts.IsJSONOutput() && !opts.IsGoTemplate() && !opts.IsJSONPathOutput()
8787
}
8888

8989
// ConfigWriter returns the io.Writer.

tools/templates-checker/astparsing/astparsing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ func getRelatedTemplateFromCallExpr(pkg *packages.Package, callExpr *ast.CallExp
369369

370370
// If there's a string literal that's not a template ignore it
371371
case *ast.BasicLit:
372-
if !(strings.Contains(templateArg.Value, "{{") && strings.Contains(templateArg.Value, "}}")) {
372+
if !strings.Contains(templateArg.Value, "{{") || !strings.Contains(templateArg.Value, "}}") {
373373
return nil, nil
374374
}
375375
}

0 commit comments

Comments
 (0)