-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
use go1.21 ast.IsGenerated when available
- Loading branch information
Showing
3 changed files
with
38 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
//go:build go1.21 | ||
|
||
package exhaustive | ||
|
||
import ( | ||
"go/ast" | ||
) | ||
|
||
func isGeneratedFile(file *ast.File) bool { | ||
return ast.IsGenerated(file) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
//go:build !go1.21 | ||
|
||
package exhaustive | ||
|
||
import ( | ||
"go/ast" | ||
"regexp" | ||
) | ||
|
||
// For definition of generated file see: | ||
// http://golang.org/s/generatedcode | ||
|
||
var generatedCodeRe = regexp.MustCompile(`^// Code generated .* DO NOT EDIT\.$`) | ||
|
||
func isGeneratedFile(file *ast.File) bool { | ||
for _, c := range file.Comments { | ||
for _, cc := range c.List { | ||
if cc.Pos() > file.Package { | ||
break | ||
} | ||
if generatedCodeRe.MatchString(cc.Text) { | ||
return true | ||
} | ||
} | ||
} | ||
return false | ||
} |