Skip to content

Commit

Permalink
build(deps): bump github.com/bombsimon/wsl/v4 from 3.4.0 to 4.2.0 (#4215
Browse files Browse the repository at this point in the history
)

Co-authored-by: Fernandez Ludovic <[email protected]>
Co-authored-by: Simon Sawert <[email protected]>
  • Loading branch information
3 people authored Nov 29, 2023
1 parent f269abe commit e32f2f3
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 77 deletions.
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)
}

0 comments on commit e32f2f3

Please sign in to comment.