Skip to content
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

Apply consistent import ordering with spotless #1811

Merged
merged 1 commit into from
Oct 31, 2019
Merged

Conversation

TimvdLippe
Copy link
Contributor

Spotless allows us to enforce a consistent import order. Configure it
such that static imports are first and non-static imports afterwards.
Within imports, java imports first, then javax, then all others.

This is consistent with the existing CONTRIBUTING.md guidelines, apart
from the fact that static imports are first. (File has been updated). I
would propose that makes more sense, but happy to discuss.

In any case, spotless already found inconsistent ordering within imports
themselves, so that is already providing value for consistency.

I have also updated the CONTRIBUTING guidelines to explain how
./gradlew spotlessApply will fix a lot of issues without the
developer having to worry about it. That should hopefully help newcomers
make changes more confidently.

(The only 2 files that are interesting to you are the build.gradle and
.github/CONTRIBUTING.md. All other file changes were automatically
performed after running ./gradlew spotlessApply locally.)

@codecov-io
Copy link

codecov-io commented Oct 25, 2019

Codecov Report

Merging #1811 into release/3.x will increase coverage by <.01%.
The diff coverage is n/a.

Impacted file tree graph

@@                Coverage Diff                @@
##             release/3.x    #1811      +/-   ##
=================================================
+ Coverage          86.76%   86.76%   +<.01%     
- Complexity          2490     2494       +4     
=================================================
  Files                311      311              
  Lines               6542     6552      +10     
  Branches             821      821              
=================================================
+ Hits                5676     5685       +9     
  Misses               670      670              
- Partials             196      197       +1
Impacted Files Coverage Δ Complexity Δ
...to/internal/handler/InvocationNotifierHandler.java 100% <ø> (ø) 8 <0> (ø) ⬇️
...n/java/org/mockito/runners/MockitoJUnitRunner.java 0% <ø> (ø) 0 <0> (ø) ⬇️
...l/creation/bytebuddy/InlineByteBuddyMockMaker.java 68.75% <ø> (ø) 14 <0> (ø) ⬇️
...g/mockito/internal/util/DefaultMockingDetails.java 100% <ø> (ø) 14 <0> (ø) ⬇️
...guration/injection/scanner/InjectMocksScanner.java 100% <ø> (ø) 8 <0> (ø) ⬇️
...kito/internal/framework/DefaultMockitoSession.java 96.15% <ø> (ø) 6 <0> (ø) ⬇️
...ockito/internal/invocation/SerializableMethod.java 48.07% <ø> (ø) 12 <0> (ø) ⬇️
...va/org/mockito/internal/junit/UnusedStubbings.java 76% <ø> (ø) 8 <0> (ø) ⬇️
...o/internal/junit/UnnecessaryStubbingsReporter.java 100% <ø> (ø) 4 <0> (ø) ⬇️
...mockito/internal/invocation/UnusedStubsFinder.java 0% <ø> (ø) 0 <0> (ø) ⬇️
... and 152 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec99f17...594160e. Read the comment docs.

Copy link
Member

@mockitoguy mockitoguy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely! Thank you.

Comment on lines +97 to +103
1. `import static java.*`
1. `import static javax.*`
1. `import static all other imports`
1. blank line
1. `import java.*`
2. `import javax.*`
3. `import all other imports`
4. blank line
5. `import static java.*`
6. `import static javax.*`
7. `import static all other imports`
1. `import javax.*`
1. `import all other imports`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should also leverage IntelliJ IDEA's .editorconfig extensions for that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that should help as well 😄

Copy link
Contributor

@bric3 bric3 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent !!!

Spotless allows us to enforce a consistent import order. Configure it
such that static imports are first and non-static imports afterwards.
Within imports, java imports first, then javax, then all others.

This is consistent with the existing CONTRIBUTING.md guidelines, apart
from the fact that static imports are first. (File has been updated). I
would propose that makes more sense, but happy to discuss.

In any case, spotless already found inconsistent ordering within imports
themselves, so that is already providing value for consistency.

I have also updated the CONTRIBUTING guidelines to explain how
`./gradlew spotlessApply` will fix a lot of issues without the
developer having to worry about it. That should hopefully help newcomers
make changes more confidently.

(The only 2 files that are interesting to you are the `build.gradle` and
`.github/CONTRIBUTING.md`. All other file changes were automatically
performed after running `./gradlew spotlessApply` locally.)
@TimvdLippe TimvdLippe merged commit fc1fc31 into release/3.x Oct 31, 2019
@TimvdLippe TimvdLippe deleted the import-order branch October 31, 2019 15:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants