Skip to content

build(deps): bump github.com/ultraware/funlen from 0.1.0 to 0.2.0 #5231

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
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)
}
Loading