Skip to content

Add support for ignoring generated files #29

Open

Description

@benjivesterby

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.

Activity

  1. leighmcculloch commented on Dec 4, 2021

    @leighmcculloch
    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.

  2. benjivesterby commented on Dec 4, 2021

    @benjivesterby
    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.

  3. leighmcculloch commented on Jan 15, 2023

    @leighmcculloch
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions