Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
fix: funlen ignore-comments
  • Loading branch information
ldez committed Mar 24, 2025
commit d2116e44b5ef75c6eda0ff9ff56dd2048ea5c5f7
2 changes: 1 addition & 1 deletion pkg/golinters/funlen/funlen.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func New(settings *config.FunlenSettings) *goanalysis.Linter {
if settings != nil {
cfg.lineLimit = settings.Lines
cfg.stmtLimit = settings.Statements
cfg.ignoreComments = !settings.IgnoreComments
cfg.ignoreComments = settings.IgnoreComments
}

a := funlen.NewAnalyzer(cfg.lineLimit, cfg.stmtLimit, cfg.ignoreComments)
Expand Down
101 changes: 63 additions & 38 deletions pkg/golinters/funlen/testdata/funlen.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,67 @@
//golangcitest:args -Efunlen
//golangcitest:config_path testdata/funlen.yml
package testdata

func TooManyLines() { // want `Function 'TooManyLines' is too long \(22 > 20\)`
t := struct {
A string
B string
C string
D string
E string
F string
G string
H string
I string
}{
`a`,
`b`,
`c`,
`d`,
`e`,
`f`,
`g`,
`h`,
`i`,
}
_ = t
}

func TooManyStatements() { // want `Function 'TooManyStatements' has too many statements \(11 > 10\)`
a := 1
b := a
c := b
d := c
e := d
f := e
g := f
h := g
i := h
j := i
_ = j
// want +1 "Function 'main' is too long"
func main() {
// Comment 1
// Comment 2
// Comment 3
// Comment 4
// Comment 5
// Comment 6
// Comment 7
// Comment 8
// Comment 9
// Comment 10
// Comment 11
// Comment 12
// Comment 13
// Comment 14
// Comment 15
// Comment 16
// Comment 17
// Comment 18
// Comment 19
// Comment 20
// Comment 21
// Comment 22
// Comment 23
// Comment 24
// Comment 25
// Comment 26
// Comment 27
// Comment 28
// Comment 29
// Comment 30
// Comment 31
// Comment 32
// Comment 33
// Comment 34
// Comment 35
// Comment 36
// Comment 37
// Comment 38
// Comment 39
// Comment 40
// Comment 41
// Comment 42
// Comment 43
// Comment 44
// Comment 45
// Comment 46
// Comment 47
// Comment 48
// Comment 49
// Comment 50
// Comment 51
// Comment 52
// Comment 53
// Comment 54
// Comment 55
// Comment 56
// Comment 57
// Comment 58
// Comment 59
// Comment 60
print("Hello, world!")
}
87 changes: 63 additions & 24 deletions pkg/golinters/funlen/testdata/funlen_cgo.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//golangcitest:args -Efunlen
//golangcitest:config_path testdata/funlen.yml
package testdata

/*
Expand All @@ -22,27 +21,67 @@ func _() {
C.free(unsafe.Pointer(cs))
}

func _() { // want `Function '_' is too long \(22 > 20\)`
t := struct {
A string
B string
C string
D string
E string
F string
G string
H string
I string
}{
`a`,
`b`,
`c`,
`d`,
`e`,
`f`,
`g`,
`h`,
`i`,
}
_ = t
// want +1 "Function 'main' is too long"
func main() {
// Comment 1
// Comment 2
// Comment 3
// Comment 4
// Comment 5
// Comment 6
// Comment 7
// Comment 8
// Comment 9
// Comment 10
// Comment 11
// Comment 12
// Comment 13
// Comment 14
// Comment 15
// Comment 16
// Comment 17
// Comment 18
// Comment 19
// Comment 20
// Comment 21
// Comment 22
// Comment 23
// Comment 24
// Comment 25
// Comment 26
// Comment 27
// Comment 28
// Comment 29
// Comment 30
// Comment 31
// Comment 32
// Comment 33
// Comment 34
// Comment 35
// Comment 36
// Comment 37
// Comment 38
// Comment 39
// Comment 40
// Comment 41
// Comment 42
// Comment 43
// Comment 44
// Comment 45
// Comment 46
// Comment 47
// Comment 48
// Comment 49
// Comment 50
// Comment 51
// Comment 52
// Comment 53
// Comment 54
// Comment 55
// Comment 56
// Comment 57
// Comment 58
// Comment 59
// Comment 60
print("Hello, world!")
}
42 changes: 42 additions & 0 deletions pkg/golinters/funlen/testdata/funlen_custom.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//golangcitest:args -Efunlen
//golangcitest:config_path testdata/funlen_custom.yml
package testdata

func TooManyLines() { // want `Function 'TooManyLines' is too long \(22 > 20\)`
t := struct {
A string
B string
C string
D string
E string
F string
G string
H string
I string
}{
`a`,
`b`,
`c`,
`d`,
`e`,
`f`,
`g`,
`h`,
`i`,
}
_ = t
}

func TooManyStatements() { // want `Function 'TooManyStatements' has too many statements \(11 > 10\)`
a := 1
b := a
c := b
d := c
e := d
f := e
g := f
h := g
i := h
j := i
_ = j
}
68 changes: 68 additions & 0 deletions pkg/golinters/funlen/testdata/funlen_ignore_comments.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//golangcitest:args -Efunlen
//golangcitest:config_path testdata/funlen_ignore_comments.yml
//golangcitest:expected_exitcode 0
package testdata

func main() {
// Comment 1
// Comment 2
// Comment 3
// Comment 4
// Comment 5
// Comment 6
// Comment 7
// Comment 8
// Comment 9
// Comment 10
// Comment 11
// Comment 12
// Comment 13
// Comment 14
// Comment 15
// Comment 16
// Comment 17
// Comment 18
// Comment 19
// Comment 20
// Comment 21
// Comment 22
// Comment 23
// Comment 24
// Comment 25
// Comment 26
// Comment 27
// Comment 28
// Comment 29
// Comment 30
// Comment 31
// Comment 32
// Comment 33
// Comment 34
// Comment 35
// Comment 36
// Comment 37
// Comment 38
// Comment 39
// Comment 40
// Comment 41
// Comment 42
// Comment 43
// Comment 44
// Comment 45
// Comment 46
// Comment 47
// Comment 48
// Comment 49
// Comment 50
// Comment 51
// Comment 52
// Comment 53
// Comment 54
// Comment 55
// Comment 56
// Comment 57
// Comment 58
// Comment 59
// Comment 60
print("Hello, world!")
}
6 changes: 6 additions & 0 deletions pkg/golinters/funlen/testdata/funlen_ignore_comments.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
version: "2"

linters:
settings:
funlen:
ignore-comments: true
Loading