File tree 8 files changed +57
-8
lines changed
8 files changed +57
-8
lines changed Original file line number Diff line number Diff line change @@ -506,6 +506,11 @@ linters-settings:
506
506
- map
507
507
- chan
508
508
509
+ nlreturn :
510
+ # size of the block (including return statement that is still "OK")
511
+ # so no return split required.
512
+ block-size : 1
513
+
509
514
nolintlint :
510
515
# Enable to ensure that nolint directives are all used. Default is true.
511
516
allow-unused : false
Original file line number Diff line number Diff line change @@ -74,7 +74,7 @@ require (
74
74
github.com/spf13/cobra v1.2.1
75
75
github.com/spf13/pflag v1.0.5
76
76
github.com/spf13/viper v1.8.1
77
- github.com/ssgreg/nlreturn/v2 v2.1.0
77
+ github.com/ssgreg/nlreturn/v2 v2.2.1
78
78
github.com/stretchr/testify v1.7.0
79
79
github.com/tdakkota/asciicheck v0.0.0-20200416200610-e657995f937b
80
80
github.com/tetafro/godot v1.4.10
Original file line number Diff line number Diff line change @@ -119,6 +119,7 @@ type LintersSettings struct {
119
119
Nakedret NakedretSettings
120
120
Nestif NestifSettings
121
121
NilNil NilNilSettings
122
+ Nlreturn NlreturnSettings
122
123
NoLintLint NoLintLintSettings
123
124
Prealloc PreallocSettings
124
125
Predeclared PredeclaredSettings
@@ -365,6 +366,10 @@ type NilNilSettings struct {
365
366
CheckedTypes []string `mapstructure:"checked-types"`
366
367
}
367
368
369
+ type NlreturnSettings struct {
370
+ BlockSize int `mapstructure:"block-size"`
371
+ }
372
+
368
373
type NoLintLintSettings struct {
369
374
RequireExplanation bool `mapstructure:"require-explanation"`
370
375
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 @@ -120,6 +120,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
120
120
var thelperCfg * config.ThelperSettings
121
121
var unusedCfg * config.StaticCheckSettings
122
122
var wrapcheckCfg * config.WrapcheckSettings
123
+ var nlreturnCfg * config.NlreturnSettings
123
124
124
125
if m .cfg != nil {
125
126
cyclopCfg = & m .cfg .LintersSettings .Cyclop
@@ -143,6 +144,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
143
144
thelperCfg = & m .cfg .LintersSettings .Thelper
144
145
unusedCfg = & m .cfg .LintersSettings .Unused
145
146
wrapcheckCfg = & m .cfg .LintersSettings .Wrapcheck
147
+ nlreturnCfg = & m .cfg .LintersSettings .Nlreturn
146
148
}
147
149
148
150
const megacheckName = "megacheck"
@@ -414,7 +416,7 @@ func (m Manager) GetAllSupportedLinterConfigs() []*linter.Config {
414
416
WithPresets (linter .PresetBugs , linter .PresetSQL ).
415
417
WithLoadForGoAnalysis ().
416
418
WithURL ("https://github.com/ryanrolds/sqlclosecheck" ),
417
- linter .NewConfig (golinters .NewNLReturn ()).
419
+ linter .NewConfig (golinters .NewNLReturn (nlreturnCfg )).
418
420
WithSince ("v1.30.0" ).
419
421
WithPresets (linter .PresetStyle ).
420
422
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