Skip to content

Commit 99c156b

Browse files
authored
Merge pull request #14 from The-Mod-Elephant/feature/linter
feat(linter): Use golangci-lint for linting and error checking
2 parents 8d488dd + a4958bf commit 99c156b

23 files changed

Lines changed: 588 additions & 374 deletions

.envrc.sample

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/env sh
2+
set -a
3+
4+
use nix
5+
mkdir -p "${TMPDIR}" 2>/dev/null || true

.github/dependabot.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: github-actions
4+
directory: /
5+
schedule:
6+
interval: daily
7+
- package-ecosystem: cargo
8+
directory: /
9+
schedule:
10+
interval: daily

.github/workflows/main.yaml

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ jobs:
1313
pre-commit:
1414
runs-on: ubuntu-latest
1515
steps:
16-
- uses: actions/checkout@v3.0.2
16+
- uses: actions/checkout@v5
1717
with:
1818
set-safe-directory: true
1919
- uses: actions/setup-python@v3
20-
- uses: pre-commit/action@v3.0.0
20+
- uses: actions/setup-go@v5
21+
- name: Install Deps
22+
run: |
23+
go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.4.0
24+
pip install pre-commit
25+
pre-commit run --all-files
2126
test:
2227
name: test
2328
runs-on: ubuntu-latest
@@ -26,7 +31,7 @@ jobs:
2631
- name: Install git
2732
run: apk add --update --no-cache git
2833
- name: Checkout code
29-
uses: actions/checkout@v3.0.2
34+
uses: actions/checkout@v5
3035
with:
3136
fetch-depth: 0
3237
set-safe-directory: true
@@ -53,7 +58,7 @@ jobs:
5358
- name: Install git
5459
run: apk add --update --no-cache git
5560
- name: Checkout
56-
uses: actions/checkout@v3.0.2
61+
uses: actions/checkout@v5
5762
with:
5863
fetch-depth: 0
5964
set-safe-directory: true
@@ -79,26 +84,15 @@ jobs:
7984
tag_name: ${{ steps.get_tag.outputs.git_tag }}
8085
steps:
8186
- name: Checkout
82-
uses: actions/checkout@v3.0.2
87+
uses: actions/checkout@v5
8388
with:
8489
fetch-depth: 0
8590
set-safe-directory: true
86-
- name: Generate a changelog
87-
uses: orhun/git-cliff-action@v4
88-
id: git-cliff
89-
with:
90-
config: cliff.toml
91-
args: --verbose --latest
92-
env:
93-
OUTPUT: changelog.md
94-
- name: Get the tag
95-
id: get_tag
96-
run: echo ::set-output name=git_tag::${GITHUB_REF/refs\/tags\//}
9791
- name: Create Release
9892
id: create_release
99-
uses: ncipollo/release-action@v1.14.0
93+
uses: ncipollo/release-action@v1.18.0
10094
with:
101-
bodyFile: ./changelog.md
95+
generateReleaseNotes: true
10296
release-artifacts:
10397
name: Release Artifacts
10498
needs:
@@ -118,7 +112,7 @@ jobs:
118112
suffix: .exe
119113
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/')
120114
steps:
121-
- uses: actions/download-artifact@v4
115+
- uses: actions/download-artifact@v5
122116
with:
123117
name: infinity-dialog-${{ matrix.os }}-${{ matrix.arch }}
124118
- name: Upload Release Asset - ${{ matrix.os }}-${{ matrix.arch }}

.golangci.yml

Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
formatters:
2+
enable:
3+
- gofumpt
4+
- goimports
5+
6+
settings:
7+
gofmt:
8+
# simplify code: gofmt with `-s` option, true by default
9+
simplify: true
10+
11+
gofumpt:
12+
# Choose whether to use the extra rules
13+
extra-rules: true
14+
15+
goimports:
16+
# put imports beginning with prefix after 3rd-party packages;
17+
# it's a comma-separated list of prefixes
18+
local-prefixes:
19+
- go.opentelemetry.io/collector
20+
21+
issues:
22+
# Maximum issues count per one linter.
23+
max-issues-per-linter: 0
24+
# Maximum count of issues with the same text.
25+
max-same-issues: 0
26+
27+
linters:
28+
enable:
29+
- asasalint
30+
- contextcheck
31+
- copyloopvar
32+
- decorder
33+
- depguard
34+
- errcheck
35+
- errorlint
36+
- fatcontext
37+
- gocritic
38+
- gosec
39+
- govet
40+
- misspell
41+
- nolintlint
42+
- perfsprint
43+
- revive
44+
- staticcheck
45+
- testifylint
46+
- thelper
47+
- unconvert
48+
- unparam
49+
- unused
50+
- usestdlibvars
51+
- usetesting
52+
- whitespace
53+
54+
exclusions:
55+
presets:
56+
- std-error-handling
57+
58+
# Excluding configuration per-path, per-linter, per-text and per-source
59+
rules: []
60+
61+
# Log a warning if an exclusion rule is unused.
62+
warn-unused: true
63+
64+
# all available settings of specific linters
65+
settings:
66+
depguard:
67+
rules:
68+
denied-deps:
69+
deny:
70+
- pkg: "go.uber.org/atomic"
71+
desc: "Use 'sync/atomic' instead of go.uber.org/atomic"
72+
- pkg: "github.com/pkg/errors"
73+
desc: "Use 'errors' or 'fmt' instead of github.com/pkg/errors"
74+
- pkg: "github.com/hashicorp/go-multierror"
75+
desc: "Use go.uber.org/multierr instead of github.com/hashicorp/go-multierror"
76+
- pkg: "math/rand$"
77+
desc: "Use the newer 'math/rand/v2' instead of math/rand"
78+
- pkg: "sigs.k8s.io/yaml"
79+
desc: "Use 'go.yaml.in/yaml' instead of sigs.k8s.io/yaml"
80+
# Add a different guard rule so that we can ignore tests.
81+
ignore-in-test:
82+
# Allow in tests for testing pdata or other receivers/exporters that expect OTLP.
83+
files:
84+
- '!**/*_test.go'
85+
deny:
86+
- pkg: go.opentelemetry.io/proto
87+
desc: Use go.opentelemetry.io/collector/pdata instead
88+
89+
gocritic:
90+
disabled-checks:
91+
- commentedOutCode
92+
- deferInLoop
93+
- filepathJoin
94+
- hugeParam
95+
- importShadow
96+
- rangeValCopy
97+
- unnamedResult
98+
- whyNoLint
99+
enable-all: true
100+
101+
gosec:
102+
excludes:
103+
- G104 # FIXME
104+
- G402
105+
- G404
106+
107+
govet:
108+
disable:
109+
# We want to order fields according to readability and grouping them by use cases.
110+
# This linter does not offer a discernible performance improvement as the structs
111+
# defined in this repository are not in the execution hot path.
112+
# See https://github.com/open-telemetry/opentelemetry-collector/issues/2789
113+
- fieldalignment
114+
enable-all: true
115+
# settings per analyzer
116+
settings:
117+
printf: # analyzer name, run `go tool vet help` to see all analyzers
118+
funcs: # run `go tool vet help printf` to see available settings for `printf` analyzer
119+
- Infof
120+
- Warnf
121+
- Errorf
122+
- Fatalf
123+
124+
misspell:
125+
# Correct spellings using locale preferences for US or UK.
126+
# Default is to use a neutral variety of English.
127+
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
128+
locale: US
129+
ignore-rules:
130+
- cancelled
131+
132+
nolintlint:
133+
require-specific: true
134+
135+
perfsprint:
136+
# Optimizes even if it requires an int or uint type cast.
137+
int-conversion: true
138+
# Optimizes into `err.Error()` even if it is only equivalent for non-nil errors.
139+
err-error: true
140+
# Optimizes `fmt.Errorf`.
141+
errorf: true
142+
# Optimizes `fmt.Sprintf` with only one argument.
143+
sprintf1: true
144+
# Optimizes into strings concatenation.
145+
strconcat: true
146+
147+
revive:
148+
# minimal confidence for issues, default is 0.8
149+
confidence: 0.8
150+
rules:
151+
# Blank import should be only in a main or test package, or have a comment justifying it.
152+
- name: blank-imports
153+
# context.Context() should be the first parameter of a function when provided as argument.
154+
- name: context-as-argument
155+
# Basic types should not be used as a key in `context.WithValue`
156+
- name: context-keys-type
157+
# Importing with `.` makes the programs much harder to understand
158+
- name: dot-imports
159+
- name: early-return
160+
arguments:
161+
- preserveScope
162+
# Empty blocks make code less readable and could be a symptom of a bug or unfinished refactoring.
163+
- name: empty-block
164+
# for better readability, variables of type `error` must be named with the prefix `err`.
165+
- name: error-naming
166+
# for better readability, the errors should be last in the list of returned values by a function.
167+
- name: error-return
168+
# for better readability, error messages should not be capitalized or end with punctuation or a newline.
169+
- name: error-strings
170+
# report when replacing `errors.New(fmt.Sprintf())` with `fmt.Errorf()` is possible
171+
- name: errorf
172+
# incrementing an integer variable by 1 is recommended to be done using the `++` operator
173+
- name: increment-decrement
174+
# highlights redundant else-blocks that can be eliminated from the code
175+
- name: indent-error-flow
176+
# This rule suggests a shorter way of writing ranges that do not use the second value.
177+
- name: range
178+
# receiver names in a method should reflect the struct name (p for Person, for example)
179+
- name: receiver-naming
180+
# redefining built in names (true, false, append, make) can lead to bugs very difficult to detect.
181+
- name: redefines-builtin-id
182+
# redundant else-blocks that can be eliminated from the code.
183+
- name: superfluous-else
184+
arguments:
185+
- preserveScope
186+
# prevent confusing name for variables when using `time` package
187+
- name: time-naming
188+
# warns when an exported function or method returns a value of an un-exported type.
189+
- name: unexported-return
190+
- name: unnecessary-stmt
191+
# spots and proposes to remove unreachable code. also helps to spot errors
192+
- name: unreachable-code
193+
# Functions or methods with unused parameters can be a symptom of an unfinished refactoring or a bug.
194+
- name: unused-parameter
195+
# Since Go 1.18, interface{} has an alias: any. This rule proposes to replace instances of interface{} with any.
196+
- name: use-any
197+
# report when a variable declaration can be simplified
198+
- name: var-declaration
199+
# warns when initialism, variable or package naming conventions are not followed.
200+
- name: var-naming
201+
202+
staticcheck:
203+
checks:
204+
- all
205+
- -ST1000
206+
- -ST1021
207+
- -ST1022
208+
209+
testifylint:
210+
enable-all: true
211+
212+
thelper:
213+
benchmark:
214+
begin: false
215+
fuzz:
216+
begin: false
217+
tb:
218+
begin: false
219+
test:
220+
begin: false
221+
222+
# output configuration options
223+
output:
224+
# The formats used to render issues.
225+
formats:
226+
# Prints issues in a text format with colors, line number, and linter name.
227+
text:
228+
# Output path can be either `stdout`, `stderr` or path to the file to write to.
229+
path: stdout
230+
# print linter name in the end of issue text, default is true
231+
print-linter-name: true
232+
# print lines of code with issue, default is true
233+
print-issued-lines: true
234+
235+
# Show statistics per linter.
236+
show-stats: false
237+
238+
# options for analysis running
239+
run:
240+
# Allow multiple parallel golangci-lint instances running.
241+
# If false (default) - golangci-lint acquires file lock on start.
242+
allow-parallel-runners: true
243+
244+
# default concurrency is a available CPU number
245+
concurrency: 4
246+
247+
# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
248+
# If invoked with -mod=readonly, the go command is disallowed from the implicit
249+
# automatic updating of go.mod described above. Instead, it fails when any changes
250+
# to go.mod are needed. This setting is most useful to check that go.mod does
251+
# not need updates, such as in a continuous integration and testing system.
252+
# If invoked with -mod=vendor, the go command assumes that the vendor
253+
# directory holds the correct copies of dependencies and ignores
254+
# the dependency descriptions in go.mod.
255+
modules-download-mode: readonly
256+
257+
# exit code when at least one issue was found, default is 1
258+
issues-exit-code: 1
259+
260+
# include test files or not, default is true
261+
tests: true
262+
263+
# timeout for analysis, e.g. 30s, 5m, default is 1m
264+
timeout: 10m
265+
266+
version: "2"

.mise.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
[tools]
2-
go = "1.23"
2+
go = "1.25"
3+
golangci-lint = "latest"

0 commit comments

Comments
 (0)