Skip to content

Commit 94a84b5

Browse files
committed
Upgrade to golangci-lint v2
1 parent 41ed6d2 commit 94a84b5

File tree

16 files changed

+79
-96
lines changed

16 files changed

+79
-96
lines changed

.github/workflows/golangci-lint.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
- run: go version
2727

2828
- name: golangci-lint
29-
uses: golangci/golangci-lint-action@v6
29+
uses: golangci/golangci-lint-action@v8
3030
with:
31-
version: v1.61 # switch to latest if development is unfreezed
31+
version: v2.1.6 # switch to latest if development is unfreezed
3232
args: --timeout=5m

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ jobs:
7070
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
7171

7272
- name: Publish the coverage to codecov
73-
uses: codecov/codecov-action@v4
73+
uses: codecov/codecov-action@v5
7474
with:
7575
token: ${{ secrets.CODECOV_TOKEN }}
7676
directory: ./coverage/

.golangci.yml

Lines changed: 57 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
1-
linters-settings:
2-
exhaustive:
3-
default-signifies-exhaustive: true
4-
gocyclo:
5-
min-complexity: 15
6-
gomodguard:
7-
blocked:
8-
modules:
9-
- github.com/pkg/errors:
10-
recommendations:
11-
- errors
12-
gomoddirectives:
13-
replace-allow-list:
14-
- github.com/go-json-experiment/json
15-
- golang.org/x/exp
16-
govet:
17-
enable:
18-
- nilness
19-
- shadow
20-
stylecheck:
21-
# STxxxx checks in https://staticcheck.io/docs/configuration/options/#checks
22-
# Default: ["*"]
23-
checks: ["all", "-ST1000", "-ST1003"]
24-
1+
version: "2"
2+
run:
3+
go: "1.22"
4+
# issues:
5+
# fix: true
256
linters:
267
enable:
278
- asasalint # Check for pass []any as any in variadic func(...any)
289
- asciicheck # Simple linter to check that your code does not contain non-ASCII identifiers
2910
- bidichk # Checks for dangerous unicode character sequences
3011
- bodyclose # Checks whether HTTP response body is closed successfully
31-
- copyloopvar # Detects places where loop variables are copied
12+
# - copyloopvar # Detects places where loop variables are copied
3213
- decorder # Check declaration order and count of types, constants, variables and functions
3314
- dogsled # Checks assignments with too many blank identifiers (e.g. x, _, _, _, := f())
3415
- dupl # Tool for code clone detection
@@ -38,25 +19,20 @@ linters:
3819
- 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.
3920
- errname # Checks that sentinel errors are prefixed with the `Err` and error types are suffixed with the `Error`.
4021
- 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.
22+
# - exportloopref # checks for pointers to enclosing loop variables
4123
- forcetypeassert # finds forced type assertions
42-
- gci # Gci control golang package import order and make it always deterministic.
4324
- gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid.
4425
- gocognit # Computes and checks the cognitive complexity of functions
4526
- goconst # Finds repeated strings that could be replaced by a constant
4627
- gocritic # The most opinionated Go source code linter
4728
- gocyclo # Computes and checks the cyclomatic complexity of functions
48-
# - godox # Tool for detection of FIXME, TODO and other comment keywords
4929
# - goerr113 # Golang linter to check the errors handling expressions
50-
- gofmt # Gofmt checks whether code was gofmt-ed. By default this tool runs with -s option to check for code simplification
51-
- gofumpt # Gofumpt checks whether code was gofumpt-ed.
5230
- goheader # Checks is file header matches to pattern
53-
- goimports # Goimports does everything that gofmt does. Additionally it checks unused imports
54-
- gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
31+
# - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' directives in go.mod.
5532
- 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.
5633
- goprintffuncname # Checks that printf-like functions are named with `f` at the end
5734
- gosec # Inspects source code for security problems
5835
- gosmopolitan # Report certain i18n/l10n anti-patterns in your Go codebase
59-
- gosimple # Linter for Go source code that specializes in simplifying a code
6036
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
6137
- grouper # An analyzer to analyze expression groups
6238
- importas # Enforces consistent import aliases
@@ -81,11 +57,8 @@ linters:
8157
- sloglint # Ensure consistent code style when using log/slog
8258
- spancheck # Checks for mistakes with OpenTelemetry/Census spans
8359
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
84-
- stylecheck # Stylecheck is a replacement for golint
85-
- tenv # tenv is analyzer that detects using os.Setenv instead of t.Setenv since Go1.17
8660
- testifylint # Checks usage of github.com/stretchr/testify.
8761
- tparallel # tparallel detects inappropriate usage of t.Parallel() method in your Go test codes
88-
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
8962
- unconvert # Remove unnecessary type conversions
9063
- unparam # Reports unused function parameters
9164
- unused # Checks Go code for unused constants, variables, functions and types
@@ -104,7 +77,7 @@ linters:
10477
- gochecknoglobals # Checks that no globals are present in Go code
10578
- gochecknoinits # Checks that no init functions are present in Go code
10679
- godot # Check if comments end in a period
107-
- gomnd # An analyzer to detect magic numbers.
80+
- godox # Tool for detection of FIXME, TODO and other comment keywords
10881
- inamedparam # Reports interfaces with unnamed method parameters.
10982
- interfacebloat # A linter that checks the number of methods inside an interface
11083
- ireturn # Accept Interfaces, Return Concrete Types
@@ -125,38 +98,51 @@ linters:
12598
- varnamelen # checks that the length of a variable's name matches its scope
12699
- wrapcheck # Checks that errors returned from external packages are wrapped
127100
- wsl # Whitespace Linter - Forces you to use empty lines!
128-
129-
issues:
130-
exclude-use-default: false
131-
exclude-rules:
132-
# Allow complex tests, better to be self contained
133-
- path: _test\.go
134-
linters:
135-
- dupword
136-
- forcetypeassert
137-
- gocognit
138-
- gocyclo
139-
140-
# Allow complex main function and lower security in examples
141-
- path: cmd/ocfclient/main\.go
142-
linters:
143-
- gocognit
144-
- goconst
145-
- gocyclo
146-
- gosec
147-
- nestif
148-
149-
- path: pkg/error
150-
text: "package name error has same name as predeclared identifier"
151-
linters:
152-
- predeclared
153-
154-
- text: "var-naming:|exported:|package-comments:"
155-
linters:
156-
- revive
157-
158-
# Fix found issues (if it's supported by the linter).
159-
# fix: true
160-
161-
run:
162-
go: "1.22"
101+
settings:
102+
gocyclo:
103+
min-complexity: 15
104+
govet:
105+
enable:
106+
- nilness
107+
- shadow
108+
exclusions:
109+
generated: lax
110+
presets:
111+
- comments
112+
- common-false-positives
113+
- legacy
114+
- std-error-handling
115+
# Log a warning if an exclusion rule is unused.
116+
# Default: false
117+
warn-unused: true
118+
rules:
119+
- linters:
120+
- dupword
121+
- forcetypeassert
122+
- gocognit
123+
- gocyclo
124+
path: _test\.go
125+
- linters:
126+
- gocognit
127+
- goconst
128+
- gocyclo
129+
- gosec
130+
- nestif
131+
path: cmd/ocfclient/main\.go
132+
- linters:
133+
- predeclared
134+
path: pkg/error
135+
text: package name error has same name as predeclared identifier
136+
- linters:
137+
- revive
138+
text: 'var-naming:|exported:|package-comments:'
139+
paths:
140+
- examples
141+
formatters:
142+
enable:
143+
- gci
144+
- gofmt
145+
- gofumpt
146+
- goimports
147+
exclusions:
148+
generated: lax

bridge/device/cloud/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ func (c *Manager) handleDeviceResource(r *net.Request) (*pool.Message, error) {
425425
}
426426

427427
func (c *Manager) handleDiscoveryResource(r *net.Request) (*pool.Message, error) {
428-
links := c.getLinks(schema.Endpoints{}, c.deviceID, getResourceTypesFilter(r.Message.Options()), resources.PublishToCloud)
428+
links := c.getLinks(schema.Endpoints{}, c.deviceID, getResourceTypesFilter(r.Options()), resources.PublishToCloud)
429429
links = patchDeviceLink(links)
430430
links = discovery.PatchLinks(links, c.deviceID.String())
431431
return resources.CreateResponseContent(r.Context(), links, codes.Content)
@@ -454,7 +454,7 @@ func (c *Manager) serveCOAP(w mux.ResponseWriter, request *mux.Message) {
454454
}
455455
return
456456
}
457-
request.Message.AddQuery("di=" + c.deviceID.String())
457+
request.AddQuery("di=" + c.deviceID.String())
458458
r := net.Request{
459459
Message: request.Message,
460460
Endpoints: nil,

bridge/net/request_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestURIPath(t *testing.T) {
7373
reqNoPath := &net.Request{
7474
Message: pool.NewMessage(context.Background()),
7575
}
76-
require.Equal(t, "", reqNoPath.URIPath())
76+
require.Empty(t, reqNoPath.URIPath())
7777
}
7878

7979
func TestInterface(t *testing.T) {
@@ -89,12 +89,12 @@ func TestInterface(t *testing.T) {
8989
Message: pool.NewMessage(context.Background()),
9090
}
9191
reqNoInterface.AddQuery("q1=v1")
92-
require.Equal(t, "", reqNoInterface.Interface())
92+
require.Empty(t, reqNoInterface.Interface())
9393

9494
reqNoQuery := &net.Request{
9595
Message: pool.NewMessage(context.Background()),
9696
}
97-
require.Equal(t, "", reqNoQuery.Interface())
97+
require.Empty(t, reqNoQuery.Interface())
9898
}
9999

100100
func TestDeviceID(t *testing.T) {

bridge/resources/device/resource.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ func (d *Resource) Get(request *net.Request) (*pool.Message, error) {
6969
// SpecificationVersion: "ocf.2.0.5",
7070
}
7171
if request.Interface() == interfaces.OC_IF_BASELINE {
72-
deviceProperties.ResourceTypes = d.Resource.GetResourceTypes()
73-
deviceProperties.Interfaces = d.Resource.ResourceInterfaces
72+
deviceProperties.ResourceTypes = d.GetResourceTypes()
73+
deviceProperties.Interfaces = d.ResourceInterfaces
7474
}
7575
properties := resources.MergeCBORStructs(additionalProperties, deviceProperties)
7676
res := pool.NewMessage(request.Context())

bridge/resources/resource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ func (r *Resource) observerHandler(req *net.Request, createSubscription bool) (*
248248
r.removeSubscription(req.Conn.RemoteAddr().String())
249249
return r.getHandler(req)
250250
}
251-
req.Message.Hijack()
251+
req.Hijack()
252252
sequence := atomic.NewUint32(1)
253253
var cancel func()
254254
var err error

bridge/service/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ func (c *Service) LoadDevice(di uuid.UUID) (Device, error) {
8383
}
8484

8585
func (c *Service) handleDiscoverAllLinks(req *net.Request) (*pool.Message, error) {
86-
if req.Message.Type() != message.Acknowledgement && req.Message.Type() != message.Reset {
86+
if req.Type() != message.Acknowledgement && req.Type() != message.Reset {
8787
// discovery is only allowed for CON, NON, UNSET messages
8888
c.onDiscoveryDevices(req)
8989
}

bridge/test/test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const (
5353
func MakeConfig(t *testing.T) service.Config {
5454
var cfg service.Config
5555
cfg.API.CoAP.ID = BRIDGE_SERVICE_PIID
56-
cfg.API.CoAP.Config.ExternalAddresses = []string{BRIDGE_DEVICE_HOST, BRIDGE_DEVICE_HOST_IPv6}
56+
cfg.API.CoAP.ExternalAddresses = []string{BRIDGE_DEVICE_HOST, BRIDGE_DEVICE_HOST_IPv6}
5757
require.NoError(t, cfg.API.Validate())
5858
return cfg
5959
}

client/observeDevices.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,7 @@ func newDevicesObserver(c *Client, observerConfiguration ObserverConfig, discove
7676
wg.Add(1)
7777
go func() {
7878
defer wg.Done()
79-
for {
80-
if !obs.poll(ctx) {
81-
break
82-
}
79+
for obs.poll(ctx) {
8380
}
8481
}()
8582
return obs

0 commit comments

Comments
 (0)