@@ -12,12 +12,13 @@ import (
12
12
"github.com/mgechev/revive/lint"
13
13
)
14
14
15
- const defaultFileLengthLimitMax = 1000
16
-
17
15
// FileLengthLimitRule lints the number of lines in a file.
18
16
type FileLengthLimitRule struct {
19
- max int
20
- skipComments bool
17
+ // max is the maximum number of lines allowed in a file. 0 means the rule is disabled.
18
+ max int
19
+ // skipComments indicates whether to skip comment lines when counting lines.
20
+ skipComments bool
21
+ // skipBlankLines indicates whether to skip blank lines when counting lines.
21
22
skipBlankLines bool
22
23
sync.Mutex
23
24
}
@@ -26,6 +27,11 @@ type FileLengthLimitRule struct {
26
27
func (r * FileLengthLimitRule ) Apply (file * lint.File , arguments lint.Arguments ) []lint.Failure {
27
28
r .configure (arguments )
28
29
30
+ if r .max <= 0 {
31
+ // when max is negative or 0 the rule is disabled
32
+ return nil
33
+ }
34
+
29
35
all := 0
30
36
blank := 0
31
37
scanner := bufio .NewScanner (bytes .NewReader (file .Content ()))
@@ -72,9 +78,12 @@ func (r *FileLengthLimitRule) configure(arguments lint.Arguments) {
72
78
r .Lock ()
73
79
defer r .Unlock ()
74
80
75
- if len (arguments ) == 0 {
76
- r .max = defaultFileLengthLimitMax
77
- return
81
+ if r .max != 0 {
82
+ return // already configured
83
+ }
84
+
85
+ if len (arguments ) < 1 {
86
+ return // use default
78
87
}
79
88
80
89
argKV , ok := arguments [0 ].(map [string ]any )
@@ -85,8 +94,8 @@ func (r *FileLengthLimitRule) configure(arguments lint.Arguments) {
85
94
switch k {
86
95
case "max" :
87
96
maxLines , ok := v .(int64 )
88
- if ! ok || maxLines < 1 {
89
- panic (fmt .Sprintf (`invalid configuration value for max lines in "file-length-limit" rule; need int64 but got %T` , arguments [0 ]))
97
+ if ! ok || maxLines < 0 {
98
+ panic (fmt .Sprintf (`invalid configuration value for max lines in "file-length-limit" rule; need positive int64 but got %T` , arguments [0 ]))
90
99
}
91
100
r .max = int (maxLines )
92
101
case "skipComments" :
0 commit comments