Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ignoring generated files #29

Open
benjivesterby opened this issue Dec 1, 2021 · 3 comments
Open

Add support for ignoring generated files #29

benjivesterby opened this issue Dec 1, 2021 · 3 comments

Comments

@benjivesterby
Copy link

Using the guidance here: https://pkg.go.dev/cmd/go/internal/generate

This tool should ignore files which contain the ^// Code generated .* DO NOT EDIT\.$ regex match.

This can be a flag or default, but it should allow for ignoring those files.

@leighmcculloch
Copy link
Owner

Interesting. I'm aware of the common practice to include that comment in generated files. I wasn't aware that linters should exclude those files though. TIL.

My experience with other linters, such as staticcheck, is that generated files are still processed. For example, in this other project I work on that uses staticcheck we had to include these linter comments to disable certain rules: https://github.com/stellar/go/blob/aa089ae/xdr/xdr_generated.go#L1-L2.

Looking at golangci-lint's configuration it appears many of the linters offer analyzing generated code as an option, but as you suggest, it is a flag that can be enabled or disabled. Although, it also looks like golangci-lint excludes generated code files by default at the top-level across all linters by simply excluding any issues found in them, so adding a flag is probably not necessary.

So far gochecknoglobals has been zero configuration, and folks who need more knobs use tools like golangci-lint that offer the additional knobs, and wrap gochecknoglobals and the many other linters available. I'm inclined to keep it as zero configuration unless there's strong need for configuration.

@benjivesterby Are you using golangci-lint? If you are, and you have gochecknoglobals enabled, it shouldn't report generated code files since golangci-lint will exclude any issues found on them by default. If it isn't, we should investigate that.

@benjivesterby
Copy link
Author

I'm using golangci-lint for some projects but not the one I'm running this on. It seemed like this was a missing feature other linters have which is why I submitted the issue.

@leighmcculloch
Copy link
Owner

I think I'm inclined to add a flag like -t. The way -t works is it ignores tests by default and adding -t enables tests. So if we add a flag like -g, change the default to ignore generated files, and then when -g is specified we check generated files.

Thoughts anyone?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants