Skip to content

Commit e5593aa

Browse files
authored
chore: improve linter configuration (#75)
1 parent 11de3da commit e5593aa

9 files changed

+174
-72
lines changed

.github/workflows/linting.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ jobs:
2525
runs-on: ${{ matrix.os }}
2626

2727
steps:
28+
- if: ${{ matrix.os == 'windows-latest' }} # https://github.com/actions/checkout/issues/135
29+
run: |
30+
git config --global core.eol lf
31+
git config --global core.autocrlf input
2832
- uses: actions/checkout@v4
2933
- uses: actions/setup-go@v5
3034
with:

.golangci.yml

Lines changed: 82 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,42 @@ run:
33

44
linters:
55
enable:
6-
- misspell
6+
- asasalint
7+
- bidichk
8+
- dogsled
9+
- dupword
10+
- durationcheck
11+
- err113
12+
- errname
13+
- errorlint
14+
- fatcontext
15+
- forbidigo
16+
- gocheckcompilerdirectives
17+
- gochecknoinits
18+
- gocritic
719
- godot
20+
- godox
21+
- gofumpt
822
- goheader
23+
- goimports
24+
- gomoddirectives
25+
- goprintffuncname
26+
- gosec
27+
- inamedparam
28+
- interfacebloat
29+
- ireturn
30+
- mirror
31+
- misspell
32+
- nolintlint
33+
- revive
34+
- stylecheck
35+
- tenv
36+
- testifylint
37+
- thelper
38+
- unconvert
39+
- unparam
40+
- usestdlibvars
41+
- whitespace
942

1043
linters-settings:
1144
misspell:
@@ -19,6 +52,54 @@ linters-settings:
1952
Copyright 2018-{{ YEAR }} The Gofrs. All rights reserved.
2053
Use of this source code is governed by the BSD 3-Clause
2154
license that can be found in the LICENSE file.
55+
gofumpt:
56+
extra-rules: true
57+
gocritic:
58+
enabled-tags:
59+
- diagnostic
60+
- style
61+
- performance
62+
disabled-checks:
63+
- paramTypeCombine # already handle by gofumpt.extra-rules
64+
- whyNoLint # already handle by nonolint
65+
- unnamedResult
66+
- hugeParam
67+
- sloppyReassign
68+
- rangeValCopy
69+
- octalLiteral
70+
- ptrToRefParam
71+
- appendAssign
72+
- ruleguard
73+
- httpNoBody
74+
- exposedSyncMutex
75+
76+
revive:
77+
rules:
78+
- name: struct-tag
79+
- name: blank-imports
80+
- name: context-as-argument
81+
- name: context-keys-type
82+
- name: dot-imports
83+
- name: error-return
84+
- name: error-strings
85+
- name: error-naming
86+
- name: exported
87+
- name: if-return
88+
- name: increment-decrement
89+
- name: var-naming
90+
- name: var-declaration
91+
- name: package-comments
92+
- name: range
93+
- name: receiver-naming
94+
- name: time-naming
95+
- name: unexported-return
96+
- name: indent-error-flow
97+
- name: errorf
98+
- name: empty-block
99+
- name: superfluous-else
100+
- name: unused-parameter
101+
- name: unreachable-code
102+
- name: redefines-builtin-id
22103

23104
issues:
24105
exclude-use-default: true

flock.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ func (f *Flock) setFh() error {
126126
} else {
127127
flags |= os.O_RDONLY
128128
}
129-
fh, err := os.OpenFile(f.path, flags, os.FileMode(0600))
129+
130+
fh, err := os.OpenFile(f.path, flags, os.FileMode(0o600))
130131
if err != nil {
131132
return err
132133
}

flock_aix.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ func (f *Flock) doLock(cmd cmdType, lt lockType, blocking bool) (bool, error) {
153153
}
154154

155155
err = setlkw(f.fh.Fd(), cmd, lt)
156-
157156
if err != nil {
158157
f.doUnlock()
159158
if cmd == tryLock && err == unix.EACCES {

flock_example_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,15 @@ func ExampleFlock_Locked() {
2020
_, err := f.TryLock()
2121
if err != nil {
2222
// handle locking error
23+
panic(err)
2324
}
2425

2526
fmt.Printf("locked: %v\n", f.Locked())
2627

2728
err = f.Unlock()
2829
if err != nil {
2930
// handle locking error
31+
panic(err)
3032
}
3133

3234
fmt.Printf("locked: %v\n", f.Locked())
@@ -41,13 +43,15 @@ func ExampleFlock_TryLock() {
4143
locked, err := fileLock.TryLock()
4244
if err != nil {
4345
// handle locking error
46+
panic(err)
4447
}
4548

4649
if locked {
4750
fmt.Printf("path: %s; locked: %v\n", fileLock.Path(), fileLock.Locked())
4851

4952
if err := fileLock.Unlock(); err != nil {
5053
// handle unlock error
54+
panic(err)
5155
}
5256
}
5357

@@ -64,13 +68,15 @@ func ExampleFlock_TryLockContext() {
6468
locked, err := fileLock.TryLockContext(lockCtx, 678*time.Millisecond)
6569
if err != nil {
6670
// handle locking error
71+
panic(err)
6772
}
6873

6974
if locked {
7075
fmt.Printf("path: %s; locked: %v\n", fileLock.Path(), fileLock.Locked())
7176

7277
if err := fileLock.Unlock(); err != nil {
7378
// handle unlock error
79+
panic(err)
7480
}
7581
}
7682

0 commit comments

Comments
 (0)