File tree Expand file tree Collapse file tree 5 files changed +71
-0
lines changed
Expand file tree Collapse file tree 5 files changed +71
-0
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,7 @@ require (
99 github.com/Antonboom/nilnil v0.1.1
1010 github.com/BurntSushi/toml v1.2.0
1111 github.com/Djarvur/go-err113 v0.0.0-20210108212216-aea10b59be24
12+ github.com/GaijinEntertainment/go-defer v1.2.0
1213 github.com/GaijinEntertainment/go-exhaustruct/v2 v2.3.0
1314 github.com/OpenPeeDeeP/depguard v1.1.1
1415 github.com/alexkohler/prealloc v1.0.0
Original file line number Diff line number Diff line change 1+ package golinters
2+
3+ import (
4+ "github.com/GaijinEntertainment/go-defer/pkg/analyzer"
5+ "golang.org/x/tools/go/analysis"
6+
7+ "github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8+ )
9+
10+ func NewDefer () * goanalysis.Linter {
11+ a , err := analyzer .NewAnalyzer ()
12+ if err != nil {
13+ linterLogger .Fatalf ("defer configuration: %v" , err )
14+ }
15+
16+ return goanalysis .NewLinter (
17+ a .Name ,
18+ a .Doc ,
19+ []* analysis.Analyzer {a },
20+ nil ,
21+ ).WithLoadMode (goanalysis .LoadModeTypesInfo )
22+ }
Original file line number Diff line number Diff line change @@ -404,6 +404,12 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
404404 WithLoadForGoAnalysis ().
405405 WithURL ("https://github.com/GaijinEntertainment/go-exhaustruct" ),
406406
407+ linter .NewConfig (golinters .NewDefer ()).
408+ WithSince ("v1.51.0" ).
409+ WithPresets (linter .PresetStyle ).
410+ WithLoadForGoAnalysis ().
411+ WithURL ("https://github.com/GaijinEntertainment/go-defer" ),
412+
407413 linter .NewConfig (golinters .NewExportLoopRef ()).
408414 WithSince ("v1.28.0" ).
409415 WithPresets (linter .PresetBugs ).
Original file line number Diff line number Diff line change 1+ //golangcitest:args -Edefer
2+ package testdata
3+
4+ func funcReturnsInt () int {
5+ return 1
6+ }
7+
8+ func funcReturnsFunc () func () {
9+ return func () {
10+ }
11+ }
12+
13+ func funcReturnsErrAndFunc () (error , func ()) {
14+ return nil , func () {
15+ }
16+ }
17+
18+ func funcDeferReturnGoodValue () {
19+ defer funcReturnsInt ()
20+ }
21+
22+ func funcDeferReturnFunc () {
23+ defer funcReturnsFunc () // want "deferred call should not return a function"
24+ }
25+
26+ func funcDeferReturnErrAndFunc () {
27+ defer funcReturnsErrAndFunc () // want "deferred call should not return a function"
28+ }
29+
30+ func funcDeferAnonymousReturnFunc () {
31+ defer func () func () { // want "deferred call should not return a function"
32+ return func () {}
33+ }()
34+ }
35+
36+ func funcDeferAnonymousReturnErrAndFunc () {
37+ defer func () (error , func ()) { // want "deferred call should not return a function"
38+ return nil , func () {}
39+ }()
40+ }
You can’t perform that action at this time.
0 commit comments