-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
IllegalImport with class pattern fails on static import #13772
Comments
Link to check documentation: https://checkstyle.sourceforge.io/checks/imports/illegalimport.html#IllegalImport |
I am on it |
I am removing 'approved' label, since this seems like the expected check behavior. From https://checkstyle.sourceforge.io/checks/imports/illegalimport.html#IllegalImport:
This import equals the given class name: Checkstyle is not type aware, and operates on one file at a time. It has no idea if
Imports are treated the same. @Bananeweizen you might want to try the following config to achieve the check behavior that you expected in the issue description:
|
confusion point is fact that we did not explain in doc how we match. We are not type aware, yes, but it is same for packages. Example for illegalPkgs that affects
I do believe we just need to relax equals to be checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheck.java Line 238 in c525c67
There is always posibility to have inner class for illegal import I still believe issue should be approved, but implementation (of referenced PR) should different and we should expand documentation. |
As you pointed, we are not type aware, so we simply match string. And we have this two options just convenience for users to define what they want. Ideally there should be should be single property |
They are not the same, just similar. Package assumes it is not a complete match. Class assumes it is a complete match. Package has some logic to basically check if a period comes after the user supplied text.
2 properties. 1 of what text to match, and the other to specify if it is regexp or not. I would still think some users would want to possibly differentiate between static and non-static imports, which may be another option. ============= A static import is always guaranteed to be It seems to me we either need to fully clarify documentation and live with the check as it is, or change it and break compatibility. |
Let's not break compatibility. I still see that user assumption that
Will violate: Is valid assumption. So we just need to update implementation to handle it. We trust user in config and he say that
|
@Bananeweizen please share your opinion |
@rnveach , please share your opinion on relying on user input, we such strategy in other Checks. |
I don't understand what you want my opinion on. I gave a opinion at #13772 (comment) . |
do you propose ?
|
|
we have 3 properties
So it is reasonable to have it, redoing whole Check, 2 property deplrecation, for such small update is not very reasoable to my mind. |
Then why did #13772 (comment) mention property |
I tried to understand you and wrote a bit more exact proposal to guess what you mean in case you have no time to write more extended, but you can do brief responses like yes/no. What I see is we can not agree on how to fix it, so issue stays unapproved, may be in future someone change his mind Meanwhile users need to use workaround with usage of |
You can approve issue for how you want to do it. I was asked for my opinion and with no clear understanding of on what, I kept pointing to my post that had my opinion. If we don't want to break compatibility, then we should update documentation for users. Since changing the property type is breaking, and I don't see adding another property will make things clearer, I can only see right now documentation change. |
While updating the documentation might be one way out of this, I'd expect more users to either not read those details or to not recognize the consequences for static imports, thereby having their configuration work for some, but not all cases. I personally also realized this only after several years of active use. You as the developers of the tool have a very precise mental model of what's happening. Users have a totally different and way more simple mental model of the same thing. Therefore if this gets fixed with documentation only, it should have at least a complete example of how to match both static and non static imports. Regarding an actual fix via code: Can't we use a rule of thumb, that good Java developers use uppercase class names and lowercase method names? Therefore I would remove all segments from an import, that start with a lowercase character, and are behind the last segment starting with an uppercase character. And I would use this "normalized" import with the same code as before. That way the import "org.junit.jupiter.api.Assertions.fail" would be normalized to "org.junit.jupiter.api.Assertions", and that would then fit again to the current implementation, right? |
we do not need to do this. |
https://checkstyle.sourceforge.io/checks/imports/illegalimport.html#IllegalImport
IllegalImport
with propertyillegalClasses
configured doesn't detect illegal static imports, because it just does a text comparison of the import statement (which contains the method names for static imports):checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/imports/IllegalImportCheck.java
Line 245 in c525c67
Both files should report the same issue.
Causes checkstyle/eclipse-cs#523
The text was updated successfully, but these errors were encountered: