-
Notifications
You must be signed in to change notification settings - Fork 18
Compile allow and deny list as globs to allow wildcards #67
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
base: v2
Are you sure you want to change the base?
Conversation
philwitty
commented
Oct 5, 2023
- as the glob special characters are not valid package names this should not cause compile errors for any matches of existing modules
bd6660c to
1af7692
Compare
* as the glob special characters are not valid package names this should not cause compile errors for any matches of existing modules
1af7692 to
6199f61
Compare
dixonwille
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am contemplating if this matters. But there was a performance benefit to only allowing prefixing instead of globs. Globs require to go through the array from the start to the end (the sorting that was done is no longer needed and maybe not expected).
Doing string comparison in comparison is cheaper and I can do a binary search (sort.Search) requiring potentially even fewer comparisons against what could be pretty lengthy slice (think mono repository with many packages).
There are significantly fewer files than imports so was willing to take the hit of globs there. Plus, globing against a well structured package (one controlled by the maintainers of the linter configuration) makes logical sense. But not every go project is built the same. So globing at package level seemed a bit like false security (don't include any package with the name test?). Prefixing made the most sense as I may not trust X organization and I can just exclude it with a prefix...
| t.Run(c.name, func(t *testing.T) { | ||
| set, err := c.configurator.parse(c.inputFile) | ||
| if err != nil { | ||
| t.Fatalf("file is not a valid json file: %s", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
File may not be json.
| if err != nil { | ||
| errs = append(errs, err) | ||
| } | ||
| sort.Strings(l.Allow) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This modifies the input slice which can be unexpected behavior to the consumer (if there are any). That is why I had it copied to an internal slice before sort.
Really good points, we certainly could optimise the globbing if performance is an issue (i.e. using a custom globber which given the well defined package names that sounds reasonable), as there isn't any cleverness in the current matching this shouldn't be a noticeable performance decrease I think. Not sure I understand your second point about the use, I should have made my use case clear in the PR, we wanted to have a shared linter config across many repos but ensure none of them were using any |
|
This makes sense for a use case I have, where I want to enforce dependency rules in a layered application implementing Clean Architecture: One such rule might say:
prefix-only matching would force us to update the config for any new context we add to the application, whereas with package globs this would be simple: prevent_app_deps_adapters:
files:
- <my-repo>/contexts/**/internal/app/**/*.go
deny:
- pkg: <my-repo>/contexts/**/internal/adapters
desc: Application layer can't depend on adapters |