-
Notifications
You must be signed in to change notification settings - Fork 14.2k
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
KAFKA-12572: Add import ordering checkstyle rule and configure an automatic formatter #10428
Conversation
I think @ijuma would be the best reviewer for the new gradle configuration introduced here. @hachikuji @mjsax @ableegoldman @cadonna Could you have a look? The automatic formatter formatted |
424bae7
to
3e5b6c3
Compare
af84b33
to
b8257b6
Compare
@cadonna Hi Bruno, Congratulations on becoming a committer. Could you have a look? 🙇 |
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.
@dongjinleekr Thank you for your perseverance with this!
I did a first pass. Here is my feedback.
b8257b6
to
39a0257
Compare
Hi @cadonna, Thanks again for your detailed review. Here is the update. Following your suggestions, I tried some other configurations. First of all, there is no way to use automatic import ordering only - without any configuration, the formatter formats the code with its default configuration. So, we have to find the least-effecting configuration. The major differences between the last draft are like the following:
But, I kept the other rules, like:
Please have a look when you are free. Thanks again for the review! +1. It would be better to check how the new configuration formats streams module. I tested with that module, for it has so many |
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.
@dongjinleekr Thank you for the updates!
I left some comments. The comments about readability are quite subjective. Would be interesting to hear other opinions.
I would try to minimize changes of line breaks by the formatter, because I think most of the people add line breaks to make the code more readable. I have the impression that adding and removing line breaks is something that is hard to automate because it is often a case by case decision.
An exception to that are line breaks in method calls and method definitions. I think having a formatter rule for that would be great.
39a0257
to
4865c11
Compare
Hi @cadonna, Here is the fix.
+1. in |
4865c11
to
a9e9a34
Compare
Rebased onto the latest trunk. @cadonna Could wou have a look now? 😃 |
a9e9a34
to
cafbd9e
Compare
Rebased onto the latest trunk. cc/ @cadonna |
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.
@dongjinleekr Thank you for the update!
I had just some minor comments.
LGTM!
But I think also somebody that contributed to the core module should look at this PR. @ijuma @hachikuji @cmccabe @rajinisivaram @omkreddy @dajac
@cadonna I greatly appreciate your detailed review. Here is the update! 😄 |
Shameless plug and related to CheckStyle: ⏩ #10698 (needs a review / approval). |
4d20bb3
to
e179f92
Compare
@cadonna Here it is, with the following: 1. making server-common to ignore import orders. 2. rebasing onto the latest trunk. +1. It seems like we can make the eclipse formatter do not insert a newline at the end of the class, but not removing it. (see here.) So I reformatted the |
throw new UnsupportedOperationException(); | ||
} | ||
|
||
@Override | ||
public CompletableFuture<Map<ConfigResource, ApiError>> legacyAlterConfigs( | ||
Map<ConfigResource, Map<String, String>> newConfigs, boolean validateOnly) { | ||
Map<ConfigResource, Map<String, String>> newConfigs, boolean validateOnly) { |
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.
One question here. If you put the parameters of this method on the same line as the method name and you run again the formatter, will the parameters stay on the same line as the method name?
What would happen if you put the first parameter on the same line as the method name and then put each of the remaining parameters on its line own line?
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.
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 do not know what you exactly mean with "broken", but that is the behavior I hoped for.
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.
Okay. I will fix it with the second approach.
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.
Could you put the first parameter in the same line as the method name and put the remaining parameters on their own line as I proposed? Could you do the same for incrementalAlterConfigs()
?
If anybody does not like this style, we can still delete
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="18"/>
<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="18"/>
from the formatter configuration, right?
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.
After that, I think, we can merge. Besides the import order changes, you kept the just a few formatting style changes, which I think is good. If somebody does not agree, we can make it even less invasive.
@cadonna Here it is. Rebased onto the latest trunk + manually formatted |
c250545
to
b970d54
Compare
@cadonna Here is the update. I excluded the
As soon as this PR is merged, I start the issues above. |
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.
@dongjinleekr Thank you for the updates and your patience!
I a few comments and I think you need to update the PR description.
b970d54
to
a98f1fb
Compare
@cadonna Here it is. Rebased onto the latest trunk and removed the formatting section from |
a98f1fb
to
cb67573
Compare
Rebased onto the latest trunk. cc/ @cadonna |
1. Define an Java import order: kafka, org.apache.kafka, com, net, org, java, javax, (static imports). 2. Add eclipse formatter and configure automatic code formatting. 3. Suppress import order check for all modules. 4. Separate raft module configurations in suppression.xml. 5. Add storage module configurations in suppression.xml. Define an Java import order and configure automatic code formatting (2) Make server-common's import ordering off
…Bracing related formatting rules. 3. Comment is not a target of the formatting anymore. 4. Wrap after assignment operator.
…ormatting with 200 characters. 3. Add trogdor to suppressions.xml (Trogdor is separated from tools in fc405d7)
…se.jdt.core.formatter.indent_empty_lines'. 2. Add 'org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default' entry. (i.e., No space between switch statement's default case and colon.) 3. Remove 'org.eclipse.jdt.core.formatter.blank_lines_after_last_class_body_declaration' entry. (i.e., No blank line at the end of the class.)
…existing blank lines but just not adding ones.)
cb67573
to
f7865fb
Compare
Rebased onto the latest trunk. Also, I reflected the recent project structure change (i.e., |
@dongjinleekr Do you have free time to fix the conflicts? I'd like to review it! |
This was done in 342e691, closing |
This PR is a part of KAFKA-10787 umbrella task, replacing the previous implementation here. In short, this PR provides automatic import ordering and checking configurations, which will be a foundation of actual code formatting tasks later. Here are some backgrounds.
When I first started KAFKA-10787, I thought it is a trivial one and can be resolved with only one PR. But it is entirely wrong.
For the reasons above, it is almost impossible to resolve this issue with one commit or PR.
So, I restarted this feature from scratch. First of all, I changed the approach like following:
This approach has the advantages like:
With this scheme, we can expand the scope of auto-formatting and checkstyle incrementally.
In turn, I converted KAFKA-10787 into an umbrella one. As the first subtask, this PR do the following:
kafka
,org.apache.kafka
,com
,net
,org
,java
,javax
and static imports. It is identical to what we discussed in the dev mailing list, except each package is grouped independely. (e.g.,kafka
andorg.apache.kafka
are regarded as independent groups.)ImportOrder
rule for the newly introduced import ordering rule.Here are some reasons for the decisions I made:
Why choose eclipse formatter?
As all of you know, Apache Kafka is using gradle as its build tool. To automatically apply the import ordering rule with gradle, we have to use spotless, which supports two formatters - google formatter and eclipse formatter.
If we choose google formatter, it changes not only import ordering but also the other aspects of code, like an indentation. To minimize non-import ordering modifications, I choose eclipse formatter, which supports a custom formatter configuration.
As you can see here, the formatter defines a minimal rules for out code only.
The original proposal consists of 3 groups:
kafka
/org.apache.kafka
,com
/org
/net
,java
/javax
, and static imports. Why are those packages separated into independent groups?It's simple - the spotless automatic formatter doesn't allow packages with different prefixes into one group. So I separated them.
* Updated (June 10th 2021): The
core
module is excluded from the PR, and it now only focuses on providing auto-formatting configurations.Committer Checklist (excluded from commit message)