-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
build(deps): bump github.com/bombsimon/wsl/v4 from 3.4.0 to 4.2.0 (#4215
) Co-authored-by: Fernandez Ludovic <[email protected]> Co-authored-by: Simon Sawert <[email protected]>
- Loading branch information
1 parent
f269abe
commit e32f2f3
Showing
3 changed files
with
26 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |