-
Notifications
You must be signed in to change notification settings - Fork 4.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
[Feature][Style] Enable spotless to manage imports #11458
Conversation
style/eclipse.importorder
Outdated
0=java | ||
1=javax | ||
2=org | ||
3=com |
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.
FYI, we could not have an empty line at the end of this file because it would cause Spotless
to fail to parse the imports management
rules.
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.
If we hope to manage the import order, it's better to use the origin order
org.apache.dolphinscheduler,org.apache,java,javax,org,com
otherwise, the default order is still ok.
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.
If we hope to manage the import order, it's better to use the origin order
org.apache.dolphinscheduler,org.apache,java,javax,org,com
otherwise, the default order is still ok.
Sure, I will give a try. If not work, will recover it.
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.
@ruanwenjun Updated. It works well.
Kudos, SonarCloud Quality Gate passed! |
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.
LGTM
<importOrder> | ||
<file>style/eclipse.importorder</file> | ||
</importOrder> | ||
<replaceRegex> |
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 removes the star import. But will it instead replaces the star import with the used specific class import? If not, this will cause compiling failed. Can you change a class with this example?
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.
@kezhenxu94 diffplug/spotless#649 (comment) It is hardly possible for Spotless
to replace with wildcards
with specific imports
, thus this is some kind of workaround actually. To prevent developers from pushing the commits without knowing that wildcards
has been removed by their pre-commit hook, one possible solution is to add a message in pre-commit hook to inform them of this behavior. WDYT?
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.
@kezhenxu94 FYI, I also added a comment in the origin issue to seek help to see if there is some good practice to handle wildcard imports
with Spotless
: diffplug/spotless#649 (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.
@kezhenxu94 FYI, I also added a comment in the origin issue to seek help to see if there is some good practice to handle
wildcard imports
withSpotless
: diffplug/spotless#649 (comment)
Wow. The issue has been 2 years...
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 removes the star import. But will it instead replaces the star import with the used specific class import? If not, this will cause compiling failed. Can you change a class with this example?
@kezhenxu94 Just a follow-up, as I've tested it locally, if we use mvn spotless:check
instead of mvn spotless:apply
, it only blocks the wildcard imports
without removing them. To improve, we could change the pre-commit hook from mvn spotless:apply
to mvn spotless:check
and add an output message to inform contributors that they should remove wildcard imports
. WDYT?
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 removes the star import. But will it instead replaces the star import with the used specific class import? If not, this will cause compiling failed. Can you change a class with this example?
@kezhenxu94 Just a follow-up, as I've tested it locally, if we use
mvn spotless:check
instead ofmvn spotless:apply
, it only blocks thewildcard imports
without removing them. To improve, we could change the pre-commit hook frommvn spotless:apply
tomvn spotless:check
and add an output message to inform contributors that they should removewildcard imports
. WDYT?
Can you identify the failure of spotless:check
is because of wildcard imports
or other code style issues?
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.
@kezhenxu94 Yes, I just double-checked it. To reproduce, you might change
Lines 33 to 35 in 68316f6
import java.util.HashMap; | |
import java.util.List; | |
import java.util.Map; |
import java.util.*;
and run mvn spotless:check
.
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.
@kezhenxu94 Yes, I just double-checked it. To reproduce, you might change
Lines 33 to 35 in 68316f6
import java.util.HashMap; import java.util.List; import java.util.Map; to
import java.util.*;
and runmvn spotless:check
.
How can yo tell the spotless:check
failure is because of wildcard import, if I have other code style issues and no wildcard import?
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.
@kezhenxu94 Yes, I just double-checked it. To reproduce, you might change
Lines 33 to 35 in 68316f6
import java.util.HashMap; import java.util.List; import java.util.Map; to
import java.util.*;
and runmvn spotless:check
.How can yo tell the
spotless:check
failure is because of wildcard import, if I have other code style issues and no wildcard import?
Good question, since each rule has its name, I think there might be a way to configure Spotless
to explicitly tell which rule the code fails. I will take a look and see if there is a way to do so.
Purpose of the pull request
imports
.Brief change log
Spotless
to remove unusedimports
.Spotless
to sortimports
in better order (instead of simply sorting import alphabetically).Spotless
to remove wildcards imports.Spotless
to remove empty line indents inpom.xml
.ZeppelinTask.java
as an example.Verify this pull request