1
1
package processors
2
2
3
3
import (
4
- "errors"
5
4
"go/ast"
6
5
"go/parser"
7
6
"go/token"
@@ -99,19 +98,15 @@ func (p *Nolint) Process(issues []result.Issue) ([]result.Issue, error) {
99
98
return filterIssuesErr (issues , p .shouldPassIssue )
100
99
}
101
100
102
- func (p * Nolint ) getOrCreateFileData (issue * result.Issue ) ( * fileData , error ) {
101
+ func (p * Nolint ) getOrCreateFileData (issue * result.Issue ) * fileData {
103
102
fd := p .cache [issue .FilePath ()]
104
103
if fd != nil {
105
- return fd , nil
104
+ return fd
106
105
}
107
106
108
107
fd = & fileData {}
109
108
p .cache [issue .FilePath ()] = fd
110
109
111
- if issue .FilePath () == "" {
112
- return nil , errors .New ("no file path for issue" )
113
- }
114
-
115
110
// TODO: migrate this parsing to go/analysis facts
116
111
// or cache them somehow per file.
117
112
@@ -120,12 +115,14 @@ func (p *Nolint) getOrCreateFileData(issue *result.Issue) (*fileData, error) {
120
115
f , err := parser .ParseFile (fset , issue .FilePath (), nil , parser .ParseComments )
121
116
if err != nil {
122
117
// Don't report error because it's already must be reporter by typecheck or go/analysis.
123
- return fd , nil
118
+ return fd
124
119
}
125
120
126
121
fd .ignoredRanges = p .buildIgnoredRangesForFile (f , fset , issue .FilePath ())
122
+
127
123
nolintDebugf ("file %s: built nolint ranges are %+v" , issue .FilePath (), fd .ignoredRanges )
128
- return fd , nil
124
+
125
+ return fd
129
126
}
130
127
131
128
func (p * Nolint ) buildIgnoredRangesForFile (f * ast.File , fset * token.FileSet , filePath string ) []ignoredRange {
@@ -161,10 +158,7 @@ func (p *Nolint) shouldPassIssue(issue *result.Issue) (bool, error) {
161
158
nolintDebugf ("checking that lint issue was used for %s: %v" , issue .ExpectedNoLintLinter , issue )
162
159
}
163
160
164
- fd , err := p .getOrCreateFileData (issue )
165
- if err != nil {
166
- return false , err
167
- }
161
+ fd := p .getOrCreateFileData (issue )
168
162
169
163
for _ , ir := range fd .ignoredRanges {
170
164
if ir .doesMatch (issue ) {
0 commit comments