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

Include/Exclude Files by Pattern #42

Open
mvrahden opened this issue Sep 1, 2023 · 7 comments
Open

Include/Exclude Files by Pattern #42

mvrahden opened this issue Sep 1, 2023 · 7 comments

Comments

@mvrahden
Copy link

mvrahden commented Sep 1, 2023

Simple Example

We want to prevent devs from using os.Setenv in Tests and use t.Setenv instead.
However, the usage of os.Setenv in source this could be a viable solution.
Therefore we'd like have a filename include matcher, to enable this forbidigo rule only on certain filepatterns, e.g. only on suffix _test\.go$.

Proposal

Add the option of a filename exclude/include pattern to the config, which helps to dismiss certain files from the rule-enforcement.

@mvrahden mvrahden changed the title Exclude Files by Pattern Include/Exclude Files by Pattern Sep 1, 2023
@ashanbrown
Copy link
Owner

@mvrahden Thanks for sharing that use case. Just to check, are you using this linter standalone or in the context of golangci-lint? Used standalone, the linter doesn't have too much control over exclusions. golangci-lint definitely has more flexible ways of excluding rules.

@mvrahden
Copy link
Author

mvrahden commented Sep 2, 2023

Hi @ashanbrown, we use it in the context of golangci-lint

@atom-andrew
Copy link

atom-andrew commented Sep 2, 2023

Does golangci-lint not allow you to control where your rules apply? Recently there were some updates to golangci-lint, so you could also both include and exclude a set of files.

@mvrahden
Copy link
Author

mvrahden commented Sep 2, 2023

Interesting, I wasn't aware of that change. I'll look into it

@jachym-tousek-keboola
Copy link

@atom-andrew I don't think that helps with forbidgo because using that approach you'd disable forbidgo completely for some files. However this feature is needed on a per-pattern bases. We do need some forbidgo patterns to be applied globally while others should be only applied only to specific files.

@ashanbrown
Copy link
Owner

Is excluding rules by text insufficient to handle these cases? The notes there say "Also, you can use issues.exclude-rules config option for per-path or per-linter configuration." Possibly you might need to annotate your rules (i.e. include some special string in them), so that you can easily find it to exclude.

Just to step back again, I'd definitely prefer to avoid building complex configuration logic forbidigo that can be handled by golang-ci (and shared with other linters). I suppose what is fairly different between forbidigo and other linters is that the rules are all user-defined. I'm not working actively in golang myself these days, but I'd be curious if there are other linters that have user-defined rules and how they handle these exclusions.

@mvrahden
Copy link
Author

Hi @ashanbrown, I can confirm that the exclude by path and by text option would work. Thanks for pointing it out

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

4 participants