feat: err113 analyzer name (#4567)
This commit is contained in:
parent
07ffe48920
commit
a7868b3e84
@ -2525,6 +2525,7 @@ linters:
|
|||||||
- dupl
|
- dupl
|
||||||
- dupword
|
- dupword
|
||||||
- durationcheck
|
- durationcheck
|
||||||
|
- err113
|
||||||
- errcheck
|
- errcheck
|
||||||
- errchkjson
|
- errchkjson
|
||||||
- errname
|
- errname
|
||||||
@ -2548,7 +2549,6 @@ linters:
|
|||||||
- gocyclo
|
- gocyclo
|
||||||
- godot
|
- godot
|
||||||
- godox
|
- godox
|
||||||
- goerr113
|
|
||||||
- gofmt
|
- gofmt
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- goheader
|
- goheader
|
||||||
@ -2638,6 +2638,7 @@ linters:
|
|||||||
- dupl
|
- dupl
|
||||||
- dupword
|
- dupword
|
||||||
- durationcheck
|
- durationcheck
|
||||||
|
- err113
|
||||||
- errcheck
|
- errcheck
|
||||||
- errchkjson
|
- errchkjson
|
||||||
- errname
|
- errname
|
||||||
@ -2661,7 +2662,6 @@ linters:
|
|||||||
- gocyclo
|
- gocyclo
|
||||||
- godot
|
- godot
|
||||||
- godox
|
- godox
|
||||||
- goerr113
|
|
||||||
- gofmt
|
- gofmt
|
||||||
- gofumpt
|
- gofumpt
|
||||||
- goheader
|
- goheader
|
||||||
|
@ -250,7 +250,7 @@
|
|||||||
"gocyclo",
|
"gocyclo",
|
||||||
"godot",
|
"godot",
|
||||||
"godox",
|
"godox",
|
||||||
"goerr113",
|
"err113",
|
||||||
"gofmt",
|
"gofmt",
|
||||||
"gofumpt",
|
"gofumpt",
|
||||||
"goheader",
|
"goheader",
|
||||||
|
@ -7,11 +7,13 @@ import (
|
|||||||
"github.com/golangci/golangci-lint/pkg/goanalysis"
|
"github.com/golangci/golangci-lint/pkg/goanalysis"
|
||||||
)
|
)
|
||||||
|
|
||||||
func NewGoerr113() *goanalysis.Linter {
|
func NewErr113() *goanalysis.Linter {
|
||||||
|
a := err113.NewAnalyzer()
|
||||||
|
|
||||||
return goanalysis.NewLinter(
|
return goanalysis.NewLinter(
|
||||||
"goerr113",
|
a.Name,
|
||||||
"Go linter to check the errors handling expressions",
|
"Go linter to check the errors handling expressions",
|
||||||
[]*analysis.Analyzer{err113.NewAnalyzer()},
|
[]*analysis.Analyzer{a},
|
||||||
nil,
|
nil,
|
||||||
).WithLoadMode(goanalysis.LoadModeTypesInfo)
|
).WithLoadMode(goanalysis.LoadModeTypesInfo)
|
||||||
}
|
}
|
@ -252,10 +252,11 @@ func (b LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
|
|||||||
WithPresets(linter.PresetStyle, linter.PresetComment).
|
WithPresets(linter.PresetStyle, linter.PresetComment).
|
||||||
WithURL("https://github.com/matoous/godox"),
|
WithURL("https://github.com/matoous/godox"),
|
||||||
|
|
||||||
linter.NewConfig(golinters.NewGoerr113()).
|
linter.NewConfig(golinters.NewErr113()).
|
||||||
WithSince("v1.26.0").
|
WithSince("v1.26.0").
|
||||||
WithPresets(linter.PresetStyle, linter.PresetError).
|
WithPresets(linter.PresetStyle, linter.PresetError).
|
||||||
WithLoadForGoAnalysis().
|
WithLoadForGoAnalysis().
|
||||||
|
WithAlternativeNames("goerr113").
|
||||||
WithURL("https://github.com/Djarvur/go-err113"),
|
WithURL("https://github.com/Djarvur/go-err113"),
|
||||||
|
|
||||||
linter.NewConfig(golinters.NewGofmt(&cfg.LintersSettings.Gofmt)).
|
linter.NewConfig(golinters.NewGofmt(&cfg.LintersSettings.Gofmt)).
|
||||||
|
2
pkg/printers/testdata/golden-json.json
vendored
2
pkg/printers/testdata/golden-json.json
vendored
File diff suppressed because one or more lines are too long
2
pkg/printers/testdata/in-report-data.json
vendored
2
pkg/printers/testdata/in-report-data.json
vendored
@ -135,7 +135,7 @@
|
|||||||
"Name": "godox"
|
"Name": "godox"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name": "goerr113"
|
"Name": "err113"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"Name": "gofmt",
|
"Name": "gofmt",
|
||||||
|
21
test/testdata/err113.go
vendored
Normal file
21
test/testdata/err113.go
vendored
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
//golangcitest:args -Eerr113
|
||||||
|
package testdata
|
||||||
|
|
||||||
|
import "os"
|
||||||
|
|
||||||
|
func SimpleEqual(e1, e2 error) bool {
|
||||||
|
return e1 == e2 // want `do not compare errors directly "e1 == e2", use "errors.Is\(e1, e2\)" instead`
|
||||||
|
}
|
||||||
|
|
||||||
|
func SimpleNotEqual(e1, e2 error) bool {
|
||||||
|
return e1 != e2 // want `do not compare errors directly "e1 != e2", use "!errors.Is\(e1, e2\)" instead`
|
||||||
|
}
|
||||||
|
|
||||||
|
func CheckGoerr13Import(e error) bool {
|
||||||
|
f, err := os.Create("f.txt")
|
||||||
|
if err != nil {
|
||||||
|
return err == e // want `do not compare errors directly "err == e", use "errors.Is\(err, e\)" instead`
|
||||||
|
}
|
||||||
|
f.Close()
|
||||||
|
return false
|
||||||
|
}
|
21
test/testdata/goerr113.go
vendored
21
test/testdata/goerr113.go
vendored
@ -1,21 +0,0 @@
|
|||||||
//golangcitest:args -Egoerr113
|
|
||||||
package testdata
|
|
||||||
|
|
||||||
import "os"
|
|
||||||
|
|
||||||
func SimpleEqual(e1, e2 error) bool {
|
|
||||||
return e1 == e2 // want `err113: do not compare errors directly "e1 == e2", use "errors.Is\(e1, e2\)" instead`
|
|
||||||
}
|
|
||||||
|
|
||||||
func SimpleNotEqual(e1, e2 error) bool {
|
|
||||||
return e1 != e2 // want `err113: do not compare errors directly "e1 != e2", use "!errors.Is\(e1, e2\)" instead`
|
|
||||||
}
|
|
||||||
|
|
||||||
func CheckGoerr13Import(e error) bool {
|
|
||||||
f, err := os.Create("f.txt")
|
|
||||||
if err != nil {
|
|
||||||
return err == e // want `err113: do not compare errors directly "err == e", use "errors.Is\(err, e\)" instead`
|
|
||||||
}
|
|
||||||
f.Close()
|
|
||||||
return false
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user