Skip to content

Commit 2ffcefb

Browse files
authored
fix: Linters (#332)
* fix: golangci configs * fix: sonar configs * fix: Linters
1 parent 08db312 commit 2ffcefb

File tree

34 files changed

+274
-163
lines changed

34 files changed

+274
-163
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ bin/
1818
dist/
1919
.DS_Store
2020
coverage/
21-
tests-report.json
21+
tests-report.json
22+
linters-report.xml

.golangci.pipe.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,11 @@ run:
106106
output:
107107
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
108108
# default is "colored-line-number"
109-
formats: colored-line-number
109+
formats:
110+
- format: colored-line-number
111+
path: stderr
112+
- format: checkstyle
113+
path: linters-report.xml
110114

111115
# print lines of code with issue, default is true
112116
print-issued-lines: true

.golangci.yml

Lines changed: 226 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,33 @@ linters-settings:
1212
lines: 100
1313
statements: 50
1414
gci:
15-
local-prefixes: github.com/obalunenko/advent-of-code
15+
# Section configuration to compare against.
16+
# Section names are case-insensitive and may contain parameters in ().
17+
# The default order of sections is `standard > default > custom > blank > dot > alias > localmodule`,
18+
# If `custom-order` is `true`, it follows the order of `sections` option.
19+
# Default: ["standard", "default"]
20+
sections:
21+
- standard # Standard section: captures all standard packages.
22+
- default # Default section: contains all imports that could not be matched to another section type.
23+
- prefix(github.com/obalunenko/advent-of-code) # Custom section: groups all imports with the specified Prefix.
24+
- blank # Blank section: contains all blank imports. This section is not present unless explicitly enabled.
25+
- dot # Dot section: contains all dot imports. This section is not present unless explicitly enabled.
26+
- alias # Alias section: contains all alias imports. This section is not present unless explicitly enabled.
27+
- localmodule # Local module section: contains all local packages. This section is not present unless explicitly enabled.
28+
29+
# Skip generated files.
30+
# Default: true
31+
skip-generated: false
32+
33+
# Enable custom order of sections.
34+
# If `true`, make the section order the same as the order of `sections`.
35+
# Default: false
36+
custom-order: true
37+
38+
# Drops lexical ordering for custom sections.
39+
# Default: false
40+
no-lex-order: true
41+
1642
goconst:
1743
min-len: 2
1844
min-occurrences: 2
@@ -33,13 +59,128 @@ linters-settings:
3359
min-complexity: 15
3460
goimports:
3561
local-prefixes: github.com/obalunenko/advent-of-code
36-
gomnd:
37-
settings:
38-
mnd:
39-
# don't include the "operation" and "assign"
40-
checks: [ argument,case,condition,return ]
62+
mnd:
63+
# List of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
64+
# Default: ["argument", "case", "condition", "operation", "return", "assign"]
65+
checks:
66+
- argument
67+
- case
68+
- condition
69+
- operation
70+
- return
71+
- assign
72+
# List of numbers to exclude from analysis.
73+
# The numbers should be written as string.
74+
# Values always ignored: "1", "1.0", "0" and "0.0"
75+
# Default: []
76+
ignored-numbers: []
77+
# List of file patterns to exclude from analysis.
78+
# Values always ignored: `.+_test.go`
79+
# Default: []
80+
ignored-files: []
81+
# List of function patterns to exclude from analysis.
82+
# Following functions are always ignored: `time.Date`,
83+
# `strconv.FormatInt`, `strconv.FormatUint`, `strconv.FormatFloat`,
84+
# `strconv.ParseInt`, `strconv.ParseUint`, `strconv.ParseFloat`.
85+
# Default: []
86+
ignored-functions: []
87+
4188
govet:
42-
check-shadowing: true
89+
# Disable all analyzers.
90+
# Default: false
91+
disable-all: false
92+
# Enable analyzers by name.
93+
# (in addition to default:
94+
# appends, asmdecl, assign, atomic, bools, buildtag, cgocall, composites, copylocks, defers, directive, errorsas,
95+
# framepointer, httpresponse, ifaceassert, loopclosure, lostcancel, nilfunc, printf, shift, sigchanyzer, slog,
96+
# stdmethods, stringintconv, structtag, testinggoroutine, tests, timeformat, unmarshal, unreachable, unsafeptr,
97+
# unusedresult
98+
# ).
99+
# Run `GL_DEBUG=govet golangci-lint run --enable=govet` to see default, all available analyzers, and enabled analyzers.
100+
# Default: []
101+
disable:
102+
- fieldalignment
103+
enable:
104+
# Check for missing values after append.
105+
- appends
106+
# Report mismatches between assembly files and Go declarations.
107+
- asmdecl
108+
# Check for useless assignments.
109+
- assign
110+
# Check for common mistakes using the sync/atomic package.
111+
- atomic
112+
# Check for non-64-bits-aligned arguments to sync/atomic functions.
113+
- atomicalign
114+
# Check for common mistakes involving boolean operators.
115+
- bools
116+
# Check //go:build and // +build directives.
117+
- buildtag
118+
# Detect some violations of the cgo pointer passing rules.
119+
- cgocall
120+
# Check for unkeyed composite literals.
121+
- composites
122+
# Check for locks erroneously passed by value.
123+
- copylocks
124+
# Check for calls of reflect.DeepEqual on error values.
125+
- deepequalerrors
126+
# Report common mistakes in defer statements.
127+
- defers
128+
# Check Go toolchain directives such as //go:debug.
129+
- directive
130+
# Report passing non-pointer or non-error values to errors.As.
131+
- errorsas
132+
# Find calls to a particular function.
133+
- findcall
134+
# Report assembly that clobbers the frame pointer before saving it.
135+
- framepointer
136+
# Check for mistakes using HTTP responses.
137+
- httpresponse
138+
# Detect impossible interface-to-interface type assertions.
139+
- ifaceassert
140+
# Check references to loop variables from within nested functions.
141+
- loopclosure
142+
# Check cancel func returned by context.WithCancel is called.
143+
- lostcancel
144+
# Check for useless comparisons between functions and nil.
145+
- nilfunc
146+
# Check for redundant or impossible nil comparisons.
147+
- nilness
148+
# Check consistency of Printf format strings and arguments.
149+
- printf
150+
# Check for comparing reflect.Value values with == or reflect.DeepEqual.
151+
- reflectvaluecompare
152+
# Check for possible unintended shadowing of variables.
153+
- shadow
154+
# Check for shifts that equal or exceed the width of the integer.
155+
- shift
156+
# Check for unbuffered channel of os.Signal.
157+
- sigchanyzer
158+
# Check for invalid structured logging calls.
159+
- slog
160+
# Check the argument type of sort.Slice.
161+
- sortslice
162+
# Check signature of methods of well-known interfaces.
163+
- stdmethods
164+
# Check for string(int) conversions.
165+
- stringintconv
166+
# Check that struct field tags conform to reflect.StructTag.Get.
167+
- structtag
168+
# Report calls to (*testing.T).Fatal from goroutines started by a test.
169+
- testinggoroutine
170+
# Check for common mistaken usages of tests and examples.
171+
- tests
172+
# Check for calls of (time.Time).Format or time.Parse with 2006-02-01.
173+
- timeformat
174+
# Report passing non-pointer or non-interface values to unmarshal.
175+
- unmarshal
176+
# Check for unreachable code.
177+
- unreachable
178+
# Check for invalid conversions of uintptr to unsafe.Pointer.
179+
- unsafeptr
180+
# Check for unused results of calls to some functions.
181+
- unusedresult
182+
# Checks for unused writes.
183+
- unusedwrite
43184
lll:
44185
line-length: 140
45186
misspell:
@@ -58,7 +199,7 @@ linters:
58199
- dogsled
59200
- dupl
60201
- errcheck
61-
- exportloopref
202+
- copyloopvar
62203
- exhaustive
63204
- funlen
64205
- gochecknoinits
@@ -67,7 +208,7 @@ linters:
67208
- gocyclo
68209
- gofmt
69210
- goimports
70-
- gomnd
211+
- mnd
71212
- goprintffuncname
72213
- gosec
73214
- gosimple
@@ -104,6 +245,19 @@ linters:
104245
# - testpackage
105246

106247
issues:
248+
# Show only new issues: if there are unstaged changes or untracked files,
249+
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
250+
# It's a super-useful option for integration of golangci-lint into existing
251+
# large codebase. It's not practical to fix all existing issues at the moment
252+
# of integration: much better don't allow issues in new code.
253+
# Default is false.
254+
new: false
255+
# Fix found issues (if it's supported by the linter)
256+
fix: false
257+
exclude-files:
258+
- \.pb\.go$
259+
exclude-dirs:
260+
- vendor/
107261
exclude-use-default: false
108262
exclude:
109263
# for "public interface + private struct implementation" cases only!
@@ -137,55 +291,77 @@ issues:
137291
linters:
138292
- gochecknoinits
139293

140-
# Show only new issues: if there are unstaged changes or untracked files,
141-
# only those changes are analyzed, else only changes in HEAD~ are analyzed.
142-
# It's a super-useful option for integration of golangci-lint into existing
143-
# large codebase. It's not practical to fix all existing issues at the moment
144-
# of integration: much better don't allow issues in new code.
145-
# Default is false.
146-
new: true
147-
148-
# Fix found issues (if it's supported by the linter)
149-
fix: false
150-
151-
severity:
152-
# Default value is empty string.
153-
# Set the default severity for issues. If severity rules are defined and the issues
154-
# do not match or no severity is provided to the rule this will be the default
155-
# severity applied. Severities should match the supported severity names of the
156-
# selected out format.
157-
# - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity
158-
# - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#severity
159-
# - GitHub: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
160-
default-severity: error
161-
162-
# The default value is false.
163-
# If set to true severity-rules regular expressions become case sensitive.
164-
case-sensitive: false
165-
166-
# Default value is empty list.
167-
# When a list of severity rules are provided, severity information will be added to lint
168-
# issues. Severity rules have the same filtering capability as exclude rules except you
169-
# are allowed to specify one matcher per severity rule.
170-
# Only affects out formats that support setting severity information.
171-
rules:
172-
- linters:
173-
- dupl
174-
severity: warning
175-
176294
run:
177295
issues-exit-code: 0
178296
tests: true
179-
skip-dirs:
180-
- vendor/
181-
skip-files:
182-
- \.pb\.go$
297+
298+
severity:
299+
# Set the default severity for issues.
300+
#
301+
# If severity rules are defined and the issues do not match or no severity is provided to the rule
302+
# this will be the default severity applied.
303+
# Severities should match the supported severity names of the selected out format.
304+
# - Code climate: https://docs.codeclimate.com/docs/issues#issue-severity
305+
# - Checkstyle: https://checkstyle.sourceforge.io/property_types.html#SeverityLevel
306+
# - GitHub: https://help.github.com/en/actions/reference/workflow-commands-for-github-actions#setting-an-error-message
307+
# - TeamCity: https://www.jetbrains.com/help/teamcity/service-messages.html#Inspection+Instance
308+
#
309+
# `@linter` can be used as severity value to keep the severity from linters (e.g. revive, gosec, ...)
310+
#
311+
# Default: ""
312+
default-severity: error
313+
314+
# If set to true `severity-rules` regular expressions become case-sensitive.
315+
# Default: false
316+
case-sensitive: true
317+
318+
# When a list of severity rules are provided, severity information will be added to lint issues.
319+
# Severity rules have the same filtering capability as exclude rules
320+
# except you are allowed to specify one matcher per severity rule.
321+
#
322+
# `@linter` can be used as severity value to keep the severity from linters (e.g. revive, gosec, ...)
323+
#
324+
# Only affects out formats that support setting severity information.
325+
#
326+
# Default: []
327+
rules:
328+
- linters:
329+
- dupl
330+
severity: info
331+
183332

184333
# output configuration options
185334
output:
186335
# colored-line-number|line-number|json|tab|checkstyle|code-climate|junit-xml|github-actions
187336
# default is "colored-line-number"
188-
format: checkstyle
337+
formats:
338+
- format: colored-line-number
339+
path: stderr
340+
- format: checkstyle
341+
path: linters-report.xml
342+
343+
344+
# Order to use when sorting results.
345+
# Require `sort-results` to `true`.
346+
# Possible values: `file`, `linter`, and `severity`.
347+
#
348+
# If the severity values are inside the following list, they are ordered in this order:
349+
# 1. error
350+
# 2. warning
351+
# 3. high
352+
# 4. medium
353+
# 5. low
354+
# Either they are sorted alphabetically.
355+
#
356+
# Default: ["file"]
357+
sort-order:
358+
- linter
359+
- severity
360+
- file # filepath, line, and column.
361+
362+
# Show statistics per linter.
363+
# Default: false
364+
show-stats: true
189365

190366
# print lines of code with issue, default is true
191367
print-issued-lines: true

cmd/aoc-cli/handlers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
)
2222

2323
func onExit(_ context.Context) cli.AfterFunc {
24-
return func(c *cli.Context) error {
24+
return func(_ *cli.Context) error {
2525
fmt.Println("Exit...")
2626

2727
return nil

internal/command/command_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func newMockHTTPClient(p returnParams) *mockHTTPClient {
3434
return &http.Response{
3535
Status: http.StatusText(p.status),
3636
StatusCode: p.status,
37-
Proto: "HTTP/1.0",
38-
ProtoMajor: 1,
39-
ProtoMinor: 0,
40-
Header: nil,
37+
Proto: req.Proto,
38+
ProtoMajor: req.ProtoMajor,
39+
ProtoMinor: req.ProtoMinor,
40+
Header: req.Header,
4141
Body: p.body,
4242
ContentLength: 0,
4343
TransferEncoding: nil,

0 commit comments

Comments
 (0)