You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your feature request related to a problem? Please describe.
I have some Go files generated from a template I control. Some mistakes in the template can result in sub-optimal Go code being generated. For example a struct can be packed poorly and fieldalignment (from govet) would catch it.
Many linters in the bugs category could be useful on generated files which depends on changes made by contributors within the project.
Describe the solution you'd like.
A configuration options to include or exclude all or some generated files as part of the set of files being linted.
Something like:
run:
# Include generated files or not.# If disabled, specific generated files can still be skipped by adding them # to skip-dirs or skip-files.# Default: falsegenerated: true
The run options skip-dirs-use-default, skip-dirs, skip-files would still be applied such that after including generated files, some specific generated files (for example those generated from another tool) can still be explicitly ignored.
Most tools which generate Go files will either put them in a specific directory or will add a prefix in the name.
E.g. stringer will add a _string prefix so running stringer on myfile.go will produce myfile_string.go which is easy to ignore with skip-files by adding `".+_string.go".
The issues options exclude, exclude-rules and include should also be applied such that some rules can be disabled for generated files that are linted.
TL;DR this would be similar to the run option tests but for generated files instead of test files.
Describe alternatives you've considered.
Removing the "generated" comment from my generated files but that doesn't work as other tools rely on those comments to identify generated files.
Make a script to run all the linters I want on the generated files. But this require the installation of multiple individual linters and having to re-configure them. It is essentially a poor-man's implementation of golangci-lint, so what's the point...
Additional context.
The new generated option should default to false to ignore generated files and preserve the current default behavior.
Some linters also have their own options which can be toggled to handle generated files—like exhaustive and gosec—and make the overall golangci-lint configuration easier when generated files are included. Those options are currently ignored!
The text was updated successfully, but these errors were encountered:
Workaround script that can be run after code generation (careful, sed arguments are platform specific, this one is for macOS):
# files with the "Code generated" comment up top are not linted by golangci-lint.
generated_folder=$1
find "$generated_folder" -type f -name '*.go' -exec sed -i '' -e 's/Code generated/C!ode generated/g' {} +
Your feature request related to a problem? Please describe.
I have some Go files generated from a template I control. Some mistakes in the template can result in sub-optimal Go code being generated. For example a
struct
can be packed poorly andfieldalignment
(fromgovet
) would catch it.Many linters in the bugs category could be useful on generated files which depends on changes made by contributors within the project.
Describe the solution you'd like.
A configuration options to include or exclude all or some generated files as part of the set of files being linted.
Something like:
The
run
optionsskip-dirs-use-default
,skip-dirs
,skip-files
would still be applied such that after including generated files, some specific generated files (for example those generated from another tool) can still be explicitly ignored.The
issues
optionsexclude
,exclude-rules
andinclude
should also be applied such that some rules can be disabled for generated files that are linted.TL;DR this would be similar to the
run
optiontests
but for generated files instead of test files.Describe alternatives you've considered.
Additional context.
generated
option should default tofalse
to ignore generated files and preserve the current default behavior.The text was updated successfully, but these errors were encountered: