Skip to content
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 @@ -22,7 +22,7 @@ require (
github.com/ashanbrown/makezero v1.1.1
github.com/bkielbasa/cyclop v1.2.1
github.com/blizzy78/varnamelen v0.8.0
github.com/bombsimon/wsl/v3 v3.4.0
github.com/bombsimon/wsl/v4 v4.2.0
github.com/breml/bidichk v0.2.7
github.com/breml/errchkjson v0.3.6
github.com/butuzov/ireturn v0.2.2
Expand Down
7 changes: 3 additions & 4 deletions go.sum

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

94 changes: 22 additions & 72 deletions pkg/golinters/wsl.go
Original file line number Diff line number Diff line change
@@ -1,89 +1,39 @@
package golinters

import (
"sync"

"github.com/bombsimon/wsl/v3"
"github.com/bombsimon/wsl/v4"
"golang.org/x/tools/go/analysis"

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

const wslName = "wsl"

// NewWSL returns a new WSL linter.
func NewWSL(settings *config.WSLSettings) *goanalysis.Linter {
var mu sync.Mutex
var resIssues []goanalysis.Issue

conf := wsl.DefaultConfig()

var conf *wsl.Configuration
if settings != nil {
conf.StrictAppend = settings.StrictAppend
conf.AllowAssignAndCallCuddle = settings.AllowAssignAndCallCuddle
conf.AllowAssignAndAnythingCuddle = settings.AllowAssignAndAnythingCuddle
conf.AllowMultiLineAssignCuddle = settings.AllowMultiLineAssignCuddle
conf.ForceCaseTrailingWhitespaceLimit = settings.ForceCaseTrailingWhitespaceLimit
conf.AllowTrailingComment = settings.AllowTrailingComment
conf.AllowSeparatedLeadingComment = settings.AllowSeparatedLeadingComment
conf.AllowCuddleDeclaration = settings.AllowCuddleDeclaration
conf.AllowCuddleWithCalls = settings.AllowCuddleWithCalls
conf.AllowCuddleWithRHS = settings.AllowCuddleWithRHS
conf.ForceCuddleErrCheckAndAssign = settings.ForceCuddleErrCheckAndAssign
conf.ErrorVariableNames = settings.ErrorVariableNames
conf.ForceExclusiveShortDeclarations = settings.ForceExclusiveShortDeclarations
conf = &wsl.Configuration{
StrictAppend: settings.StrictAppend,
AllowAssignAndCallCuddle: settings.AllowAssignAndCallCuddle,
AllowAssignAndAnythingCuddle: settings.AllowAssignAndAnythingCuddle,
AllowMultiLineAssignCuddle: settings.AllowMultiLineAssignCuddle,
ForceCaseTrailingWhitespaceLimit: settings.ForceCaseTrailingWhitespaceLimit,
AllowTrailingComment: settings.AllowTrailingComment,
AllowSeparatedLeadingComment: settings.AllowSeparatedLeadingComment,
AllowCuddleDeclaration: settings.AllowCuddleDeclaration,
AllowCuddleWithCalls: settings.AllowCuddleWithCalls,
AllowCuddleWithRHS: settings.AllowCuddleWithRHS,
ForceCuddleErrCheckAndAssign: settings.ForceCuddleErrCheckAndAssign,
ErrorVariableNames: settings.ErrorVariableNames,
ForceExclusiveShortDeclarations: settings.ForceExclusiveShortDeclarations,
}
}

analyzer := &analysis.Analyzer{
Name: goanalysis.TheOnlyAnalyzerName,
Doc: goanalysis.TheOnlyanalyzerDoc,
Run: func(pass *analysis.Pass) (any, error) {
issues := runWSL(pass, &conf)

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

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

return nil, nil
},
}
a := wsl.NewAnalyzer(conf)

return goanalysis.NewLinter(
wslName,
"Whitespace Linter - Forces you to use empty lines!",
[]*analysis.Analyzer{analyzer},
a.Name,
a.Doc,
[]*analysis.Analyzer{a},
nil,
).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
return resIssues
}).WithLoadMode(goanalysis.LoadModeSyntax)
}

func runWSL(pass *analysis.Pass, conf *wsl.Configuration) []goanalysis.Issue {
if conf == nil {
return nil
}

files := getFileNames(pass)
wslErrors, _ := wsl.NewProcessorWithConfig(*conf).ProcessFiles(files)
if len(wslErrors) == 0 {
return nil
}

var issues []goanalysis.Issue
for _, err := range wslErrors {
issues = append(issues, goanalysis.NewIssue(&result.Issue{
FromLinter: wslName,
Pos: err.Position,
Text: err.Reason,
}, pass))
}

return issues
).WithLoadMode(goanalysis.LoadModeSyntax)
}