Skip to content

Commit fb64456

Browse files
authored
Merge pull request #14 from codeGROOVE-dev/relint
Modernize code-base & improve code quality
2 parents 34e3772 + 7a031ef commit fb64456

File tree

15 files changed

+542
-303
lines changed

15 files changed

+542
-303
lines changed

.github/dependabot.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
version: 2
22
updates:
3-
- package-ecosystem: gomod
4-
directory: "/"
5-
schedule:
6-
interval: daily
7-
time: "04:00"
8-
open-pull-requests-limit: 10
3+
- package-ecosystem: gomod
4+
directory: "/"
5+
schedule:
6+
interval: daily
7+
time: "04:00"
8+
open-pull-requests-limit: 10

.github/workflows/workflow.yaml

Lines changed: 15 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -2,64 +2,26 @@ name: Go
22

33
on:
44
push:
5+
branches: [main]
56
pull_request:
6-
branches:
7-
- master
7+
branches: [main]
88

99
jobs:
10-
golangci-lint:
10+
build:
1111
runs-on: ubuntu-latest
1212
steps:
13-
- uses: actions/checkout@v4
14-
- uses: actions/setup-go@v5
15-
with:
16-
go-version: stable
17-
- name: golangci-lint
18-
uses: golangci/golangci-lint-action@v6
19-
with:
20-
version: latest
21-
tests:
22-
runs-on: ${{ matrix.os }}
23-
strategy:
24-
fail-fast: false
25-
matrix:
26-
go-version: ['1.20', '1.21', '1.22', '1.23', '1.24']
27-
os: [ubuntu-latest, macos-latest, windows-latest]
28-
env:
29-
OS: ${{ matrix.os }}
30-
GOVERSION: ${{ matrix.go-version }}
31-
steps:
32-
- uses: actions/checkout@v4
33-
- name: Setup Go ${{ matrix.go-version }}
34-
uses: actions/setup-go@v5
35-
with:
36-
go-version: ${{ matrix.go-version }}
37-
check-latest: true
38-
cache: true
39-
- name: Display Go version
40-
run: go version
41-
- name: Install dependencies
42-
run: make setup
43-
- name: Test
44-
run: make ci
45-
- name: Archive code coverage results
46-
uses: actions/upload-artifact@v4
13+
- uses: actions/checkout@v2
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v2
4717
with:
48-
name: code-coverage-report-${{ matrix.os }}-${{ matrix.go-version }}
49-
path: coverage.txt
18+
go-version: 1.22
5019

51-
coverage:
52-
needs: tests
53-
runs-on: ubuntu-latest
20+
- name: Build
21+
run: make build
5422

55-
steps:
56-
- name: Download a linux coverage report
57-
uses: actions/download-artifact@v4
58-
with:
59-
name: code-coverage-report-ubuntu-latest-1.24
60-
- name: Upload coverage to Codecov
61-
uses: codecov/codecov-action@v4
62-
with:
63-
token: ${{ secrets.CODECOV_TOKEN }}
64-
fail_ci_if_error: true
65-
flags: unittest
23+
- name: Test
24+
run: make test
25+
26+
- name: Lint
27+
run: make lint

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,6 @@ Gopkg.lock
1919

2020
# cover
2121
coverage.txt
22+
23+
# added by lint-install
24+
out/

.golangci.yml

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
## Golden config for golangci-lint - strict, but within the realm of what Go authors might use.
2+
#
3+
# This is tied to the version of golangci-lint listed in the Makefile, usage with other
4+
# versions of golangci-lint will yield errors and/or false positives.
5+
#
6+
# Docs: https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml
7+
# Based heavily on https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322
8+
9+
version: "2"
10+
11+
issues:
12+
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
13+
max-issues-per-linter: 0
14+
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
15+
max-same-issues: 0
16+
17+
formatters:
18+
enable:
19+
# - gci
20+
# - gofmt
21+
- gofumpt
22+
# - goimports
23+
# - golines
24+
- swaggo
25+
26+
settings:
27+
golines:
28+
# Default: 100
29+
max-len: 120
30+
31+
linters:
32+
default: all
33+
disable:
34+
# linters that give advice contrary to what the Go authors advise
35+
- decorder # checks declaration order and count of types, constants, variables and functions
36+
- dupword # [useless without config] checks for duplicate words in the source code
37+
- exhaustruct # [highly recommend to enable] checks if all structure fields are initialized
38+
- forcetypeassert # [replaced by errcheck] finds forced type assertions
39+
- ginkgolinter # [if you use ginkgo/gomega] enforces standards of using ginkgo and gomega
40+
- gochecknoglobals # checks that no global variables exist
41+
- cyclop # replaced by revive
42+
- funlen # replaced by revive
43+
- godox # TODO's are OK
44+
- ireturn # It's OK
45+
- musttag
46+
- nonamedreturns
47+
- goconst # finds repeated strings that could be replaced by a constant
48+
- goheader # checks is file header matches to pattern
49+
- gomodguard # [use more powerful depguard] allow and block lists linter for direct Go module dependencies
50+
- err113 # bad advice about dynamic errors
51+
- lll # [replaced by golines] reports long lines
52+
- mnd # detects magic numbers, duplicated by revive
53+
- nlreturn # [too strict and mostly code is not more readable] checks for a new line before return and branch statements to increase code clarity
54+
- noinlineerr # disallows inline error handling `if err := ...; err != nil {`
55+
- prealloc # [premature optimization, but can be used in some cases] finds slice declarations that could potentially be preallocated
56+
- tagliatelle # needs configuration
57+
- testableexamples # checks if examples are testable (have an expected output)
58+
- testpackage # makes you use a separate _test package
59+
- paralleltest # not every test should be in parallel
60+
- wrapcheck # not required
61+
- wsl # [too strict and mostly code is not more readable] whitespace linter forces you to use empty lines
62+
- wsl_v5 # [too strict and mostly code is not more readable] add or remove empty lines
63+
- zerologlint # detects the wrong usage of zerolog that a user forgets to dispatch zerolog.Event
64+
65+
# All settings can be found here https://github.com/golangci/golangci-lint/blob/HEAD/.golangci.reference.yml
66+
settings:
67+
depguard:
68+
rules:
69+
"deprecated":
70+
files:
71+
- "$all"
72+
deny:
73+
- pkg: github.com/golang/protobuf
74+
desc: Use google.golang.org/protobuf instead, see https://developers.google.com/protocol-buffers/docs/reference/go/faq#modules
75+
- pkg: github.com/satori/go.uuid
76+
desc: Use github.com/google/uuid instead, satori's package is not maintained
77+
- pkg: github.com/gofrs/uuid$
78+
desc: Use github.com/gofrs/uuid/v5 or later, it was not a go module before v5
79+
"non-test files":
80+
files:
81+
- "!$test"
82+
deny:
83+
- pkg: math/rand$
84+
desc: Use math/rand/v2 instead, see https://go.dev/blog/randv2
85+
- pkg: "github.com/sirupsen/logrus"
86+
desc: not allowed
87+
- pkg: "github.com/pkg/errors"
88+
desc: Should be replaced by standard lib errors package
89+
90+
dupl:
91+
# token count (default: 150)
92+
threshold: 300
93+
94+
embeddedstructfieldcheck:
95+
# Checks that sync.Mutex and sync.RWMutex are not used as embedded fields.
96+
forbid-mutex: true
97+
98+
errcheck:
99+
# Report about not checking of errors in type assertions: `a := b.(MyStruct)`.
100+
check-type-assertions: true
101+
102+
exhaustive:
103+
# Program elements to check for exhaustiveness.
104+
# Default: [ switch ]
105+
check:
106+
- switch
107+
- map
108+
default-signifies-exhaustive: true
109+
110+
fatcontext:
111+
# Check for potential fat contexts in struct pointers.
112+
# May generate false positives.
113+
# Default: false
114+
check-struct-pointers: true
115+
116+
funcorder:
117+
# Checks if the exported methods of a structure are placed before the non-exported ones.
118+
struct-method: false
119+
120+
gocognit:
121+
min-complexity: 55
122+
123+
gocritic:
124+
enable-all: true
125+
disabled-checks:
126+
- paramTypeCombine
127+
# The list of supported checkers can be found at https://go-critic.com/overview.
128+
settings:
129+
captLocal:
130+
# Whether to restrict checker to params only.
131+
paramsOnly: false
132+
underef:
133+
# Whether to skip (*x).method() calls where x is a pointer receiver.
134+
skipRecvDeref: false
135+
hugeParam:
136+
# Default: 80
137+
sizeThreshold: 200
138+
139+
govet:
140+
enable-all: true
141+
142+
godot:
143+
scope: toplevel
144+
145+
inamedparam:
146+
# Skips check for interface methods with only a single parameter.
147+
skip-single-param: true
148+
149+
nakedret:
150+
# Default: 30
151+
max-func-lines: 4
152+
153+
nestif:
154+
min-complexity: 12
155+
156+
nolintlint:
157+
# Exclude following linters from requiring an explanation.
158+
# Default: []
159+
allow-no-explanation: [funlen, gocognit, golines]
160+
# Enable to require an explanation of nonzero length after each nolint directive.
161+
require-explanation: true
162+
# Enable to require nolint directives to mention the specific linter being suppressed.
163+
require-specific: true
164+
165+
revive:
166+
enable-all-rules: true
167+
rules:
168+
- name: add-constant
169+
severity: warning
170+
disabled: false
171+
exclude: [""]
172+
arguments:
173+
- max-lit-count: "5"
174+
allow-strs: '"","\n"'
175+
allow-ints: "0,1,2,3,256,1024"
176+
allow-floats: "0.0,0.,1.0,1.,2.0,2."
177+
- name: cognitive-complexity
178+
arguments: [50]
179+
- name: cyclomatic
180+
severity: warning
181+
arguments: [30]
182+
- name: function-length
183+
arguments: [150, 225]
184+
- name: line-length-limit
185+
arguments: [150]
186+
- name: nested-structs
187+
disabled: true
188+
189+
rowserrcheck:
190+
# database/sql is always checked.
191+
# Default: []
192+
packages:
193+
- github.com/jmoiron/sqlx
194+
195+
perfsprint:
196+
# optimize fmt.Sprintf("x: %s", y) into "x: " + y
197+
strconcat: false
198+
199+
staticcheck:
200+
checks:
201+
- all
202+
203+
usetesting:
204+
# Enable/disable `os.TempDir()` detections.
205+
# Default: false
206+
os-temp-dir: true
207+
208+
varnamelen:
209+
max-distance: 40
210+
min-name-length: 2
211+
212+
exclusions:
213+
# Default: []
214+
presets:
215+
- common-false-positives
216+
rules:
217+
# Allow "err" and "ok" vars to shadow existing declarations, otherwise we get too many false positives.
218+
- text: '^shadow: declaration of "(err|ok)" shadows declaration'
219+
linters:
220+
- govet
221+
- text: "parameter 'ctx' seems to be unused, consider removing or renaming it as _"
222+
linters:
223+
- revive
224+
- path: _test\.go
225+
linters:
226+
- dupl
227+
- gosec
228+
- noctx
229+
- perfsprint
230+
- revive
231+
- varnamelen

.yamllint

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
extends: default
3+
4+
rules:
5+
braces:
6+
max-spaces-inside: 1
7+
brackets:
8+
max-spaces-inside: 1
9+
comments: disable
10+
comments-indentation: disable
11+
document-start: disable
12+
line-length:
13+
level: warning
14+
max: 160
15+
allow-non-breakable-inline-mappings: true
16+
truthy: disable

0 commit comments

Comments
 (0)