File tree 3 files changed +38
-33
lines changed
3 files changed +38
-33
lines changed Original file line number Diff line number Diff line change @@ -3,42 +3,9 @@ package exhaustive
3
3
import (
4
4
"go/ast"
5
5
"go/token"
6
- "regexp"
7
6
"strings"
8
7
)
9
8
10
- // For definition of generated file see:
11
- // http://golang.org/s/generatedcode
12
-
13
- var generatedCodeRe = regexp .MustCompile (`^// Code generated .* DO NOT EDIT\.$` )
14
-
15
- func isGeneratedFile (file * ast.File ) bool {
16
- // NOTE: file.Comments includes file.Doc as well, so no need
17
- // to separately check file.Doc.
18
- for _ , c := range file .Comments {
19
- for _ , cc := range c .List {
20
- // This check handles the "must appear before the first
21
- // non-comment, non-blank text in the file" requirement.
22
- //
23
- // According to https://golang.org/ref/spec#Source_file_organization
24
- // the package clause is the first element in a file, which
25
- // should make it the first non-comment, non-blank text.
26
- if c .Pos () >= file .Package {
27
- return false
28
- }
29
- // According to the docs:
30
- // '\r' has been removed.
31
- // '\n' has been removed for //-style comments
32
- // This has also been manually verified.
33
- if generatedCodeRe .MatchString (cc .Text ) {
34
- return true
35
- }
36
- }
37
- }
38
-
39
- return false
40
- }
41
-
42
9
const (
43
10
ignoreComment = "//exhaustive:ignore"
44
11
enforceComment = "//exhaustive:enforce"
Original file line number Diff line number Diff line change
1
+ //go:build go1.21
2
+
3
+ package exhaustive
4
+
5
+ import (
6
+ "go/ast"
7
+ )
8
+
9
+ func isGeneratedFile (file * ast.File ) bool {
10
+ return ast .IsGenerated (file )
11
+ }
Original file line number Diff line number Diff line change
1
+ //go:build !go1.21
2
+
3
+ package exhaustive
4
+
5
+ import (
6
+ "go/ast"
7
+ "regexp"
8
+ )
9
+
10
+ // For definition of generated file see:
11
+ // http://golang.org/s/generatedcode
12
+
13
+ var generatedCodeRe = regexp .MustCompile (`^// Code generated .* DO NOT EDIT\.$` )
14
+
15
+ func isGeneratedFile (file * ast.File ) bool {
16
+ for _ , c := range file .Comments {
17
+ for _ , cc := range c .List {
18
+ if cc .Pos () > file .Package {
19
+ break
20
+ }
21
+ if generatedCodeRe .MatchString (cc .Text ) {
22
+ return true
23
+ }
24
+ }
25
+ }
26
+ return false
27
+ }
You can’t perform that action at this time.
0 commit comments