-
Notifications
You must be signed in to change notification settings - Fork 302
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
Development
: Modify the IntelliJ editor configuration to discourage star imports
#7974
Conversation
b964791
to
d31a0bd
Compare
Development
: use .editorconfig to clean importsDevelopment
: expand .editorconfig
d31a0bd
to
b4ea143
Compare
b4ea143
to
38fc94a
Compare
WalkthroughThe updates bring about stricter coding standards and formatting rules project-wide. Key changes include implementing a maximum line length and standardizing tab width. Moreover, adjustments to configurations for Java and Python files ensure consistent formatting. Newly added Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configration File (
|
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.
Thanks for handling the issue
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.
The amount of changes in this file is simply way too big to properly review them. I found at least one instance where it is not in line with our existing Spotless settings. For changes like this we would have to make sure that they are 100% in line with our other linter settings that we use. For this we would have to painstakingly go through each setting and compare them with Spotless (and possibly other linters)
There are several other existing differences between IntelliJ default settings and our Linter settings that I am aware of that likely are also included in the changes here. (e.g. double vs. single quotes in JS code is a common thing).
I think our priority should not be to enforce the default IntelliJ settings in our editorconfig, but to enforce our custom linter rules that differ from the default IntelliJ settings.
It is important to remember that the editorconfig is used when you reformat or generate code in IntelliJ. Our linters run as a pre-commit hook and would then complain about or revert differences.
.editorconfig
Outdated
ij_java_catch_on_new_line = false | ||
ij_java_class_annotation_wrap = split_into_lines | ||
ij_java_class_brace_style = end_of_line | ||
ij_java_class_count_to_use_import_on_demand = 100 |
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 should ideally be included in Spotless if possible. A quick search suggests that this should be possible.
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 couldn't quickly find anything that suggests that spotless could do that, I think spotless only looks at one file at a time and does not know which classes of the package are actually used.
Hi @Hialus,
What would you say if I revert all of the lines apart from the increased star import limit (as established in the last meeting, we want to eliminate the magic number of 4, my original intention with this PR) and thus hopefully make Teamscale helpful? What do you think? |
I am also not fully aware of all the different linters and formatters we use, which is a big reason why I am against such massive changes. Ensuring that these changes are all coordinated is sadly everything but trivial.
I know. This was an example of another difference between IntelliJ's default and our custom rules. This would be a case that should be handled in the editorconfig file (instead of e.g. defining the suffix for auto generated subclasses)
We also can't just throw away all of our existing rules. In the last meeting we merely discussed changing the star import rule, not completely redoing our linter/formatter rules.
That would be fine, as that is what we already agreed upon. Though again I think it would be great if this could also be put into our spotless config (as well as other linters if possible). Ideally our own server code style GitHub run would fail if we add new star imports, so that we do not rely on Teamscale for this. |
1cda331
to
acd95ce
Compare
acd95ce
to
6857de5
Compare
@Hialus, I removed everything except the changes to the usage of star imports. I also aligned the import order specified by Spotless. Now, if you optimize the imports using IntelliJ, it will expand them and remove the lines between the groups (didn't find anything for that). Spotless will validate the imports and readd the blank lines in between. I also couldn't find a setting for Spotless to replace star imports, but I guess with this setting, our code should produce fewer false positives. |
I'm not sure if I understood the changes / goals right. My current understanding is the following: The goal of this PR is to change our approach to star imports in order to get rid of teamscale and coderabbit warnings. This means that if I change a file with star imports in one of my PRs, nothing will happen for now, and no tool will complain. The star imports will only get removed when using the "optimize imports" feature of IntelliJ. At least in my workflow, the IntelliJ formatter does not play a role. If I want to reformat the code, I quickly execute spotless. This means that in this form this change will create an inconsistent code style, depending on the current workflow of the developer. I'd like to avoid this. Please check if you can enforce star import rules via spotless. Then violations will be automatically corrected in the pre-commit-hook and would lead to a failure in the Regarding the PR size: If the configuration change is small (e.g. only one changed rule), I'm ok with bigger PRs (considering LOC) which enures a consistent code base. But I also agree with Timor, we should touch only 1-2 rules in such PRs to keep them reviewable. My sugesstion would be to
This in combination with the editorconfig changes should not lead to failures when regularly working with the code, but will throw an error if a developer explicitly adds a star import, maintaining consistency across the code base. References:
|
Hi @Strohgelaender, sorry I didn't reply earlier. You're right. My goal/idea is to gradually phase out star imports as they keep causing false positives and leading to a complete neglect of real findings. As I couldn't find a way to use Spotless only for changed files of a commit, I would rather merge these changes that prevent new ones and after some time, apply the config for all files that are left. This would decrease the potential merge conflicts and developer time for those changes. I agree that this results in a temporarily inconsistent code styling, but after all, it's just imports |
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.
As discussied I'm ok with this approach. In a few months we should open another PR making the star import usage consistent and also implement the custom rule mentioned 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.
Nice, looks good 🚀
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.
code lgtm
Development
: expand .editorconfigDevelopment
: Modify the IntelliJ editor configuration to discourage star imports
Checklist
General
Motivation and Context
We have multiple code scanning tools that complain about our usage of star imports or other formatting issues, making it hard to spot any real findings that should be taken care of.
Description
I exported the default editor configuration of Intellij and removed everything I could see that did not make sense for us. The only values that I changed is the usage of star imports to 1000 to prevent teamscale findings and coderabbit comments.
I do not intend to tell you how to format your code, I'd very much like this editor config to be a living document and be changeable by all. After all its just formatting and easily changeable.
Review Progress
Code Review
Summary by CodeRabbit
.editorconfig
to improve code formatting standards, including line length and tab width adjustments..editorconfig
settings for Liquibase changelog files to prevent reformatting issues..editorconfig
in the test resources to address potential formatting-related test failures.