Skip to content

Commit

Permalink
build(deps): bump github.com/ultraware/funlen from 0.1.0 to 0.2.0 (#5231
Browse files Browse the repository at this point in the history
)

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
  • Loading branch information
dependabot[bot] and ldez authored Dec 16, 2024
1 parent c751e5c commit 966259a
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 61 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ require (
github.com/timonwong/loggercheck v0.10.1
github.com/tomarrell/wrapcheck/v2 v2.10.0
github.com/tommy-muehle/go-mnd/v2 v2.5.1
github.com/ultraware/funlen v0.1.0
github.com/ultraware/funlen v0.2.0
github.com/ultraware/whitespace v0.1.1
github.com/uudashr/gocognit v1.2.0
github.com/uudashr/iface v1.3.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

74 changes: 16 additions & 58 deletions pkg/golinters/funlen/funlen.go
Original file line number Diff line number Diff line change
@@ -1,75 +1,33 @@
package funlen

import (
"go/token"
"strings"
"sync"

"github.com/ultraware/funlen"
"golang.org/x/tools/go/analysis"

"github.com/golangci/golangci-lint/pkg/config"
"github.com/golangci/golangci-lint/pkg/goanalysis"
"github.com/golangci/golangci-lint/pkg/lint/linter"
"github.com/golangci/golangci-lint/pkg/result"
)

const linterName = "funlen"
type Config struct {
lineLimit int
stmtLimit int
ignoreComments bool
}

func New(settings *config.FunlenSettings) *goanalysis.Linter {
var mu sync.Mutex
var resIssues []goanalysis.Issue

analyzer := &analysis.Analyzer{
Name: linterName,
Doc: goanalysis.TheOnlyanalyzerDoc,
Run: func(pass *analysis.Pass) (any, error) {
issues := runFunlen(pass, settings)

if len(issues) == 0 {
return nil, nil
}

mu.Lock()
resIssues = append(resIssues, issues...)
mu.Unlock()

return nil, nil
},
cfg := Config{}
if settings != nil {
cfg.lineLimit = settings.Lines
cfg.stmtLimit = settings.Statements
cfg.ignoreComments = !settings.IgnoreComments
}

a := funlen.NewAnalyzer(cfg.lineLimit, cfg.stmtLimit, cfg.ignoreComments)

return goanalysis.NewLinter(
linterName,
"Tool for detection of long functions",
[]*analysis.Analyzer{analyzer},
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
return resIssues
}).WithLoadMode(goanalysis.LoadModeSyntax)
}

func runFunlen(pass *analysis.Pass, settings *config.FunlenSettings) []goanalysis.Issue {
var lintIssues []funlen.Message
for _, file := range pass.Files {
fileIssues := funlen.Run(file, pass.Fset, settings.Lines, settings.Statements, settings.IgnoreComments)
lintIssues = append(lintIssues, fileIssues...)
}

if len(lintIssues) == 0 {
return nil
}

issues := make([]goanalysis.Issue, len(lintIssues))
for k, i := range lintIssues {
issues[k] = goanalysis.NewIssue(&result.Issue{
Pos: token.Position{
Filename: i.Pos.Filename,
Line: i.Pos.Line,
},
Text: strings.TrimRight(i.Message, "\n"),
FromLinter: linterName,
}, pass)
}

return issues
).WithLoadMode(goanalysis.LoadModeSyntax)
}

0 comments on commit 966259a

Please # to comment.