@@ -63,6 +63,10 @@ func (p *AutogeneratedExclude) shouldPassIssue(issue *result.Issue) (bool, error
63
63
return true , nil
64
64
}
65
65
66
+ if issue .FilePath () == "" {
67
+ return false , errors .New ("no file path for issue" )
68
+ }
69
+
66
70
if ! isGoFile (issue .FilePath ()) {
67
71
return false , nil
68
72
}
@@ -76,20 +80,16 @@ func (p *AutogeneratedExclude) shouldPassIssue(issue *result.Issue) (bool, error
76
80
fs = & fileSummary {}
77
81
p .fileSummaryCache [issue .FilePath ()] = fs
78
82
79
- if issue .FilePath () == "" {
80
- return false , errors .New ("no file path for issue" )
81
- }
82
-
83
83
if p .strict {
84
84
var err error
85
85
fs .generated , err = p .isGeneratedFileStrict (issue .FilePath ())
86
86
if err != nil {
87
- return false , fmt .Errorf ("failed to get doc of file %s: %w" , issue .FilePath (), err )
87
+ return false , fmt .Errorf ("failed to get doc (strict) of file %s: %w" , issue .FilePath (), err )
88
88
}
89
89
} else {
90
90
doc , err := getComments (issue .FilePath ())
91
91
if err != nil {
92
- return false , fmt .Errorf ("failed to get doc of file %s: %w" , issue .FilePath (), err )
92
+ return false , fmt .Errorf ("failed to get doc (lax) of file %s: %w" , issue .FilePath (), err )
93
93
}
94
94
95
95
fs .generated = p .isGeneratedFileLax (doc )
@@ -102,7 +102,7 @@ func (p *AutogeneratedExclude) shouldPassIssue(issue *result.Issue) (bool, error
102
102
}
103
103
104
104
// isGeneratedFileLax reports whether the source file is generated code.
105
- // Using a bit laxer rules than https://go.dev/s/generatedcode to match more generated code.
105
+ // The function uses a bit laxer rules than isGeneratedFileStrict to match more generated code.
106
106
// See https://github.com/golangci/golangci-lint/issues/48 and https://github.com/golangci/golangci-lint/issues/72.
107
107
func (p * AutogeneratedExclude ) isGeneratedFileLax (doc string ) bool {
108
108
markers := []string {genCodeGenerated , genDoNotEdit , genAutoFile }
@@ -122,8 +122,12 @@ func (p *AutogeneratedExclude) isGeneratedFileLax(doc string) bool {
122
122
return false
123
123
}
124
124
125
- // Based on https://go.dev/s/generatedcode
126
- // > This line must appear before the first non-comment, non-blank text in the file.
125
+ // isGeneratedFileStrict returns true if the source file has a line that matches the regular expression:
126
+ //
127
+ // ^// Code generated .* DO NOT EDIT\.$
128
+ //
129
+ // This line must appear before the first non-comment, non-blank text in the file.
130
+ // Based on https://go.dev/s/generatedcode.
127
131
func (p * AutogeneratedExclude ) isGeneratedFileStrict (filePath string ) (bool , error ) {
128
132
file , err := parser .ParseFile (token .NewFileSet (), filePath , nil , parser .PackageClauseOnly | parser .ParseComments )
129
133
if err != nil {
0 commit comments