Skip to content

Commit 998dfd5

Browse files
committed
update linter and fix linter issues
1 parent f24e36e commit 998dfd5

5 files changed

Lines changed: 75 additions & 55 deletions

File tree

.github/workflows/go.yaml

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,34 +5,36 @@ on:
55
branches:
66
- main
77
pull_request:
8+
types:
9+
- opened
10+
- reopened
11+
- synchronize
12+
- ready_for_review
813

914
jobs:
1015
build:
11-
if: "!contains(github.event.commits[0].message, '[skip ci]')"
16+
if: ${{ github.event_name == 'push' || !github.event.pull_request.draft || !contains(github.event.commits[0].message, '[skip ci]') }}
1217
timeout-minutes: 15
1318

1419
name: Build
1520
runs-on: ubuntu-latest
1621
strategy:
1722
matrix:
18-
go: [1.17, 1.18, 1.19]
23+
go: [ "1.17", "1.18" ]
1924

2025
steps:
2126
- name: Set up Go 1.x
22-
uses: actions/setup-go@v2
27+
uses: actions/setup-go@v6
2328
with:
2429
go-version: ${{ matrix.go }}
2530
id: go
2631

2732
- name: Check out code into the Go module directory
28-
uses: actions/checkout@v2
33+
uses: actions/checkout@v5
2934

3035
- name: Install linters
3136
run: make install-linters
3237

33-
- name: Get dependencies
34-
run: go mod download
35-
3638
- name: Run tests
3739
run: make test
3840

.golangci.yml

Lines changed: 57 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,70 @@
1+
version: "2"
12
run:
2-
deadline: 5m
3-
3+
modules-download-mode: readonly
44
linters:
55
enable:
6-
- asasalint # check for pass []any as any in variadic func(...any)
7-
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
6+
- asasalint # Check for pass []any as any in variadic func(...any)
7+
- asciicheck # Checks that code identifiers do not have non-ASCII symbols
88
- bidichk # Checks for dangerous unicode character sequences
9-
- containedctx # detects struct contained context.Context field
10-
- contextcheck # check the function whether use a non-inherited context
11-
- cyclop # checks function and package cyclomatic complexity
12-
- decorder # check declaration order and count of types, constants, variables and functions
13-
- depguard # Go linter that checks if package imports are in a list of acceptable packages
14-
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
15-
- durationcheck # check for two durations multiplied together
16-
- errcheck # checking for unchecked errors
17-
- errname # Checks that errors are prefixed with the `Err` and error types are suffixed with the `Error`
18-
- errorlint # finds code that will cause problems with the error wrapping scheme introduced in Go 1.13
19-
- exportloopref # checks for pointers to enclosing loop variables
20-
- funlen # Tool for detection of long functions
21-
- gci # controls golang package import order and makes it always deterministic
9+
- containedctx # Detects struct contained context.Context field
10+
- contextcheck # Check whether the function uses a non-inherited context
11+
- copyloopvar # Detects places where loop variables are copied
12+
- cyclop # Checks function and package cyclomatic complexity
13+
- decorder # Check declaration order of types, constants, variables and functions
14+
- dogsled # Checks assignments with too many blank identifiers
15+
- durationcheck # Check for two durations multiplied together
16+
- embeddedstructfieldcheck # Checks embedded struct field positioning and formatting
17+
- err113 # Check errors handling expressions
18+
- errcheck # Checks for unchecked errors in Go code
19+
- errname # Checks that sentinel errors are prefixed with Err
20+
- errorlint # Find code that will cause problems with error wrapping
21+
- funlen # Checks for long functions
2222
- gocognit # Computes and checks the cognitive complexity of functions
2323
- gocritic # Provides diagnostics that check for bugs, performance and style issues
2424
- gocyclo # Computes and checks the cyclomatic complexity of functions
2525
- godot # Check if comments end in a period
26-
- goerr113 # Golang linter to check the errors handling expressions
27-
- gosimple # Linter for Go source code that specializes in simplifying a code
28-
- govet # reports suspicious constructs, such as Printf calls with wrong arguments
26+
- govet # Examines Go source code and reports suspicious constructs
27+
- grouper # Analyze expression groups
28+
- iface # Detect the incorrect use of interfaces
2929
- ineffassign # Detects when assignments to existing variables are not used
30-
- maintidx # measures the maintainability index of each function
31-
- makezero # Finds slice declarations with non-zero initial length
32-
- misspell # Finds commonly misspelled English words in comments
33-
- nakedret # Finds naked returns in functions
30+
- intrange # Find places where for loops could use an integer range
31+
- ireturn # Accept Interfaces, Return Concrete Types
32+
- maintidx # Measures the maintainability index of each function
33+
- makezero # Find slice declarations with non-zero initial length
34+
- mirror # Reports wrong mirror patterns of bytes/strings usage
35+
- misspell # Finds commonly misspelled English words
36+
- modernize # Suggest simplifications using modern Go features
37+
- nakedret # Finds naked returns in functions longer than a maximum size
3438
- nestif # Reports deeply nested if statements
35-
- nilerr # Finds the code that returns nil even if it checks that the error is not nil
36-
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value
37-
- prealloc # Finds slice declarations that could potentially be preallocated
38-
- predeclared # find code that shadows one of Go's predeclared identifiers
39-
- revive # drop-in replacement of golint
40-
- staticcheck # drop-in replacement of go vet
41-
- stylecheck # Stylecheck is a replacement for golint
42-
- tenv # detects using os.Setenv instead of t.Setenv
43-
- thelper # checks the consistency of test helpers
44-
- tparallel # detects inappropriate usage of t.Parallel()
45-
- typecheck # parses and type-checks Go code
39+
- nilerr # Finds code that returns nil even if it checks that error is not nil
40+
- nilnil # Checks that there is no simultaneous return of nil error and invalid value
41+
- noctx # Detects missing usage of context.Context
42+
- perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative
43+
- prealloc # Find slice declarations that could be pre-allocated
44+
- predeclared # Find code that shadows one of Go's predeclared identifiers
45+
- reassign # Checks that package variables are not reassigned
46+
- revive # Fast, configurable, extensible linter for Go
47+
- staticcheck # Set of rules from staticcheck
48+
- thelper # Detects test helpers which do not call t.Helper()
49+
- tparallel # Detects inappropriate usage of t.Parallel()
4650
- unconvert # Remove unnecessary type conversions
4751
- unparam # Reports unused function parameters
4852
- unused # Checks Go code for unused constants, variables, functions and types
49-
- usestdlibvars # detect the possibility to use variables/constants from the Go standard library
50-
- wastedassign # finds wasted assignment statements
51-
- whitespace # detects leading and trailing whitespace
52-
53-
issues:
54-
exclude-use-default: false
55-
exclude-rules:
56-
- linters:
57-
- goerr113
58-
text: "do not define dynamic errors"
53+
- usestdlibvars # Detect the possibility to use variables/constants from stdlib
54+
- wastedassign # Finds wasted assignment statements
55+
- whitespace # Checks for unnecessary newlines
56+
- wrapcheck # Checks that errors returned from external packages are wrapped
57+
settings:
58+
whitespace:
59+
multi-if: true # Enforces newlines (or comments) after every multi-line if statement
60+
multi-func: true # Enforces newlines (or comments) after every multi-line function signature
61+
exclusions:
62+
rules:
63+
- linters:
64+
- err113
65+
text: do not define dynamic errors
66+
formatters:
67+
enable:
68+
- gci # Check if code and import statements are formatted, with additional rules
69+
- gofmt # Check if the code is formatted according to 'gofmt' command
70+
- goimports # Checks if the code and import statements are formatted according to the 'goimports' command

Makefile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
GOLANGCI_VERSION = v2.6.1
2+
13
help: ## show help, shown by default if no target is specified
24
@grep -E '^[0-9a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'
35

@@ -15,4 +17,4 @@ test-coverage-web: test-coverage ## run unit tests and show test coverage in bro
1517
go tool cover -html=.testCoverage
1618

1719
install-linters: ## install all used linters
18-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $$(go env GOPATH)/bin v1.49.0
20+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCI_VERSION}

map.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func (m *Map) Range(f func(key string, value interface{}) bool) {
3535
// UnmarshalJSON implements the json.Unmarshaler interface.
3636
func (m *Map) UnmarshalJSON(b []byte) error {
3737
if err := json.Unmarshal(b, &m.Data); err != nil {
38-
return err
38+
return fmt.Errorf("failed to unmarshal orderedmap: %w", err)
3939
}
4040

4141
m.rebuildKeys()

map_value.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,5 +35,9 @@ func (s *Entry) UnmarshalJSON(b []byte) error {
3535

3636
// MarshalJSON implements the json.Marshaler interface.
3737
func (s *Entry) MarshalJSON() ([]byte, error) {
38-
return json.Marshal(s.Value)
38+
b, err := json.Marshal(s.Value)
39+
if err != nil {
40+
return nil, fmt.Errorf("marshalling entry: %w", err)
41+
}
42+
return b, nil
3943
}

0 commit comments

Comments
 (0)