File tree 6 files changed +52
-7
lines changed 6 files changed +52
-7
lines changed Original file line number Diff line number Diff line change @@ -158,6 +158,11 @@ linters-settings:
158
158
# Exclude godoc examples from forbidigo checks. Default is true.
159
159
exclude_godoc_examples : false
160
160
161
+ nlreturn :
162
+ # size of the block (including return statement that are still "OK")
163
+ # so no return split required.
164
+ block-size : 1
165
+
161
166
funlen :
162
167
lines : 60
163
168
statements : 40
Original file line number Diff line number Diff line change @@ -118,6 +118,7 @@ type LintersSettings struct {
118
118
Misspell MisspellSettings
119
119
Nakedret NakedretSettings
120
120
Nestif NestifSettings
121
+ Nlreturn NlreturnSettings
121
122
NoLintLint NoLintLintSettings
122
123
Prealloc PreallocSettings
123
124
Predeclared PredeclaredSettings
@@ -360,6 +361,10 @@ type NestifSettings struct {
360
361
MinComplexity int `mapstructure:"min-complexity"`
361
362
}
362
363
364
+ type NlreturnSettings struct {
365
+ BlockSize int `mapstructure:"block-size"`
366
+ }
367
+
363
368
type NoLintLintSettings struct {
364
369
RequireExplanation bool `mapstructure:"require-explanation"`
365
370
AllowLeadingSpace bool `mapstructure:"allow-leading-space"`
Original file line number Diff line number Diff line change @@ -4,16 +4,24 @@ import (
4
4
"github.com/ssgreg/nlreturn/v2/pkg/nlreturn"
5
5
"golang.org/x/tools/go/analysis"
6
6
7
+ "github.com/golangci/golangci-lint/pkg/config"
7
8
"github.com/golangci/golangci-lint/pkg/golinters/goanalysis"
8
9
)
9
10
10
- func NewNLReturn () * goanalysis.Linter {
11
+ func NewNLReturn (settings * config.NlreturnSettings ) * goanalysis.Linter {
12
+ a := nlreturn .NewAnalyzer ()
13
+
14
+ cfg := map [string ]map [string ]interface {}{}
15
+ if settings != nil {
16
+ cfg [a .Name ] = map [string ]interface {}{
17
+ "block-size" : settings .BlockSize ,
18
+ }
19
+ }
20
+
11
21
return goanalysis .NewLinter (
12
- "nlreturn" ,
22
+ a . Name ,
13
23
"nlreturn checks for a new line before return and branch statements to increase code clarity" ,
14
- []* analysis.Analyzer {
15
- nlreturn .NewAnalyzer (),
16
- },
17
- nil ,
24
+ []* analysis.Analyzer {a },
25
+ cfg ,
18
26
).WithLoadMode (goanalysis .LoadModeSyntax )
19
27
}
Original file line number Diff line number Diff line change @@ -119,6 +119,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
119
119
var stylecheckCfg * config.StaticCheckSettings
120
120
var unusedCfg * config.StaticCheckSettings
121
121
var wrapcheckCfg * config.WrapcheckSettings
122
+ var nlreturnCfg * config.NlreturnSettings
122
123
123
124
if m .cfg != nil {
124
125
govetCfg = & m .cfg .LintersSettings .Govet
@@ -141,6 +142,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
141
142
stylecheckCfg = & m .cfg .LintersSettings .Stylecheck
142
143
unusedCfg = & m .cfg .LintersSettings .Unused
143
144
wrapcheckCfg = & m .cfg .LintersSettings .Wrapcheck
145
+ nlreturnCfg = & m .cfg .LintersSettings .Nlreturn
144
146
}
145
147
146
148
const megacheckName = "megacheck"
@@ -412,7 +414,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
412
414
WithPresets (linter .PresetBugs , linter .PresetSQL ).
413
415
WithLoadForGoAnalysis ().
414
416
WithURL ("https://github.com/ryanrolds/sqlclosecheck" ),
415
- linter .NewConfig (golinters .NewNLReturn ()).
417
+ linter .NewConfig (golinters .NewNLReturn (nlreturnCfg )).
416
418
WithSince ("v1.30.0" ).
417
419
WithPresets (linter .PresetStyle ).
418
420
WithURL ("https://github.com/ssgreg/nlreturn" ),
Original file line number Diff line number Diff line change
1
+ linters-settings :
2
+ nlreturn :
3
+ block-size : 2
Original file line number Diff line number Diff line change
1
+ // args: -Enlreturn
2
+ // config_path: testdata/configs/nlreturn.yml
3
+ package testdata
4
+
5
+ func foo0 (n int ) int {
6
+ if n == 1 {
7
+ n2 := n * n
8
+ return n2
9
+ }
10
+
11
+ return 1
12
+ }
13
+
14
+ func foo1 (n int ) int {
15
+ if n == 1 {
16
+ n2 := n * n
17
+ n3 := n2 * n
18
+ return n3 // ERROR "return with no blank line before"
19
+ }
20
+
21
+ return 1
22
+ }
You can’t perform that action at this time.
0 commit comments