feat: err113 analyzer name (#4567)

This commit is contained in:
Ludovic Fernandez 2024-03-28 21:04:49 +01:00 committed by GitHub
parent 07ffe48920
commit a7868b3e84
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 33 additions and 30 deletions

View File

@ -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

View File

@ -250,7 +250,7 @@
"gocyclo", "gocyclo",
"godot", "godot",
"godox", "godox",
"goerr113", "err113",
"gofmt", "gofmt",
"gofumpt", "gofumpt",
"goheader", "goheader",

View File

@ -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)
} }

View File

@ -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)).

File diff suppressed because one or more lines are too long

View File

@ -135,7 +135,7 @@
"Name": "godox" "Name": "godox"
}, },
{ {
"Name": "goerr113" "Name": "err113"
}, },
{ {
"Name": "gofmt", "Name": "gofmt",

21
test/testdata/err113.go vendored Normal file
View 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
}

View File

@ -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
}