Skip to content

Commit

Permalink
Merge pull request project-ncl#13 from rnc/FORMAT
Browse files Browse the repository at this point in the history
Baseline formatter upon Quarkus format
  • Loading branch information
thescouser89 authored Jan 23, 2025
2 parents fd72707 + 896b997 commit 4b263d0
Show file tree
Hide file tree
Showing 9 changed files with 383 additions and 380 deletions.
103 changes: 98 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ProjectNCL IDE Configuration Files

The directories below contain instructions and IDE configuration files for Eclipse. See below for additional information.

This was originally based upon https://github.com/jboss/ide-config
This was originally based upon https://github.com/jboss/ide-config and https://github.com/quarkusio/quarkus/blob/main/independent-projects/ide-config/src/main/resources/eclipse-format.xml


IDE Agnostic Conventions
Expand All @@ -15,17 +15,16 @@ IDE Agnostic Conventions
* Line length is 120 characters
* Spaces are used instead of tabs
* Indentation size is 4
* Switch blocks are indented
* Switch blocks are indented

*Formatting Other Files*

* Line length is 120 characters
* Spaces are used instead of tabs
* Indentation size is 4



# Intellij setup with the eclipse formatter xml
## Intellij setup with the eclipse formatter xml

1. On Intellij, install the 'Eclipse Code Formatter' plugin
2. Restart Intellij for the plugin to be installed
Expand All @@ -35,3 +34,97 @@ IDE Agnostic Conventions
6. Finally, click 'OK'. When formatting your code, it'll format according to the recommened codestyle now

PS: we are not using the built-in Intellij 'Eclipse import Java codestyle' since it is lacking in a lot of places and the formatting is not a good representation of what we have in Eclipse.


# Integration With Maven

There are a couple of options using either `net.revelc.code.formatter:formatter-maven-plugin` or `com.diffplug.spotless:spotless-maven-plugin`.

Note that there is **no** need to store a local copy of the formatter (any of those can be removed).

## revelc:formatter

A typical pom could contain:

```
<properties
<formatter-maven-plugin.version>2.24.1</formatter-maven-plugin.version>
<impsort-maven-plugin.version>1.12.0</impsort-maven-plugin.version>
<format.skip>false</format.skip>
</properties>
<plugin>
<groupId>net.revelc.code.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>${formatter-maven-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.jboss.pnc</groupId>
<artifactId>ide-config</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache/formatter-maven-plugin-${formatter-maven-plugin.version}</cachedir>
<configFile>java-formatter.xml</configFile>
<lineEnding>LF</lineEnding>
<skip>${format.skip}</skip>
</configuration>
</plugin>
<plugin>
<groupId>net.revelc.code</groupId>
<artifactId>impsort-maven-plugin</artifactId>
<version>${impsort-maven-plugin.version}</version>
<configuration>
<!-- store outside of target to speed up formatting when mvn clean is used -->
<cachedir>.cache/impsort-maven-plugin-${impsort-maven-plugin.version}</cachedir>
<groups>java.,javax.,jakarta.,org.,com.</groups>
<staticGroups>*</staticGroups>
<lineEnding>LF</lineEnding>
<skip>${format.skip}</skip>
<removeUnused>true</removeUnused>
</configuration>
</plugin>
```

Note that configuration for `impsort-maven-plugin` has also been added as its a common extra with `formatter-maven-plugin`.

## spotless

A typical pom could contain:

```
<plugin>
<groupId>com.diffplug.spotless</groupId>
<artifactId>spotless-maven-plugin</artifactId>
<version>2.44.2</version>
<dependencies>
<dependency>
<groupId>org.jboss.pnc</groupId>
<artifactId>ide-config</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<configuration>
<java>
<removeUnusedImports/>
<importOrder>
<order>java,javax,jakarta,org,com</order>
</importOrder>
<eclipse>
<file>java-formatter.xml</file>
</eclipse>
<lineEndings>UNIX</lineEndings>
</java>
</configuration>
<executions>
<execution>
<goals>
<goal>apply</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
</plugin>
```
6 changes: 2 additions & 4 deletions src/main/resources/README.md
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
JBoss IDE Configuration Files For Eclipse
IDE Configuration Files For Eclipse
=========================================
The following instructions cover how to configure eclipse to use files and conventions to comply with JBoss coding standards.

(version 3.7 used)
The following instructions cover how to configure eclipse to use files and conventions to comply with coding standards.

Java Formatter
--------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
Expand Down
Loading

0 comments on commit 4b263d0

Please sign in to comment.