-
Notifications
You must be signed in to change notification settings - Fork 30
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
Change to bespoke spotless import spec to something more typical #1048
Change to bespoke spotless import spec to something more typical #1048
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #1048 +/- ##
============================================
- Coverage 80.55% 80.52% -0.04%
+ Complexity 2736 2733 -3
============================================
Files 365 365
Lines 13614 13614
Branches 941 941
============================================
- Hits 10967 10962 -5
- Misses 2070 2071 +1
- Partials 577 581 +4
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
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 taking the time to look into these rules, a couple questions about the process to arrive at the ordering, but I'm not directly opposed to these changes.
So long as we've got a way to keep our files looking consistent across the project I think the specific rules choices are less of a concern.
@@ -7,7 +7,6 @@ | |||
import io.opentelemetry.api.common.AttributeKey; | |||
import io.opentelemetry.api.common.AttributesBuilder; | |||
import io.opentelemetry.api.trace.Span; |
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 would recommend that we keep line breaks between external dependencies and internal/java dependencies - the line breaks make it easier to identify if an import is 'ignorable' vs a new dependency or an unexpected dependency.
A quick note on where this preference is from - it makes it easier to review code, as opposed to a preference when writing.
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 agree. I think that's what the empty '' values were doing. I'd like to bring them in. I wasn't sure if that was getting in the way of static imports getting confused, so I was playing around.
I've never used spotless, so I'm hoping to get some help here.
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.
Please take a look at the new version - we have newline/block spaces between groups. spotlessApply with those configs has also DUPLICATED a number of imports. I'm confused at why spotless doesn't consider those duplicate or why it thinks they belong elsewhere. Any guidance would be appreciated?
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've created a PR [1] for spotless that address your duplicate import issue by ignoring duplicate entries, could you take a look?
@@ -62,10 +62,8 @@ subprojects { | |||
targetExclude '**/build/**', ".gradle/**" | |||
importOrder( |
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.
Fighting tools is super frustrating - trying to understand your workflow, are you manually placing imports, using auto-add or using the IntelliJ import organizer? If using the import organizer, there are tweaks [1] that can be pulled into it consistent with the existing rules, how does that impact your preference?
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 you take a look at the comments in the linked PR, you'll see a number of my concerns, that remain unaddressed. I'd like to figure something out to improve this. One issue is in getting IntelliJ to pickup configs by default, which that PR didn't address. Another way to skin that cat would be to use the default IntelliJ list, which is probably more universally adopted than the opensearch one or the one that the spotless rules use now & use that.
The only issue that I have at the moment is that I can't figure out how to get static imports to work well with spotless (they work find w/ IntelliJ).
build.gradle
Outdated
@@ -62,10 +62,8 @@ subprojects { | |||
targetExclude '**/build/**', ".gradle/**" | |||
importOrder( | |||
'java|javax', | |||
'io.opentelemetry|com.google|com.fasterxml|org.apache|org.hamcrest|org.junit', | |||
'org.opensearch', |
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'd like consistency when possible. I realize we are divergent from OpenSearch already, but they have a larger and more formal separations declared [1] in their rules. Other than alphabetical (the default ordering) is there a reason for one order vs another?
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 is the rule that I don't understand. Why are some 3rd party packages different than others? e.g. why are google imports going to be in a different block than netty ones? I'd like to see all of those together. That will scale much better over time and doesn't put us into an 'editorial' mode where we're categorizing third party packages.
I'd like to see built-in java imports in one block, optionally by preprocessor blocks (lombok), org.opensearch imports in another, everything else in another, static imports by themselves. Line breaks should be between each of those sections.
I don't think that larger lists are better - it actually means less order - e.g. why is carrotsearch before avast in the linked list? Package names are already naturally grouping when sorted alphabetically by virtue of them being fully-qualified.
The issue that I'm having is that I can't figure out how to even express that with spotless.
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.
you can use an empty string for all the imports you didn't specify explicitly
From https://github.com/diffplug/spotless/tree/main/plugin-gradle#java
I'm guessing using empty string twice is causing those imports to be duplicated when printing, try a single empty string before or after the java|javax
matches.
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 - I put a comment in the gradle file to point to that 'documentation'. It would be awesome for you to open a PR against that repo to improve the documentation. A comment in a code block that describes one behavior and no mention of the '#' doesn't give me warm-fuzzies.
I think that the '#' character is a special magical one that means static imports, but I can't find it documented. Signed-off-by: Greg Schohn <[email protected]>
0ba81b7
to
cdb1cb9
Compare
I think that the '#' character is a special magical one that means static imports, but I can't find it documented. Signed-off-by: Greg Schohn <[email protected]>
cdb1cb9
to
824287d
Compare
…migrations into SpotlessWackiness
That's what IntelliJ does by default. Signed-off-by: Greg Schohn <[email protected]>
Signed-off-by: Greg Schohn <[email protected]>
Signed-off-by: Greg Schohn <[email protected]>
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 the updated import order; I was also confused by the previous ordering but just endured it. This new ordering is much more normal. I appreciate the conversation around norms and standards across the OpenSeach Project, but I think that any external contributors who looked at the code in our repo would find the new ordering much more natural than the Project's "standard" ordering, if that's what we were using before. We can always reassess later if divergence from the "standard" causes problems, but for now it feels like the right path forward.
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.
Please undo the change to the .gitignore
- then looks good to me to merge.
@@ -8,7 +8,6 @@ __pycache__ | |||
*.egg-info* | |||
.python-version | |||
logs | |||
.vscode/ |
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.
Please leave this exclusion in place, vs code puts files in here for individual workspace configuration
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 can't do that and checkin a file for vscode's autoformatting rules. We had decided that for spotless changes - and spotless - to stay in our processes, that we'd sync changes w/ IDEs so that devs wouldn't have to fight the formatters. Is there another solution?
I would think that users would want to manage their own git ignores locally. Should a repo that doesn't use vscode for the solution to build need to ignore those directories globally (same argument for intelliJ and eclipse)?
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.
Git can still index files that are ignored, I've just moved all my settings from my local workspace to the machine wide configuration, I'll figure this out if it creates friction.
Description
Issues Resolved
No Jira
Is this a backport? If so, please add backport PR # and/or commits #
Testing
gradle & CICD
Check List
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.