-
- Notifications
You must be signed in to change notification settings - Fork 1.5k
rules: support inverted path match #3617
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
Conversation
| Hello,
|
Let's brainstorm, perhaps we can come up with something better.
cc @ashanbrown |
|
|
c05858e to a3643ad Compare | Thinking a bit more about this, |
| I'm fine with Regarding |
| Semantically, all of the conditions are AND and there's no implied ordering. That more complex conditions get checked after others is merely an implementation detail. |
| My only reason for suggesting |
| I suspect that it is already possible to keep such separate cases also separated in the YAML with different |
|
|
cc5e128 to bb208bd Compare | Renamed to |
6e5a8fe to 9fc78a6 Compare It is not possible to use `exclude-rules: path` to exclude issues for non-test files because it is impossible to write a regexp that reliably matches those (golangci#2440). The new `path-except` check solves that by inverting the meaning: it excludes if the pattern does not match. Besides test files, this is also useful for large code bases where some specific code paths have additional constraints. For example, in Kubernetes the usage of certain functions is forbidden in test/e2e/framework but okay elsewhere. Without `path-except`, a regular expression that carefully matches all other paths has to be used, which is very cumbersome: - path: ^(api|cluster|cmd|hack|pkg|plugin|staging|test/(cmd|conformance|e2e/(apimachinery|apps|architecture|auth|autoscaling|chaosmonkey|cloud|common|dra|instrumentation|kubectl|lifecycle|network|node|perftype|reporters|scheduling|storage|testing-manifests|upgrades|windows)|e2e_kubeadm|e2e_node|fixtures|fuzz|images|instrumentation|integration|kubemark|list|soak|typecheck|utils)|third_party|vendor)/ msg: "E2E framework:" linters: - forbidigo With path-except, this becomes much simpler: - path-except: ^test/e2e/framework/ msg: "E2E framework:" linters: - forbidigo
| Sorry for the delay, I will handle the PR very soon. |
It is not possible to use
exclude-rules: pathto exclude issues for non-test files because it is impossible to write a regexp that reliably matches those (#2440). The newnot-pathcheck solves that by inverting the meaning: it excludes if the pattern does not match.Besides test files, this is also useful for large code bases where some specific code paths have additional constraints. For example, in Kubernetes the usage of certain functions is forbidden in test/e2e/framework but okay elsewhere. Without
not-pathpath-except, a regular expression that carefully matches all other paths has to be used, which is very cumbersome:With
path-except, this becomes much simpler:Fixes: #2440