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

[Maintenance] Add spotless options #152

Open
2 tasks done
devtobi opened this issue Aug 2, 2024 · 3 comments
Open
2 tasks done

[Maintenance] Add spotless options #152

devtobi opened this issue Aug 2, 2024 · 3 comments
Labels
Priority: High The issue contains work with high priority. Template: Backend Issues regarding the backend template. Template: EAI Issues regarding the eai template. Type: Maintenance The issue contains maintenance work.

Comments

@devtobi
Copy link
Member

devtobi commented Aug 2, 2024

Relevant template

refarch-backend, refarch-eai

Problem description (optional)

Spotless has capabilities currently not used (import sorting, removing unused imports and so on)

Desired solution

Add the options

<importOrder/>
<removeUnusedImports />
<formatAnnotations />

I took a look at the currently used https://github.com/it-at-m/itm-java-codeformat/blob/main/formatter/src/main/resources/itm-java-codeformat/java_codestyle_formatter.xml.
Those options are not available there.

Alternatively to the standard import order mentioned above, we could think about a custom import order. An example:

<importOrder>  <!-- or a custom ordering -->
  <wildcardsLast>false</wildcardsLast> <!-- Optional, default false. Sort wildcard import after specific imports -->
  <order>java|javax,org,com,com.diffplug,,\#com.diffplug,\#</order>  <!-- or use <file>${project.basedir}/eclipse.importorder</file> -->
  <!-- you can use an empty string for all the imports you didn't specify explicitly, '|' to join group without blank line, and '\#` prefix for static imports. -->
  <semanticSort>false</semanticSort> <!-- Optional, default false. Sort by package, then class, then member (for static imports). Splitting is based on common conventions (packages are lower case, classes start with upper case). Use <treatAsPackage> and <treatAsClass> for exceptions. -->
  <treatAsPackage> <!-- Packages starting with upper case letters. -->
    <package>com.example.MyPackage</package>
  </treatAsPackage>
  <treatAsClass> <!-- Classes starting with lower case letters. -->
    <class>com.example.myClass</class>
  </treatAsClass>
</importOrder>

Considered alternatives (optional)

No response

Additional context (optional)

No response

No duplicate

  • I confirm that this issue is not a duplicate

Code of Conduct

  • I agree to follow this project's Code of Conduct
@devtobi devtobi added Template: Backend Issues regarding the backend template. Template: EAI Issues regarding the eai template. Type: Maintenance The issue contains maintenance work. Priority: High The issue contains work with high priority. labels Aug 2, 2024
@devtobi devtobi self-assigned this Aug 2, 2024
@devtobi
Copy link
Member Author

devtobi commented Aug 2, 2024

I suggest using semanticSort set to true with

<importOrder>
    <semanticSort>true</semanticSort> <!-- Sort by package, then class, then member (for static imports). Splitting is based on common conventions (packages are lower case, classes start with upper case) -->
</importOrder>

@devtobi
Copy link
Member Author

devtobi commented Aug 2, 2024

The new mentioned options are only available in a later Spotless version (see diffplug/spotless#1920) than the one thats currently in use. With the problem mentioned in #16 we need to set this issue to blocked for now.

@devtobi devtobi removed their assignment Aug 7, 2024
@eidottermihi
Copy link
Member

We used https://github.com/revelc/formatter-maven-plugin before we switched to spotless. It's way more limited than spotless, but at least Eclipse JDT rules from https://github.com/it-at-m/itm-java-codeformat can be checked/enforced in CI without side-loading stuff from the internet as spotless currently needs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority: High The issue contains work with high priority. Template: Backend Issues regarding the backend template. Template: EAI Issues regarding the eai template. Type: Maintenance The issue contains maintenance work.
Projects
Status: Blocked
Development

When branches are created from issues, their pull requests are automatically linked.

2 participants