Skip to content

Commit 4ab7da5

Browse files
author
Rethil
committed
fix auto-generated code detection
This allows to detect files with auto-generated signatures such as: - // Code generated by go-enum DO NOT EDIT. - // Code generated by sqlc. DO NOT EDIT.
1 parent faf4e4a commit 4ab7da5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

docs/include-auto-generated.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ title: include-auto-generated
44

55
:octicons-tag-24: v3.5.0
66

7-
The `#!yaml include-auto-generated:` parameter specifies whether or not mockery should include source files that appear to be auto-generated. By default, mockery will search for the presence of a string in the source code that appears before the `#!go package foo` declaration that matches the regular expression `^\/\/ Code generated by .*; DO NOT EDIT(\.?)( )*$`. Sometimes, users may wish to override this behavior and unconditionally include these source files. For example:
7+
The `#!yaml include-auto-generated:` parameter specifies whether or not mockery should include source files that appear to be auto-generated. By default, mockery will search for the presence of a string in the source code that appears before the `#!go package foo` declaration that matches the regular expression `^\/\/ Code generated by .* DO NOT EDIT(\.?)( )*$`. Sometimes, users may wish to override this behavior and unconditionally include these source files. For example:
88

99
```yaml title=".mockery.yml"
1010
packages:
@@ -18,7 +18,7 @@ You may also set this at the top-level as such:
1818
```yaml title=".mockery.yml"
1919
include-auto-generated: true
2020
packages:
21-
github.com/vektra/mockery/v3/internal/fixtures/include_auto_generated:
21+
github.com/vektra/mockery/v3/internal/fixtures/include_auto_generated:
2222
```
2323
2424
It is not possible to set this parameter at the interface level config because mockery performs this regular expression check before parsing the syntax in the source file. Allowing users to specify this on the interface-level config would require mockery to unconditionally parse all files, which defeats the performance benefits of excluding such auto-generated files in the first place.

internal/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import (
1919
"golang.org/x/tools/go/packages"
2020
)
2121

22-
var autoGeneratedRegex = regexp.MustCompile(`^\/\/ Code generated by .*; DO NOT EDIT(\.?)( )*$`)
22+
var autoGeneratedRegex = regexp.MustCompile(`^\/\/ Code generated by .* DO NOT EDIT(\.?)( )*$`)
2323

2424
type Parser struct {
2525
parserPackages []*types.Package

0 commit comments

Comments
 (0)