Skip to content

Commit e0d4e87

Browse files
authored
Merge pull request #3 from scaleway/feature/linter
Feature/linter
2 parents f6538cc + a89265a commit e0d4e87

File tree

8 files changed

+272
-6
lines changed

8 files changed

+272
-6
lines changed

.github/workflows/go.yml

+6
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,11 @@ jobs:
2121
with:
2222
go-version: '1.23'
2323

24+
- name: Install golangci-lint
25+
run: curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin
26+
27+
- name: Lint
28+
run: make golint
29+
2430
- name: Test
2531
run: make gotest

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
# Test binary, built with `go test -c`
1212
*.test
13+
coverage.txt
14+
coverage/
1315

1416
# Output of the go coverage tool, specifically when used with LiteIDE
1517
*.out

.golangci.yml

+239
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
# options for analysis running
2+
run:
3+
# default concurrency is a available CPU number
4+
concurrency: 4
5+
6+
# timeout for analysis, e.g. 30s, 5m, default is 1m
7+
timeout: 20m
8+
9+
# exit code when at least one issue was found, default is 1
10+
issues-exit-code: 1
11+
12+
# include test files or not, default is true
13+
tests: true
14+
15+
# which dirs to skip: issues from them won't be reported;
16+
# can use regexp here: generated.*, regexp is applied on full path;
17+
# default value is empty list, but default dirs are skipped independently
18+
# from this option's value (see exclude-dirs-use-default).
19+
exclude-dirs:
20+
- third_party
21+
- local
22+
- cmd/otelcontribcol
23+
- cmd/oteltestbedcol
24+
25+
# default is true. Enables skipping of directories:
26+
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
27+
exclude-dirs-use-default: false
28+
29+
# which files to skip: they will be analyzed, but issues from them
30+
# won't be reported. Default value is empty list, but there is
31+
# no need to include all autogenerated files, we confidently recognize
32+
# autogenerated files. If it's not please let us know.
33+
skip-files:
34+
35+
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
36+
# If invoked with -mod=readonly, the go command is disallowed from the implicit
37+
# automatic updating of go.mod described above. Instead, it fails when any changes
38+
# to go.mod are needed. This setting is most useful to check that go.mod does
39+
# not need updates, such as in a continuous integration and testing system.
40+
# If invoked with -mod=vendor, the go command assumes that the vendor
41+
# directory holds the correct copies of dependencies and ignores
42+
# the dependency descriptions in go.mod.
43+
modules-download-mode: readonly
44+
45+
# output configuration options
46+
output:
47+
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
48+
formats: colored-line-number
49+
50+
# print lines of code with issue, default is true
51+
print-issued-lines: true
52+
53+
# print linter name in the end of issue text, default is true
54+
print-linter-name: true
55+
56+
# all available settings of specific linters
57+
linters-settings:
58+
gci:
59+
sections:
60+
- standard
61+
- default
62+
- prefix(github.com/scaleway/opentelemetry-collector-scaleway)
63+
64+
govet:
65+
# settings per analyzer
66+
settings:
67+
printf: # analyzer name, run `go tool vet help` to see all analyzers
68+
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
69+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Infof
70+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Warnf
71+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Errorf
72+
- (github.com/golangci/golangci-lint/pkg/logutils.Log).Fatalf
73+
74+
enable-all: true
75+
# TODO: Enable this and fix the alignment issues.
76+
disable:
77+
- fieldalignment
78+
79+
revive:
80+
# minimal confidence for issues, default is 0.8
81+
min-confidence: 0.8
82+
rules:
83+
# Blank import should be only in a main or test package, or have a comment justifying it.
84+
- name: blank-imports
85+
# context.Context() should be the first parameter of a function when provided as argument.
86+
- name: context-as-argument
87+
# Basic types should not be used as a key in `context.WithValue`
88+
- name: context-keys-type
89+
# Importing with `.` makes the programs much harder to understand
90+
- name: dot-imports
91+
# Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
92+
- name: empty-block
93+
# for better readability, variables of type `error` must be named with the prefix `err`.
94+
- name: error-naming
95+
# for better readability, the errors should be last in the list of returned values by a function.
96+
- name: error-return
97+
# for better readability, error messages should not be capitalized or end with punctuation or a newline.
98+
- name: error-strings
99+
# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
100+
- name: errorf
101+
# incrementing an integer variable by 1 is recommended to be done using the `++` operator
102+
- name: increment-decrement
103+
# highlights redundant else-blocks that can be eliminated from the code
104+
- name: indent-error-flow
105+
# This rule suggests a shorter way of writing ranges that do not use the second value.
106+
- name: range
107+
# receiver names in a method should reflect the struct name (p for Person, for example)
108+
- name: receiver-naming
109+
# redefining built in names (true, false, append, make) can lead to bugs very difficult to detect.
110+
- name: redefines-builtin-id
111+
# redundant else-blocks that can be eliminated from the code.
112+
- name: superfluous-else
113+
# prevent confusing name for variables when using `time` package
114+
- name: time-naming
115+
# warns when an exported function or method returns a value of an un-exported type.
116+
- name: unexported-return
117+
# spots and proposes to remove unreachable code. also helps to spot errors
118+
- name: unreachable-code
119+
# Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
120+
- name: unused-parameter
121+
# Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any.
122+
- name: use-any
123+
# report when a variable declaration can be simplified
124+
- name: var-declaration
125+
# warns when initialism, variable or package naming conventions are not followed.
126+
- name: var-naming
127+
128+
goimports:
129+
# put imports beginning with prefix after 3rd-party packages;
130+
# it's a comma-separated list of prefixes
131+
local-prefixes: github.com/open-telemetry/opentelemetry-collector-contrib
132+
133+
misspell:
134+
# Correct spellings using locale preferences for US or UK.
135+
# Default is to use a neutral variety of English.
136+
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
137+
locale: US
138+
ignore-words:
139+
- cancelled
140+
- metre
141+
- meter
142+
- metres
143+
- kilometre
144+
- kilometres
145+
146+
depguard:
147+
rules:
148+
denied-deps:
149+
deny:
150+
- pkg: go.uber.org/atomic
151+
desc: "Use 'sync/atomic' instead of go.uber.org/atomic"
152+
- pkg: github.com/pkg/errors
153+
desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors"
154+
- pkg: github.com/hashicorp/go-multierror
155+
desc: "Use go.uber.org/multierr instead of github.com/hashicorp/go-multierror"
156+
- pkg: "math/rand$"
157+
desc: "Use math/rand/v2 instead of math/rand"
158+
# Add a different guard rule so that we can ignore tests.
159+
ignore-in-test:
160+
deny:
161+
- pkg: go.opentelemetry.io/proto
162+
desc: "Use go.opentelemetry.io/collector/pdata instead"
163+
# Allow in tests for testing pdata or other receivers/exporters that expect OTLP.
164+
files:
165+
- "!**/*_test.go"
166+
167+
exhaustive:
168+
explicit-exhaustive-switch: true
169+
ignore-enum-members: "pmetric.MetricTypeEmpty"
170+
171+
nolintlint:
172+
require-specific: true
173+
174+
predeclared:
175+
ignore: copy
176+
177+
testifylint:
178+
disable:
179+
- float-compare
180+
- require-error
181+
- suite-subtest-run
182+
- encoded-compare # has false positives that cannot be fixed with testifylint-fix
183+
enable-all: true
184+
thelper:
185+
test:
186+
begin: false
187+
benchmark:
188+
begin: false
189+
tb:
190+
begin: false
191+
fuzz:
192+
begin: false
193+
194+
linters:
195+
enable:
196+
- copyloopvar
197+
- decorder
198+
- depguard
199+
- errcheck
200+
- errorlint
201+
- exhaustive
202+
- gci
203+
- gocritic
204+
- gofmt
205+
- goimports
206+
- gosec
207+
- govet
208+
- misspell
209+
- nolintlint
210+
- predeclared
211+
- reassign
212+
- revive
213+
- staticcheck
214+
- tenv
215+
- testifylint
216+
- thelper
217+
- unconvert
218+
- unparam
219+
- unused
220+
- usestdlibvars
221+
- wastedassign
222+
- whitespace
223+
224+
issues:
225+
# Excluding configuration per-path, per-linter, per-text and per-source
226+
exclude-rules:
227+
- text: "G404:"
228+
linters:
229+
- gosec
230+
- text: "G402:"
231+
linters:
232+
- gosec
233+
- text: "G115:"
234+
linters:
235+
- gosec
236+
- path: "pagefile.go" # This exclusion is required for Windows only
237+
text: "cachedBytes"
238+
linters:
239+
- unused

Makefile

+9
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,12 @@ for-all-target: $(GOMODULES)
2020
.PHONY: gotest
2121
gotest:
2222
@$(MAKE) for-all-target TARGET="test"
23+
24+
.PHONY: gotest-with-cover
25+
gotest-with-cover:
26+
@$(MAKE) for-all-target TARGET="test-with-cover"
27+
$(GOCMD) tool covdata textfmt -i=./coverage/unit -o ./coverage.txt
28+
29+
.PHONY: golint
30+
golint:
31+
@$(MAKE) for-all-target TARGET="lint"

Makefile.Common

+11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
GOCMD?= go
2+
COVER_PKGS := $(shell go list ./... | tr "\n" ",")
3+
LINT := golangci-lint
24

35
.PHONY: tests
46
test:
57
$(GOCMD) test ./...
8+
9+
.PHONY: test-with-cover
10+
test-with-cover:
11+
mkdir -p $(PWD)/coverage/unit
12+
$(GOCMD) test -cover -covermode=atomic -coverpkg $(COVER_PKGS) -test.gocoverdir="$(PWD)/coverage/unit" ./...
13+
14+
.PHONY: lint
15+
lint:
16+
$(LINT) run

receiver/scwaudittrail/factory_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func TestCreateReceiver(t *testing.T) {
2323
assert.Error(t, err)
2424

2525
// Override for test.
26-
rCfg.makeClient = func(c *Config) (Client, error) {
26+
rCfg.makeClient = func(_ *Config) (Client, error) {
2727
ctrl := gomock.NewController(t)
2828
client := NewMockClient(ctrl)
2929
return client, nil

receiver/scwaudittrail/receiver.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,12 @@ import (
55
"sync"
66
"time"
77

8-
"go.uber.org/zap"
9-
108
audit_trail "github.com/scaleway/scaleway-sdk-go/api/audit_trail/v1alpha1"
119
"go.opentelemetry.io/collector/component"
1210
"go.opentelemetry.io/collector/consumer"
1311
"go.opentelemetry.io/collector/receiver"
1412
"go.opentelemetry.io/collector/receiver/receiverhelper"
13+
"go.uber.org/zap"
1514
)
1615

1716
// auditTrailReceiver implements a custom OpenTelemetry log receiver.

receiver/scwaudittrail/receiver_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616

1717
func TestNewLogsReceiver(t *testing.T) {
1818
rCfg := createDefaultConfig().(*Config)
19-
rCfg.makeClient = func(c *Config) (Client, error) {
19+
rCfg.makeClient = func(_ *Config) (Client, error) {
2020
ctrl := gomock.NewController(t)
2121
client := NewMockClient(ctrl)
2222
return client, nil
@@ -37,7 +37,7 @@ func TestNewLogsReceiver(t *testing.T) {
3737

3838
func TestHandleEvent(t *testing.T) {
3939
rCfg := createDefaultConfig().(*Config)
40-
rCfg.makeClient = func(c *Config) (Client, error) {
40+
rCfg.makeClient = func(_ *Config) (Client, error) {
4141
ctrl := gomock.NewController(t)
4242
client := NewMockClient(ctrl)
4343
return client, nil
@@ -67,7 +67,7 @@ func TestFetchEvents(t *testing.T) {
6767
Events: []*audit_trail.Event{getEvent()},
6868
}
6969

70-
rCfg.makeClient = func(c *Config) (Client, error) {
70+
rCfg.makeClient = func(_ *Config) (Client, error) {
7171
ctrl := gomock.NewController(t)
7272
client := NewMockClient(ctrl)
7373

0 commit comments

Comments
 (0)