|
1 | 1 | package golinters |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "sync" |
5 | | - |
6 | | - "github.com/bombsimon/wsl/v3" |
| 4 | + "github.com/bombsimon/wsl/v4" |
7 | 5 | "golang.org/x/tools/go/analysis" |
8 | 6 |
|
9 | 7 | "github.com/golangci/golangci-lint/pkg/config" |
10 | 8 | "github.com/golangci/golangci-lint/pkg/golinters/goanalysis" |
11 | | - "github.com/golangci/golangci-lint/pkg/lint/linter" |
12 | | - "github.com/golangci/golangci-lint/pkg/result" |
13 | 9 | ) |
14 | 10 |
|
15 | | -const wslName = "wsl" |
16 | | - |
17 | | -// NewWSL returns a new WSL linter. |
18 | 11 | func NewWSL(settings *config.WSLSettings) *goanalysis.Linter { |
19 | | - var mu sync.Mutex |
20 | | - var resIssues []goanalysis.Issue |
21 | | - |
22 | | - conf := wsl.DefaultConfig() |
23 | | - |
| 12 | + var conf *wsl.Configuration |
24 | 13 | if settings != nil { |
25 | | - conf.StrictAppend = settings.StrictAppend |
26 | | - conf.AllowAssignAndCallCuddle = settings.AllowAssignAndCallCuddle |
27 | | - conf.AllowAssignAndAnythingCuddle = settings.AllowAssignAndAnythingCuddle |
28 | | - conf.AllowMultiLineAssignCuddle = settings.AllowMultiLineAssignCuddle |
29 | | - conf.ForceCaseTrailingWhitespaceLimit = settings.ForceCaseTrailingWhitespaceLimit |
30 | | - conf.AllowTrailingComment = settings.AllowTrailingComment |
31 | | - conf.AllowSeparatedLeadingComment = settings.AllowSeparatedLeadingComment |
32 | | - conf.AllowCuddleDeclaration = settings.AllowCuddleDeclaration |
33 | | - conf.AllowCuddleWithCalls = settings.AllowCuddleWithCalls |
34 | | - conf.AllowCuddleWithRHS = settings.AllowCuddleWithRHS |
35 | | - conf.ForceCuddleErrCheckAndAssign = settings.ForceCuddleErrCheckAndAssign |
36 | | - conf.ErrorVariableNames = settings.ErrorVariableNames |
37 | | - conf.ForceExclusiveShortDeclarations = settings.ForceExclusiveShortDeclarations |
| 14 | + conf = &wsl.Configuration{ |
| 15 | + StrictAppend: settings.StrictAppend, |
| 16 | + AllowAssignAndCallCuddle: settings.AllowAssignAndCallCuddle, |
| 17 | + AllowAssignAndAnythingCuddle: settings.AllowAssignAndAnythingCuddle, |
| 18 | + AllowMultiLineAssignCuddle: settings.AllowMultiLineAssignCuddle, |
| 19 | + ForceCaseTrailingWhitespaceLimit: settings.ForceCaseTrailingWhitespaceLimit, |
| 20 | + AllowTrailingComment: settings.AllowTrailingComment, |
| 21 | + AllowSeparatedLeadingComment: settings.AllowSeparatedLeadingComment, |
| 22 | + AllowCuddleDeclaration: settings.AllowCuddleDeclaration, |
| 23 | + AllowCuddleWithCalls: settings.AllowCuddleWithCalls, |
| 24 | + AllowCuddleWithRHS: settings.AllowCuddleWithRHS, |
| 25 | + ForceCuddleErrCheckAndAssign: settings.ForceCuddleErrCheckAndAssign, |
| 26 | + ErrorVariableNames: settings.ErrorVariableNames, |
| 27 | + ForceExclusiveShortDeclarations: settings.ForceExclusiveShortDeclarations, |
| 28 | + } |
38 | 29 | } |
39 | 30 |
|
40 | | - analyzer := &analysis.Analyzer{ |
41 | | - Name: goanalysis.TheOnlyAnalyzerName, |
42 | | - Doc: goanalysis.TheOnlyanalyzerDoc, |
43 | | - Run: func(pass *analysis.Pass) (any, error) { |
44 | | - issues := runWSL(pass, &conf) |
45 | | - |
46 | | - if len(issues) == 0 { |
47 | | - return nil, nil |
48 | | - } |
49 | | - |
50 | | - mu.Lock() |
51 | | - resIssues = append(resIssues, issues...) |
52 | | - mu.Unlock() |
53 | | - |
54 | | - return nil, nil |
55 | | - }, |
56 | | - } |
| 31 | + a := wsl.NewAnalyzer(conf) |
57 | 32 |
|
58 | 33 | return goanalysis.NewLinter( |
59 | | - wslName, |
60 | | - "Whitespace Linter - Forces you to use empty lines!", |
61 | | - []*analysis.Analyzer{analyzer}, |
| 34 | + a.Name, |
| 35 | + a.Doc, |
| 36 | + []*analysis.Analyzer{a}, |
62 | 37 | nil, |
63 | | - ).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue { |
64 | | - return resIssues |
65 | | - }).WithLoadMode(goanalysis.LoadModeSyntax) |
66 | | -} |
67 | | - |
68 | | -func runWSL(pass *analysis.Pass, conf *wsl.Configuration) []goanalysis.Issue { |
69 | | - if conf == nil { |
70 | | - return nil |
71 | | - } |
72 | | - |
73 | | - files := getFileNames(pass) |
74 | | - wslErrors, _ := wsl.NewProcessorWithConfig(*conf).ProcessFiles(files) |
75 | | - if len(wslErrors) == 0 { |
76 | | - return nil |
77 | | - } |
78 | | - |
79 | | - var issues []goanalysis.Issue |
80 | | - for _, err := range wslErrors { |
81 | | - issues = append(issues, goanalysis.NewIssue(&result.Issue{ |
82 | | - FromLinter: wslName, |
83 | | - Pos: err.Position, |
84 | | - Text: err.Reason, |
85 | | - }, pass)) |
86 | | - } |
87 | | - |
88 | | - return issues |
| 38 | + ).WithLoadMode(goanalysis.LoadModeSyntax) |
89 | 39 | } |
0 commit comments