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

Support for group of imports without blank lines between groups #1401

Merged

Conversation

murdos
Copy link
Contributor

@murdos murdos commented Nov 19, 2022

To keep compatibility with existing configuration, a special delimiter | is introduced to separate subgroup of imports inside a group. For example "java|javax" will not generate a blank line between the java group and the javax group.

The notion of ImportsGroup has been introduced for clarification, allowing a significant code simplification.

Fixes #1375

Example of usage: defining order as java|javax,org,comwill reorder imports as follow:
Before:

import org.dooda.Didoo;
import java.util.List;
import javax.inject.Inject;
import java.lang.Thread;
import javax.annotation.Nullable;

After:

import java.lang.Thread;
import java.util.List;
import javax.annotation.Nullable;
import javax.inject.Inject;

import org.dooda.Didoo;

To keep compatibility with existing configuration, a special delimiter `|` is introduced to separate subgroup of imports inside a group.
For example "java|javax" will not generate a blank line between the java group and the javax group.

The notion of ImportsGroup has been introduced for clarification, allowing code has been simplification.

Fixes diffplug#1375
@murdos murdos force-pushed the importorder-without-blanklines-between-groups branch from f4ebaad to 35a56ea Compare November 20, 2022 20:19
@nedtwigg nedtwigg merged commit c173aa7 into diffplug:main Nov 24, 2022
@murdos murdos deleted the importorder-without-blanklines-between-groups branch November 24, 2022 07:22
private final List<String> subGroups;

public ImportsGroup(String importOrder) {
this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR))
Copy link
Contributor

Choose a reason for hiding this comment

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

This line has a bug that only |\\# can be split as { "", "\\#" }, but \\#| will be split as { "\\#" } so configure static subgroup before catch all subgroup is impossible.

Copy link
Contributor

Choose a reason for hiding this comment

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

cc @murdos @nedtwigg

Also, it seems that the doc can be incorrect since the correct syntax is \# instead of \\#.

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR))
this.subGroups = Stream.of(importOrder.split("\\" + SUBGROUP_SEPARATOR, -1))

... can help.

@nedtwigg
Copy link
Member

Published in plugin-gradle 6.13.0 and plugin-maven 2.30.0.

benkard added a commit to benkard/mulkcms2 that referenced this pull request Apr 2, 2023
…1.0 (mulk/mulkcms2!12)

This MR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [com.diffplug.spotless:spotless-maven-plugin](https://github.com/diffplug/spotless) | build | minor | `2.30.0` -> `2.31.0` |

---

### Release Notes

<details>
<summary>diffplug/spotless</summary>

### [`v2.31.0`](https://github.com/diffplug/spotless/blob/HEAD/CHANGES.md#&#8203;2310---2022-11-24)

##### Added

-   `importOrder` now support groups of imports without blank lines ([#&#8203;1401](diffplug/spotless#1401))

##### Fixed

-   Don't treat `@Value` as a type annotation [#&#8203;1367](diffplug/spotless#1367)
-   Support `ktlint_disabled_rules` in `ktlint` 0.47.x [#&#8203;1378](diffplug/spotless#1378)
-   Share git repositories across projects when using ratchet ([#&#8203;1426](diffplug/spotless#1426))

##### Changes

-   Bump default `ktfmt` version to latest `0.40` -> `0.41` ([#&#8203;1340](diffplug/spotless#1340))
-   Bump default `scalafmt` version to latest `3.5.9` -> `3.6.1` ([#&#8203;1373](diffplug/spotless#1373))
-   Bump default `diktat` version to latest `1.2.3` -> `1.2.4.2` ([#&#8203;1393](diffplug/spotless#1393))
-   Bump default `palantir-java-format` version to latest `2.10` -> `2.28` ([#&#8203;1393](diffplug/spotless#1393))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever MR is behind base branch, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this MR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this MR, check this box

---

This MR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4yNC4wIiwidXBkYXRlZEluVmVyIjoiMzQuMjQuMCJ9-->
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.

ImportOrder without blank line between groups
3 participants