Comments (3)
Hi,
I created a project to reproduce the issue: https://github.com/nils-christian/formatter-maven-plugin-issue-776
Simply execute the batch file (or run mvn -q net.revelc.code.formatter:formatter-maven-plugin:format@formatter-format manually) and the file "A.java" will be changed. Eclipse, on the other hand, won't change the file with the same formatter settings.
from formatter-maven-plugin.
Your formatter configuration is quite old. If I import it into a newer version of Eclipse, and then re-export it, it includes additional configuration items that pertain to styling for newer Java language elements, such as the sealed keyword. When you import it into Eclipse, it fills in those additional items and formats correctly. If you use the old formatter config file as-is, the Eclipse formatter API, which this plugin uses, will not do that. If you want to this plugin to format newer language elements, you need to use a config file that specifies the formatting for those elements. The current formatter config file you have will not do that.
Oh, and as a request, if you want to provide an example project in future to report a bug or potential bug, that's fine, but please make it self-contained, rather than have it rely on a separate external parent POM that I have to track down. I modified your example locally to get rid of the parent POM before I could reproduce:
diff --git a/pom.xml b/pom.xml
index ec75c94..fee83a2 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,20 +3,16 @@
<modelVersion>4.0.0</modelVersion>
- <parent>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-parent</artifactId>
- <version>2.7.14</version>
- <relativePath />
- </parent>
-
<groupId>com.example</groupId>
<artifactId>demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>demo</name>
<properties>
- <java.version>17</java.version>
+ <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
+ <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
+ <maven.compiler.source>17</maven.compiler.source>
+ <maven.compiler.target>17</maven.compiler.target>
</properties>
<build>
@@ -34,7 +30,7 @@
<goals>
<goal>format</goal>
</goals>
- <phase>none</phase>
+ <phase>package</phase>
</execution>
<execution>
<id>formatter-validate</id>
@@ -51,4 +47,4 @@
</plugins>
</build>
-</project>
\ No newline at end of file
+</project>
This is the is diff after merely importing your formatter config and re-exporting it:
diff --git a/src/main/java/com/example/demo/A.java b/src/main/java/com/example/demo/A.java
index bc20c7b..e0d39e0 100644
--- a/src/main/java/com/example/demo/A.java
+++ b/src/main/java/com/example/demo/A.java
@@ -1,5 +1,6 @@
package com.example.demo;
-public sealed interface A permits B, C {
+public sealed interface A
+ permits B, C {
}
More details about the differences between what Eclipse does in the UI and what it does in the formatting library API that is used by this plugin can be found in the discussion at https://bugs.eclipse.org/bugs/show_bug.cgi?id=545603
from formatter-maven-plugin.
Hi,
Yes, I can confirm that simply re-exporting the formatting configuration solves the issue. Thank you.
from formatter-maven-plugin.
Related Issues (20)
- Cannot invoke IExtensionRegistry.getExtensionPoint because Platform.getExtensionRegistry()" is null HOT 2
- Allow resources to be included when formatting
- On the fly hash before and after to replace current caching system files. HOT 1
- Add support for xml-formatter 'deleteBlankLines' HOT 2
- Drop dependabot in favor of Renovate HOT 3
- Mockito WHEN Bug in Eclipse formatting jdt core 3.32.0 and 3.33.0 HOT 3
- Large whitespace in debug output HOT 9
- Bad format of sealed interfaces extending other interfaces HOT 9
- Option to fail to process invalid setting id HOT 2
- New Configuration hashing into file hash breaks existing caching - only confirmed with XML at the moment HOT 2
- NOTICE: Eclipse 2023-06 Requires jdk 17 for many parts HOT 7
- Eclipse Formatter Attribute Ignored: Parameter After Annotation HOT 1
- Not able to run validate due to ExtensionRegistry return null value HOT 4
- False configuration used for line Indentation HOT 2
- lineEnding=KEEP breaks JSON validation on Windows HOT 6
- Report problematic line number in error message HOT 3
- Tab treated as one space for the purpose of line length HOT 3
- Includes are not honored by includeResources
- Rewrite the cache store to match that done on impsort HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from formatter-maven-plugin.