Skip to content

Commit 1c61ed7

Browse files
committed
add noinlineerr linter
1 parent 8eab120 commit 1c61ed7

File tree

8 files changed

+93
-0
lines changed

8 files changed

+93
-0
lines changed

.golangci.next.reference.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ linters:
9191
- nilnil
9292
- nlreturn
9393
- noctx
94+
- noinlineerr
9495
- nolintlint
9596
- nonamedreturns
9697
- nosprintfhostport
@@ -200,6 +201,7 @@ linters:
200201
- nilnil
201202
- nlreturn
202203
- noctx
204+
- noinlineerr
203205
- nolintlint
204206
- nonamedreturns
205207
- nosprintfhostport

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
4d63.com/gochecknoglobals v0.2.2
88
github.com/4meepo/tagalign v1.4.2
99
github.com/Abirdcfly/dupword v0.1.4
10+
github.com/AlwxSin/noinlineerr v1.0.1
1011
github.com/Antonboom/errname v1.1.0
1112
github.com/Antonboom/nilnil v1.1.0
1213
github.com/Antonboom/testifylint v1.6.1

go.sum

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

jsonschema/golangci.next.jsonschema.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -791,6 +791,7 @@
791791
"nilnil",
792792
"nlreturn",
793793
"noctx",
794+
"noinlineerr",
794795
"nolintlint",
795796
"nonamedreturns",
796797
"nosprintfhostport",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package noinlineerr
2+
3+
import (
4+
"github.com/AlwxSin/noinlineerr"
5+
"golang.org/x/tools/go/analysis"
6+
7+
"github.com/golangci/golangci-lint/v2/pkg/goanalysis"
8+
)
9+
10+
func New() *goanalysis.Linter {
11+
analyzer := noinlineerr.NewAnalyzer()
12+
return goanalysis.NewLinter(
13+
analyzer.Name,
14+
analyzer.Doc,
15+
[]*analysis.Analyzer{analyzer},
16+
nil,
17+
).WithLoadMode(goanalysis.LoadModeTypesInfo)
18+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package noinlineerr
2+
3+
import (
4+
"testing"
5+
6+
"github.com/golangci/golangci-lint/v2/test/testshared/integration"
7+
)
8+
9+
func TestFromTestdata(t *testing.T) {
10+
integration.RunTestdata(t)
11+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//golangcitest:args -Enoinlineerr
2+
package testdata
3+
4+
func doSomething() error {
5+
return nil
6+
}
7+
8+
func doSmthManyArgs(a, b, c, d int) error {
9+
return nil
10+
}
11+
12+
func doSmthMultipleReturn() (bool, error) {
13+
return false, nil
14+
}
15+
16+
func valid() error {
17+
err := doSomething() // ok
18+
if err != nil {
19+
return err
20+
}
21+
22+
err = doSmthManyArgs(0, 0, 0, 0) // ok
23+
if err != nil {
24+
return err
25+
}
26+
27+
_, err = doSmthMultipleReturn() // ok
28+
if err != nil {
29+
return err
30+
}
31+
return nil
32+
}
33+
34+
func invalid() error {
35+
if err := doSomething(); err != nil { // want "avoid inline error handling using `if err := ...; err != nil; use plain assignment `err := ..."
36+
return err
37+
}
38+
39+
if err := doSmthManyArgs(0, // want "avoid inline error handling using `if err := ...; err != nil; use plain assignment `err := ..."
40+
0,
41+
0,
42+
0,
43+
); err != nil {
44+
return err
45+
}
46+
47+
if _, err := doSmthMultipleReturn(); err != nil { // want "avoid inline error handling using `if err := ...; err != nil; use plain assignment `err := ..."
48+
_ = false
49+
return err
50+
}
51+
return nil
52+
}

pkg/lint/lintersdb/builder_linter.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import (
7979
"github.com/golangci/golangci-lint/v2/pkg/golinters/nilnil"
8080
"github.com/golangci/golangci-lint/v2/pkg/golinters/nlreturn"
8181
"github.com/golangci/golangci-lint/v2/pkg/golinters/noctx"
82+
"github.com/golangci/golangci-lint/v2/pkg/golinters/noinlineerr"
8283
"github.com/golangci/golangci-lint/v2/pkg/golinters/nolintlint"
8384
"github.com/golangci/golangci-lint/v2/pkg/golinters/nonamedreturns"
8485
"github.com/golangci/golangci-lint/v2/pkg/golinters/nosprintfhostport"
@@ -511,6 +512,11 @@ func (LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
511512
WithLoadForGoAnalysis().
512513
WithURL("https://github.com/sonatard/noctx"),
513514

515+
linter.NewConfig(noinlineerr.New()).
516+
WithSince("v2.2.80").
517+
WithLoadForGoAnalysis().
518+
WithURL("https://github.com/AlwxSin/noinlineerr"),
519+
514520
linter.NewConfig(nonamedreturns.New(&cfg.Linters.Settings.NoNamedReturns)).
515521
WithSince("v1.46.0").
516522
WithLoadForGoAnalysis().

0 commit comments

Comments
 (0)