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

Exclude some lines from the line-length-limit rule using regular expressions #778

Open
james-johnston-thumbtack opened this issue Dec 10, 2022 · 1 comment

Comments

@james-johnston-thumbtack

Is your feature request related to a problem? Please describe.
Sometimes a line is unavoidably long and the line-length-limit rule triggers on it anyway, and a comment-based exclusion must be defined. For example:

// revive:disable:line-length-limit To allow go generate command
//go:generate go run ../../../cmd/stackwrapper/main.go -output stack_wrapper.go -type Monetization -dir ../../thrift/monetization/service -output-type StackWrapper

//revive:enable

In this case, the go:generate command must remain on one line, and there is no way to wrap it to a second line. One proposal to do so was declined: golang/go#46050

Other examples may also exist: for example users may want to carve out exclusions for long URLs (i.e. lines that match https://).

While it is possible to carve out exclusions every time this happens such as in the code example above, it is cumbersome to do so.

Describe the solution you'd like
A similar standalone linter, the lll linter, offers an exclude parameter which excludes lines matching a regular expression. If the line-length-limit rule could offer a similar option to exclude lines based on a regular expression, then we could set it to exclude checking lines with a pattern like go:generate.

Describe alternatives you've considered
Issue #701 proposes a somewhat similar scheme of excluding rules based on whether the filename matches a regular expression. Rather than have a line exclusion specific to line-length-limit, we could allow excluding any rule based on whether the line matches a regular expression. This could be more generic if other rules could benefit from line-regexp-specific exclusions.

Additional context
None

@james-johnston-thumbtack
Copy link
Author

Upon further research, I found a way to do this using golangci-lint when revive is used by that lint aggregator:

issues:
  exclude-rules:
    - linters:
        - revive
      text: "line-length-limit"
      source: '^\s*//go:generate |https?://'

This will exclude all lines matching the regexp that were flagged by the line-length-limit rule.

Obviously, this won't help anyone who isn't using golangci-lint.

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

1 participant