Skip to content

Commit

Permalink
feat: err113 analyzer name (#4567)
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez committed Mar 28, 2024
1 parent 07ffe48 commit a7868b3
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 30 deletions.
4 changes: 2 additions & 2 deletions .golangci.next.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2525,6 +2525,7 @@ linters:
- dupl
- dupword
- durationcheck
- err113
- errcheck
- errchkjson
- errname
Expand All @@ -2548,7 +2549,6 @@ linters:
- gocyclo
- godot
- godox
- goerr113
- gofmt
- gofumpt
- goheader
Expand Down Expand Up @@ -2638,6 +2638,7 @@ linters:
- dupl
- dupword
- durationcheck
- err113
- errcheck
- errchkjson
- errname
Expand All @@ -2661,7 +2662,6 @@ linters:
- gocyclo
- godot
- godox
- goerr113
- gofmt
- gofumpt
- goheader
Expand Down
2 changes: 1 addition & 1 deletion jsonschema/golangci.next.jsonschema.json
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@
"gocyclo",
"godot",
"godox",
"goerr113",
"err113",
"gofmt",
"gofumpt",
"goheader",
Expand Down
8 changes: 5 additions & 3 deletions pkg/golinters/goerr113.go → pkg/golinters/err113.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ import (
"github.com/golangci/golangci-lint/pkg/goanalysis"
)

func NewGoerr113() *goanalysis.Linter {
func NewErr113() *goanalysis.Linter {
a := err113.NewAnalyzer()

return goanalysis.NewLinter(
"goerr113",
a.Name,
"Go linter to check the errors handling expressions",
[]*analysis.Analyzer{err113.NewAnalyzer()},
[]*analysis.Analyzer{a},
nil,
).WithLoadMode(goanalysis.LoadModeTypesInfo)
}
3 changes: 2 additions & 1 deletion pkg/lint/lintersdb/builder_linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,10 +252,11 @@ func (b LinterBuilder) Build(cfg *config.Config) ([]*linter.Config, error) {
WithPresets(linter.PresetStyle, linter.PresetComment).
WithURL("https://github.com/matoous/godox"),

linter.NewConfig(golinters.NewGoerr113()).
linter.NewConfig(golinters.NewErr113()).
WithSince("v1.26.0").
WithPresets(linter.PresetStyle, linter.PresetError).
WithLoadForGoAnalysis().
WithAlternativeNames("goerr113").
WithURL("https://github.com/Djarvur/go-err113"),

linter.NewConfig(golinters.NewGofmt(&cfg.LintersSettings.Gofmt)).
Expand Down
2 changes: 1 addition & 1 deletion pkg/printers/testdata/golden-json.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion pkg/printers/testdata/in-report-data.json
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@
"Name": "godox"
},
{
"Name": "goerr113"
"Name": "err113"
},
{
"Name": "gofmt",
Expand Down
21 changes: 21 additions & 0 deletions test/testdata/err113.go
Original file line number Diff line number Diff line change
@@ -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 changes: 0 additions & 21 deletions test/testdata/goerr113.go

This file was deleted.

0 comments on commit a7868b3

Please sign in to comment.