Git Product home page Git Product logo

Comments (3)

nils-christian avatar nils-christian commented on June 24, 2024

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.

ctubbsii avatar ctubbsii commented on June 24, 2024

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.

nils-christian avatar nils-christian commented on June 24, 2024

Hi,

Yes, I can confirm that simply re-exporting the formatting configuration solves the issue. Thank you.

from formatter-maven-plugin.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.