Skip to content

Commit e64ea9a

Browse files
authored
Update the linter configuration. (#1478)
Sync the configuration with the one used in Beats, which has disabled the majority of the least useful linters already.
1 parent 9c6a43b commit e64ea9a

File tree

2 files changed

+48
-70
lines changed

2 files changed

+48
-70
lines changed

.github/workflows/golangci-lint.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@ jobs:
1818
name: lint
1919
runs-on: ${{ matrix.os }}
2020
steps:
21-
- uses: actions/checkout@v2
21+
- uses: actions/checkout@v3
2222

2323
# Uses Go version from the repository.
2424
- name: Read .go-version file
2525
id: goversion
2626
run: echo "::set-output name=version::$(cat .go-version)"
2727

28-
- uses: actions/setup-go@v2
28+
- uses: actions/setup-go@v3
2929
with:
3030
go-version: "${{ steps.goversion.outputs.version }}"
3131

3232
- name: golangci-lint
33-
uses: golangci/golangci-lint-action@v2
33+
uses: golangci/golangci-lint-action@v3
3434
with:
3535
# Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version
36-
version: v1.45.2
36+
version: v1.47.2
3737

3838
# Give the job more time to execute.
3939
# Regarding `--whole-files`, the linter is supposed to support linting of changed a patch only but,

.golangci.yml

+44-66
Original file line numberDiff line numberDiff line change
@@ -12,46 +12,37 @@ issues:
1212
# Set to 0 to disable.
1313
# Default: 50
1414
max-issues-per-linter: 0
15+
exclude-rules:
16+
# Exclude package name contains '-' issue because we have at least one package with
17+
# it on its name.
18+
- text: "ST1003:"
19+
linters:
20+
- stylecheck
21+
# From mage we are priting to the console to ourselves
22+
- path: (.*magefile.go|.*dev-tools/mage/.*)
23+
linters:
24+
- forbidigo
1525

1626
output:
1727
sort-results: true
1828

19-
# Uncomment and add a path if needed to exclude
20-
# skip-dirs:
21-
# - some/path
22-
# skip-files:
23-
# - ".*\\.my\\.go$"
24-
# - lib/bad.go
25-
2629
# Find the whole list here https://golangci-lint.run/usage/linters/
2730
linters:
2831
disable-all: true
2932
enable:
30-
- deadcode # finds unused code
3133
- errcheck # checking for unchecked errors in go programs
3234
- 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.
33-
- goconst # finds repeated strings that could be replaced by a constant
34-
- dupl # tool for code clone detection
3535
- forbidigo # forbids identifiers matched by reg exps
36-
# 'replace' is used in go.mod for many dependencies that come from libbeat. We should work to remove those,
37-
# so we can re-enable this linter.
38-
# - gomoddirectives # manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
39-
- gomodguard
4036
- gosimple # linter for Go source code that specializes in simplifying a code
4137
- misspell # finds commonly misspelled English words in comments
4238
- nakedret # finds naked returns in functions greater than a specified function length
43-
- prealloc # finds slice declarations that could potentially be preallocated
4439
- nolintlint # reports ill-formed or insufficient nolint directives
4540
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
4641
- stylecheck # a replacement for golint
47-
- unparam # reports unused function parameters
4842
- unused # checks Go code for unused constants, variables, functions and types
49-
5043
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
5144
- ineffassign # detects when assignments to existing variables are not used
52-
- structcheck # finds unused struct fields
5345
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
54-
- varcheck # Finds unused global variables and constants
5546
- asciicheck # simple linter to check that your code does not contain non-ASCII identifiers
5647
- bodyclose # checks whether HTTP response body is closed successfully
5748
- durationcheck # check for two durations multiplied together
@@ -63,14 +54,20 @@ linters:
6354
- noctx # noctx finds sending http request without context.Context
6455
- unconvert # Remove unnecessary type conversions
6556
- wastedassign # wastedassign finds wasted assignment statements.
66-
# - godox # tool for detection of FIXME, TODO and other comment keywords
57+
- gomodguard # check for blocked dependencies
6758

6859
# all available settings of specific linters
6960
linters-settings:
7061
errcheck:
7162
# report about not checking of errors in type assertions: `a := b.(MyStruct)`;
72-
# default is false: such cases aren't reported by default.
73-
check-type-assertions: true
63+
check-type-assertions: false
64+
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`.
65+
check-blank: false
66+
# List of functions to exclude from checking, where each entry is a single function to exclude.
67+
# See https://github.com/kisielk/errcheck#excluding-functions for details.
68+
exclude-functions:
69+
- (mapstr.M).Delete # Only returns ErrKeyNotFound, can safely be ignored.
70+
- (mapstr.M).Put # Can only fail on type conversions, usually safe to ignore.
7471

7572
errorlint:
7673
# Check whether fmt.Errorf uses the %w verb for formatting errors. See the readme for caveats
@@ -80,85 +77,66 @@ linters-settings:
8077
# Check for plain error comparisons
8178
comparison: true
8279

83-
goconst:
84-
# minimal length of string constant, 3 by default
85-
min-len: 3
86-
# minimal occurrences count to trigger, 3 by default
87-
min-occurrences: 2
88-
89-
dupl:
90-
# tokens count to trigger issue, 150 by default
91-
threshold: 100
92-
9380
forbidigo:
9481
# Forbid the following identifiers
9582
forbid:
9683
- fmt.Print.* # too much log noise
9784
# Exclude godoc examples from forbidigo checks. Default is true.
9885
exclude_godoc_examples: true
9986

100-
gomoddirectives:
101-
# Allow local `replace` directives. Default is false.
102-
replace-local: false
87+
goimports:
88+
local-prefixes: github.com/elastic
10389

10490
gomodguard:
10591
blocked:
10692
# List of blocked modules.
10793
modules:
108-
- github.com/elastic/beats/v7:
109-
reason: "There must be no Beats dependency, use elastic-agent-libs instead."
110-
94+
# Blocked module.
95+
- github.com/pkg/errors:
96+
# Recommended modules that should be used instead. (Optional)
97+
recommendations:
98+
- errors
99+
- fmt
100+
reason: "This package is deprecated, use `fmt.Errorf` with `%w` instead"
111101

112102
gosimple:
113103
# Select the Go version to target. The default is '1.13'.
114-
go: "1.17"
115-
116-
misspell:
117-
# Correct spellings using locale preferences for US or UK.
118-
# Default is to use a neutral variety of English.
119-
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
120-
# locale: US
121-
# ignore-words:
122-
# - IdP
104+
go: "1.18.7"
123105

124106
nakedret:
125107
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
126108
max-func-lines: 0
127109

128-
prealloc:
129-
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
130-
# True by default.
131-
simple: true
132-
range-loops: true # Report preallocation suggestions on range loops, true by default
133-
for-loops: false # Report preallocation suggestions on for loops, false by default
134-
135110
nolintlint:
136111
# Enable to ensure that nolint directives are all used. Default is true.
137112
allow-unused: false
138113
# Disable to ensure that nolint directives don't have a leading space. Default is true.
139-
allow-leading-space: true
114+
allow-leading-space: false
140115
# Exclude following linters from requiring an explanation. Default is [].
141116
allow-no-explanation: []
142117
# Enable to require an explanation of nonzero length after each nolint directive. Default is false.
143118
require-explanation: true
144119
# Enable to require nolint directives to mention the specific linter being suppressed. Default is false.
145-
require-specific: true
120+
require-specific: false
146121

147122
staticcheck:
148123
# Select the Go version to target. The default is '1.13'.
149-
go: "1.17"
124+
go: "1.18.7"
125+
checks: ["all"]
150126

151127
stylecheck:
152128
# Select the Go version to target. The default is '1.13'.
153-
go: "1.17"
154-
155-
unparam:
156-
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
157-
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
158-
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
159-
# with golangci-lint call it on a directory with the changed file.
160-
check-exported: false
129+
go: "1.18.7"
130+
checks: ["all"]
161131

162132
unused:
163133
# Select the Go version to target. The default is '1.13'.
164-
go: "1.17"
134+
go: "1.18.7"
135+
136+
gosec:
137+
excludes:
138+
- G306 # Expect WriteFile permissions to be 0600 or less
139+
- G404 # Use of weak random number generator
140+
- G401 # Detect the usage of DES, RC4, MD5 or SHA1: Used in non-crypto contexts.
141+
- G501 # Import blocklist: crypto/md5: Used in non-crypto contexts.
142+
- G505 # Import blocklist: crypto/sha1: Used in non-crypto contexts.

0 commit comments

Comments
 (0)