Skip to content

Commit 242cbba

Browse files
authored
fix: nolint directives syntax (#101)
1 parent debcdd5 commit 242cbba

File tree

11 files changed

+52
-32
lines changed

11 files changed

+52
-32
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ jobs:
5757
steps:
5858
- uses: actions/checkout@v4
5959
- name: lint
60-
uses: golangci/golangci-lint-action@v5.3.0
60+
uses: golangci/golangci-lint-action@v6
6161
with:
6262
version: latest
63-
skip-build-cache: true
64-
skip-pkg-cache: true
65-
args: -D deadcode --skip-dirs "^(cmd|testdata)"
6663

.golangci.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
linters:
2+
enable:
3+
- nolintlint
4+
- gci
5+
- gofumpt
6+
- testifylint
7+
8+
linters-settings:
9+
nolintlint:
10+
allow-unused: false
11+
require-specific: true
12+
gci:
13+
sections:
14+
- standard
15+
- default
16+
- prefix(github.com/butuzov/ireturn)
17+
18+
output:
19+
show-stats: true
20+
sort-results: true
21+
sort-order:
22+
- linter
23+
- file

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ tests:
1414
-coverprofile=coverage.cov ./...
1515

1616
lints:
17-
golangci-lint run --no-config ./... -D deadcode
17+
golangci-lint run
1818

1919
cover:
2020
go tool cover -html=coverage.cov
2121

22+
generate:
23+
scripts/generate-std.sh
24+
2225
install:
2326
go install -trimpath -v -ldflags="-w -s" ./cmd/ireturn/
2427

analyzer/analyzer.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ import (
88
"strings"
99
"sync"
1010

11-
"github.com/butuzov/ireturn/analyzer/internal/config"
12-
"github.com/butuzov/ireturn/analyzer/internal/types"
13-
1411
"golang.org/x/tools/go/analysis"
1512
"golang.org/x/tools/go/analysis/passes/inspect"
1613
"golang.org/x/tools/go/ast/inspector"
14+
15+
"github.com/butuzov/ireturn/analyzer/internal/config"
16+
"github.com/butuzov/ireturn/analyzer/internal/types"
1717
)
1818

1919
const name string = "ireturn" // linter name
@@ -23,10 +23,10 @@ type validator interface {
2323
}
2424

2525
type analyzer struct {
26-
once sync.Once
27-
mu sync.RWMutex
28-
handler validator
29-
err error
26+
once sync.Once
27+
mu sync.RWMutex
28+
handler validator
29+
err error
3030
disabledNolint bool
3131

3232
found []analysis.Diagnostic
@@ -128,7 +128,7 @@ func (a *analyzer) readConfiguration(fs *flag.FlagSet) {
128128
}
129129

130130
func NewAnalyzer() *analysis.Analyzer {
131-
a := analyzer{} //nolint: exhaustivestruct
131+
a := analyzer{}
132132

133133
return &analysis.Analyzer{
134134
Name: name,
@@ -196,7 +196,7 @@ func filterInterfaces(p *analysis.Pass, ft *ast.FuncType, di map[string]struct{}
196196

197197
typeParams := val.String()
198198
prefix, suffix := "interface{", "}"
199-
if strings.HasPrefix(typeParams, prefix) { // nolint: gosimple
199+
if strings.HasPrefix(typeParams, prefix) { //nolint:gosimple
200200
typeParams = typeParams[len(prefix):]
201201
}
202202
if strings.HasSuffix(typeParams, suffix) {

analyzer/analyzer_test.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
1-
//nolint: wrapcheck
2-
//nolint: exhaustivestruct
3-
41
package analyzer
52

63
import (
74
"flag"
85
"fmt"
9-
"io/ioutil"
106
"os"
117
"path/filepath"
128
"strings"
139
"testing"
1410

15-
"github.com/butuzov/ireturn/analyzer/internal/types"
1611
"github.com/stretchr/testify/assert"
1712
"golang.org/x/tools/go/analysis/analysistest"
13+
14+
"github.com/butuzov/ireturn/analyzer/internal/types"
1815
)
1916

2017
const testPackageName = "example"
@@ -478,9 +475,9 @@ func (tc testCase) xerox(root string) error {
478475
func cp(src, dst string) error {
479476
if location, err := filepath.Abs(src); err != nil {
480477
return err
481-
} else if data, err := ioutil.ReadFile(location); err != nil {
478+
} else if data, err := os.ReadFile(location); err != nil {
482479
return err
483-
} else if err := ioutil.WriteFile(filepath.Join(dst, filepath.Base(src)), data, 0o600); err != nil {
480+
} else if err := os.WriteFile(filepath.Join(dst, filepath.Base(src)), data, 0o600); err != nil {
484481
return err
485482
}
486483

analyzer/internal/config/new.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ import (
1010

1111
var ErrCollisionOfInterests = errors.New("can't have both `-accept` and `-reject` specified at same time")
1212

13-
// nolint: exhaustivestruct
1413
func DefaultValidatorConfig() *allowConfig {
1514
return allowAll([]string{
1615
types.NameEmpty, // "empty": empty interfaces (interface{})

analyzer/internal/types/iface.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ func (i IFace) HashString() string {
4747
}
4848

4949
func (i IFace) ExportDiagnostic() analysis.Diagnostic {
50-
return analysis.Diagnostic{ //nolint: exhaustivestruct
50+
return analysis.Diagnostic{
5151
Pos: i.Pos,
5252
Message: i.String(),
5353
}

analyzer/std_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func Test_isStdLib(t *testing.T) {
1818
want, name := want, name
1919
t.Run(name, func(t *testing.T) {
2020
got := isStdPkgInterface(name)
21-
assert.Equal(t, got, want,
21+
assert.Equal(t, want, got,
2222
"pkg %s doesn't match expectations (got %v vs want %v)", name, got, want)
2323
})
2424
}

analyzer/testdata/disallow_directive_ok.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,35 @@ package example
33
/*
44
Actual disallow directive.
55
*/
6-
//nolint: ireturn
6+
//nolint:ireturn
77
func dissAllowDirective1() interface{} { return 1 }
88

99
/*
1010
Some other linter in disallow directive.
1111
*/
12-
//nolint: ireturn1
12+
//nolint:return1
1313
func dissAllowDirective2() interface{} { return 1 }
1414

1515
/*
1616
Coma separate linters in nolint directive. golangci-lint compatible mode
1717
*/
18-
//nolint: ireturn, nocode
18+
//nolint:ireturn,nocode
1919
func dissAllowDirective3() interface{} { return 1 }
2020

2121
/*
2222
Example of the good example if interlapsing name and actual ireturn with dot at the end.
2323
*/
24-
//nolint: ireturnlong, ireturn.
24+
//nolint:ireturnlong,ireturn.
2525
func dissAllowDirective4() interface{} { return 1 }
2626

2727
/*
2828
Example of the good example if interlapsing name and actual ireturn with dot at the end.
2929
*/
30-
//nolint: ireturnlong, ireturn
30+
//nolint:ireturnlong,ireturn
3131
func dissAllowDirective5() interface{} { return 1 }
3232

3333
/*
3434
Not works!
3535
*/
36-
//nolint: ireturnlong, itertut ireturn1.
36+
//nolint:ireturnlong,itertutireturn1.
3737
func dissAllowDirective6() interface{} { return 1 }

cmd/ireturn/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package main
22

33
import (
4-
"github.com/butuzov/ireturn/analyzer"
54
"golang.org/x/tools/go/analysis/singlechecker"
5+
6+
"github.com/butuzov/ireturn/analyzer"
67
)
78

89
func main() {

readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ You can use shorthand for some types of interfaces:
5555

5656
### Disable directive
5757

58-
`golangci-lint` compliant disable directive `//nolint: ireturn` can be used with `ireturn`
58+
`golangci-lint` compliant disable directive `//nolint:ireturn` can be used with `ireturn`
5959

6060
### GitHub Action
6161

0 commit comments

Comments
 (0)