Skip to content

Commit 89dc119

Browse files
committed
chore: migrate whitespace
1 parent ebcff94 commit 89dc119

File tree

1 file changed

+2
-75
lines changed

1 file changed

+2
-75
lines changed
Lines changed: 2 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,18 @@
11
package whitespace
22

33
import (
4-
"fmt"
5-
"sync"
6-
74
"github.com/ultraware/whitespace"
85
"golang.org/x/tools/go/analysis"
96

107
"github.com/golangci/golangci-lint/pkg/config"
118
"github.com/golangci/golangci-lint/pkg/goanalysis"
12-
"github.com/golangci/golangci-lint/pkg/lint/linter"
13-
"github.com/golangci/golangci-lint/pkg/result"
149
)
1510

16-
const linterName = "whitespace"
17-
1811
func New(settings *config.WhitespaceSettings) *goanalysis.Linter {
19-
var mu sync.Mutex
20-
var resIssues []goanalysis.Issue
21-
2212
var wsSettings whitespace.Settings
2313
if settings != nil {
2414
wsSettings = whitespace.Settings{
25-
Mode: whitespace.RunningModeGolangCI,
15+
Mode: whitespace.RunningModeNative,
2616
MultiIf: settings.MultiIf,
2717
MultiFunc: settings.MultiFunc,
2818
}
@@ -35,68 +25,5 @@ func New(settings *config.WhitespaceSettings) *goanalysis.Linter {
3525
a.Doc,
3626
[]*analysis.Analyzer{a},
3727
nil,
38-
).WithContextSetter(func(_ *linter.Context) {
39-
a.Run = func(pass *analysis.Pass) (any, error) {
40-
issues, err := runWhitespace(pass, wsSettings)
41-
if err != nil {
42-
return nil, err
43-
}
44-
45-
if len(issues) == 0 {
46-
return nil, nil
47-
}
48-
49-
mu.Lock()
50-
resIssues = append(resIssues, issues...)
51-
mu.Unlock()
52-
53-
return nil, nil
54-
}
55-
}).WithIssuesReporter(func(*linter.Context) []goanalysis.Issue {
56-
return resIssues
57-
}).WithLoadMode(goanalysis.LoadModeSyntax)
58-
}
59-
60-
func runWhitespace(pass *analysis.Pass, wsSettings whitespace.Settings) ([]goanalysis.Issue, error) {
61-
lintIssues := whitespace.Run(pass, &wsSettings)
62-
63-
issues := make([]goanalysis.Issue, len(lintIssues))
64-
for i, issue := range lintIssues {
65-
report := &result.Issue{
66-
FromLinter: linterName,
67-
Pos: pass.Fset.PositionFor(issue.Diagnostic, false),
68-
Text: issue.Message,
69-
}
70-
71-
switch issue.MessageType {
72-
case whitespace.MessageTypeRemove:
73-
if len(issue.LineNumbers) == 0 {
74-
continue
75-
}
76-
77-
report.LineRange = &result.Range{
78-
From: issue.LineNumbers[0],
79-
To: issue.LineNumbers[len(issue.LineNumbers)-1],
80-
}
81-
82-
report.Replacement = &result.Replacement{NeedOnlyDelete: true}
83-
84-
case whitespace.MessageTypeAdd:
85-
report.Pos = pass.Fset.PositionFor(issue.FixStart, false)
86-
report.Replacement = &result.Replacement{
87-
Inline: &result.InlineFix{
88-
StartCol: 0,
89-
Length: 1,
90-
NewString: "\n\t",
91-
},
92-
}
93-
94-
default:
95-
return nil, fmt.Errorf("unknown message type: %v", issue.MessageType)
96-
}
97-
98-
issues[i] = goanalysis.NewIssue(report, pass)
99-
}
100-
101-
return issues, nil
28+
).WithLoadMode(goanalysis.LoadModeSyntax)
10229
}

0 commit comments

Comments
 (0)