-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add flag
--skip-generated
to skip generated code (#150)
This diff adds the flag `--skip-generated` to be able to skip running gopatch on files containing generated code. When the flag is set to true, if the comments contains `@generated` or the special go generated code comment `^// Code generated .* DO NOT EDIT\.$`, we do not run gopatch on that particular file. We are adding a check for the former case(@generated) as at times, the generated code does not follow the the special go generated code format perfectly. Example: For test file `testdata/test_file/skip_generated_file/special_notation_generated.go`, if we apply the patch `testdata/patch/time.go` Without running `--skip-generated`, the file gets modified to ``` --- testdata/test_files/skip_generated_files/test1.go +++ testdata/test_files/skip_generated_files/test1.go @@ -9,6 +9,6 @@ func main() { startOfYear := time.Date(2021, 0o1, 0o1, 0, 0, 0, 0, time.UTC) - result := time.Now().Sub(startOfYear) + result := time.Since(startOfYear) fmt.Println(result) } ``` Running with flag `--skip-generated`, file isn't modified at all. Internal ref: GO-2502 Note: We also upgraded the go version to 1.22 to use the [ast.IsGenerated ](https://pkg.go.dev/go/ast#IsGenerated) function which was introduced in 1.21.
- Loading branch information
Showing
10 changed files
with
139 additions
and
4 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
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
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
13 changes: 13 additions & 0 deletions
13
testdata/test_files/skip_generated_files/simple_generated.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
testdata/test_files/skip_generated_files/special_notation_generated.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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