Skip to content

Commit

Permalink
chore: improve linter configuration (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored Jun 29, 2024
1 parent 11de3da commit e5593aa
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 72 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/linting.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- if: ${{ matrix.os == 'windows-latest' }} # https://github.com/actions/checkout/issues/135
run: |
git config --global core.eol lf
git config --global core.autocrlf input
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
Expand Down
83 changes: 82 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,42 @@ run:

linters:
enable:
- misspell
- asasalint
- bidichk
- dogsled
- dupword
- durationcheck
- err113
- errname
- errorlint
- fatcontext
- forbidigo
- gocheckcompilerdirectives
- gochecknoinits
- gocritic
- godot
- godox
- gofumpt
- goheader
- goimports
- gomoddirectives
- goprintffuncname
- gosec
- inamedparam
- interfacebloat
- ireturn
- mirror
- misspell
- nolintlint
- revive
- stylecheck
- tenv
- testifylint
- thelper
- unconvert
- unparam
- usestdlibvars
- whitespace

linters-settings:
misspell:
Expand All @@ -19,6 +52,54 @@ linters-settings:
Copyright 2018-{{ YEAR }} The Gofrs. All rights reserved.
Use of this source code is governed by the BSD 3-Clause
license that can be found in the LICENSE file.
gofumpt:
extra-rules: true
gocritic:
enabled-tags:
- diagnostic
- style
- performance
disabled-checks:
- paramTypeCombine # already handle by gofumpt.extra-rules
- whyNoLint # already handle by nonolint
- unnamedResult
- hugeParam
- sloppyReassign
- rangeValCopy
- octalLiteral
- ptrToRefParam
- appendAssign
- ruleguard
- httpNoBody
- exposedSyncMutex

revive:
rules:
- name: struct-tag
- name: blank-imports
- name: context-as-argument
- name: context-keys-type
- name: dot-imports
- name: error-return
- name: error-strings
- name: error-naming
- name: exported
- name: if-return
- name: increment-decrement
- name: var-naming
- name: var-declaration
- name: package-comments
- name: range
- name: receiver-naming
- name: time-naming
- name: unexported-return
- name: indent-error-flow
- name: errorf
- name: empty-block
- name: superfluous-else
- name: unused-parameter
- name: unreachable-code
- name: redefines-builtin-id

issues:
exclude-use-default: true
Expand Down
3 changes: 2 additions & 1 deletion flock.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ func (f *Flock) setFh() error {
} else {
flags |= os.O_RDONLY
}
fh, err := os.OpenFile(f.path, flags, os.FileMode(0600))

fh, err := os.OpenFile(f.path, flags, os.FileMode(0o600))
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion flock_aix.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ func (f *Flock) doLock(cmd cmdType, lt lockType, blocking bool) (bool, error) {
}

err = setlkw(f.fh.Fd(), cmd, lt)

if err != nil {
f.doUnlock()
if cmd == tryLock && err == unix.EACCES {
Expand Down
6 changes: 6 additions & 0 deletions flock_example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@ func ExampleFlock_Locked() {
_, err := f.TryLock()
if err != nil {
// handle locking error
panic(err)
}

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

err = f.Unlock()
if err != nil {
// handle locking error
panic(err)
}

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

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

if err := fileLock.Unlock(); err != nil {
// handle unlock error
panic(err)
}
}

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

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

if err := fileLock.Unlock(); err != nil {
// handle unlock error
panic(err)
}
}

Expand Down
Loading

0 comments on commit e5593aa

Please sign in to comment.