-
Notifications
You must be signed in to change notification settings - Fork 160
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
customImportOrder does not work #377
Comments
Looks like #372 change is already released in 5.16.3. But, the below configuration is not working in Intellij IDEA 2017.3.3
|
@appraveen Is there an error? What doesn't work? I just tested using the configuration you have provided and it seems alright. Imported correctly and I had no errors. I am on IntelliJ 2017.2.5 though, not sure if that matters. |
@appraveen Hmm this is what I got after importing and it's correct. Is your plugin updated to the latest version? Does the import layout table change at all after importing? |
@yeoji Same issue for 2017.3.4. Doesn't import counts to use "*" as well. Maybe something had changed in the API since 2017.2? |
@appraveen @e-tyryshkin You're right, I just upgraded to 2017.3.4 to test this out and it doesn't import properly! Hmm since the plugin is developed with 2016.1, I'm not too sure how to go about figuring out what has changed/fixing this. I'll try and see if I can find anything out though. |
This is a standard problem, I fear - sometime new versions can do odd things. But people tend to get a bit miffed if we follow the release, as a lot of large orgs don't or can't upgrade immediately. I'd try switching the version referenced in |
This should not be a problem. Looking at the Intellij Version 2017.2.5 to 2017.3.4, API seem to be broken between their If something works in 2017.2.5 i would expect it to work on all |
I am using the plugin version:
Here is an a snippet that demonstrates a CustomImportOrder check: <module name="CustomImportOrder">
<property name="severity" value="error"/>
<property name="customImportOrderRules"
value="SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE###STATIC"/>
<property name="specialImportsRegExp" value="^javax\."/>
<property name="standardPackageRegExp" value="^java\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="false"/>
</module> Full example available here Importing the configuration from Then, I changed the rule to the following, taking out <module name="CustomImportOrder">
<property name="customImportOrderRules"
value="SAME_PACKAGE(3)###THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE###STATIC"/>
<property name="specialImportsRegExp" value="^javax\."/>
<property name="standardPackageRegExp" value="^java\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="false"/>
</module> Second error presents itself complaining about missing enum constant for <module name="CustomImportOrder">
<property name="customImportOrderRules"
value="SAME_PACKAGE###THIRD_PARTY_PACKAGE###SPECIAL_IMPORTS###STANDARD_JAVA_PACKAGE###STATIC"/>
<property name="specialImportsRegExp" value="^javax\."/>
<property name="standardPackageRegExp" value="^java\."/>
<property name="sortImportsInGroupAlphabetically" value="true"/>
<property name="separateLineBetweenGroups" value="false"/>
</module> In summary and to confirm:
PS Happy to open up a separate issue, if it helps further. |
@mmoayyed thanks for the report. What version of Checkstyle are you using with this config? At first glance that exception seems to be coming from Checkstyle, not the plugin. In general the plugin just concerns itself with munging the file paths - most of the work, including the majority of parsing, is still done by the underlying Checkstyle instance. |
Apologies. I should have mentioned that I use Checkstyle It's worth noting that with the original |
@mmoayyed thanks - and another thank you for your excellent bug report, it's much appreciated! The good news: I can reproduce it. The file works fine for addition & scanning, but fails when imported as a code style. The bad news: the code style work was a contribution, so it's a bit of a mystery. But I'll see what I can dig up 😄 |
I've added some fixes - |
Outstanding. Thank you very much for your time. I'll give the new release a try and will report back. |
I should report back the latest version of the plugin that is 5.21.0 resolves this issue. Once again, thank you very much for your help. I hope to get better at this gradually and start contributing more :) |
I'm seeing a similar issue with 5.22.1:
So the checkstyle.xml is saying static first, but the Import Layout section of the Code Style after importing (with no errors reported) is still showing the default IntelliJ order (statics last and separate java & javax sections). The Checkstyle plugin is configured with the right version (8.12). Taking another look - i did find that you need to make sure the Scheme selected in the Code Style -> Java preferences is set to Project (and not anything related to the IDE) - in which case it half gets the Import Layout right (the java & javax sections are the issue now, they shouldn't be present): |
This is still an issue in 5.54.0. Here's a snippet of the imports section I was using
I found a workaround:
|
This is still an issue in 2021 (5.55.1).
The huge downside is that once you edit the checkstyle again you have to edit the order again. |
Thank you @mqzry for the feature. There is a bug from the pull #363 which prevents customImportOrder to work properly.
Using
value.split("###")
might fix the issue. [Spec].(http://checkstyle.sourceforge.net/apidocs/com/puppycrawl/tools/checkstyle/checks/imports/CustomImportOrderCheck.html)The text was updated successfully, but these errors were encountered: