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
Support lint for sub-package usage #2
Conversation
The given NOT to import package will be linted not only for itself, but also for its sub-packages. The lint message will also reflect this. A potential counterpart change would be to merge the input argument and merge them if they has root-sub relationship. Or we should allow user to pass in two paths, e.g. *a=x* and *a/b=y*, and lint the import path of *a/b* using the second hint (i.e. use suggestion of *y*), this allows package author to split a mono package into several independent packages.
faillint/faillint.go
Outdated
@@ -52,15 +52,30 @@ func run(pass *analysis.Pass) (interface{}, error) { | |||
|
|||
for _, file := range pass.Files { | |||
for _, path := range imports { | |||
imp := usesImport(file, path) | |||
imp, exact := usesImport(file, path) |
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'm not sure about the "exact" word here. What do you think about "fullMatch" or "exactMatch" ? Or you reverse it and return the "subMatch" (or "subPath"). Then below you could say if subMatch { ... }
which I think is easier to read and reason than if !exact { ... }
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.
Thank you for the comment, I agree!
This is now fixed with the change here: #14 I'm sorry that we couldn't get this in, but we had my changes so we had to implement it in a different way. I appreciate your work and let me know if you see any problems. |
The given NOT to import package will be linted not only for itself, but also for its sub-packages. The lint message will also reflect this.
Additionally we should allow user to pass in root package path and sub package path and prefer the exact matching path if any. E.g. when pass in a=x and a/b=y, then we should lint the import path of a/b using the a/b=y suggestion (instead of a=x), this allows package author to split a mono package into several independent packages.
Another potential issue is that user might passing, e.g., a, a/b, and the code actually only import a/b/c. For now I didn't considered this case yet since I want to see whether I'm in the correct direction first, before diving into too detail.