Skip to content

Commit 966259a

Browse files
build(deps): bump github.com/ultraware/funlen from 0.1.0 to 0.2.0 (#5231)
Co-authored-by: Fernandez Ludovic <[email protected]>
1 parent c751e5c commit 966259a

File tree

3 files changed

+19
-61
lines changed

3 files changed

+19
-61
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ require (
113113
github.com/timonwong/loggercheck v0.10.1
114114
github.com/tomarrell/wrapcheck/v2 v2.10.0
115115
github.com/tommy-muehle/go-mnd/v2 v2.5.1
116-
github.com/ultraware/funlen v0.1.0
116+
github.com/ultraware/funlen v0.2.0
117117
github.com/ultraware/whitespace v0.1.1
118118
github.com/uudashr/gocognit v1.2.0
119119
github.com/uudashr/iface v1.3.0

go.sum

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/golinters/funlen/funlen.go

+16-58
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,33 @@
11
package funlen
22

33
import (
4-
"go/token"
5-
"strings"
6-
"sync"
7-
84
"github.com/ultraware/funlen"
95
"golang.org/x/tools/go/analysis"
106

117
"github.com/golangci/golangci-lint/pkg/config"
128
"github.com/golangci/golangci-lint/pkg/goanalysis"
13-
"github.com/golangci/golangci-lint/pkg/lint/linter"
14-
"github.com/golangci/golangci-lint/pkg/result"
159
)
1610

17-
const linterName = "funlen"
11+
type Config struct {
12+
lineLimit int
13+
stmtLimit int
14+
ignoreComments bool
15+
}
1816

1917
func New(settings *config.FunlenSettings) *goanalysis.Linter {
20-
var mu sync.Mutex
21-
var resIssues []goanalysis.Issue
22-
23-
analyzer := &analysis.Analyzer{
24-
Name: linterName,
25-
Doc: goanalysis.TheOnlyanalyzerDoc,
26-
Run: func(pass *analysis.Pass) (any, error) {
27-
issues := runFunlen(pass, settings)
28-
29-
if len(issues) == 0 {
30-
return nil, nil
31-
}
32-
33-
mu.Lock()
34-
resIssues = append(resIssues, issues...)
35-
mu.Unlock()
36-
37-
return nil, nil
38-
},
18+
cfg := Config{}
19+
if settings != nil {
20+
cfg.lineLimit = settings.Lines
21+
cfg.stmtLimit = settings.Statements
22+
cfg.ignoreComments = !settings.IgnoreComments
3923
}
4024

25+
a := funlen.NewAnalyzer(cfg.lineLimit, cfg.stmtLimit, cfg.ignoreComments)
26+
4127
return goanalysis.NewLinter(
42-
linterName,
43-
"Tool for detection of long functions",
44-
[]*analysis.Analyzer{analyzer},
28+
a.Name,
29+
a.Doc,
30+
[]*analysis.Analyzer{a},
4531
nil,
46-
).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
47-
return resIssues
48-
}).WithLoadMode(goanalysis.LoadModeSyntax)
49-
}
50-
51-
func runFunlen(pass *analysis.Pass, settings *config.FunlenSettings) []goanalysis.Issue {
52-
var lintIssues []funlen.Message
53-
for _, file := range pass.Files {
54-
fileIssues := funlen.Run(file, pass.Fset, settings.Lines, settings.Statements, settings.IgnoreComments)
55-
lintIssues = append(lintIssues, fileIssues...)
56-
}
57-
58-
if len(lintIssues) == 0 {
59-
return nil
60-
}
61-
62-
issues := make([]goanalysis.Issue, len(lintIssues))
63-
for k, i := range lintIssues {
64-
issues[k] = goanalysis.NewIssue(&result.Issue{
65-
Pos: token.Position{
66-
Filename: i.Pos.Filename,
67-
Line: i.Pos.Line,
68-
},
69-
Text: strings.TrimRight(i.Message, "\n"),
70-
FromLinter: linterName,
71-
}, pass)
72-
}
73-
74-
return issues
32+
).WithLoadMode(goanalysis.LoadModeSyntax)
7533
}

0 commit comments

Comments
 (0)