revelc / formatter-maven-plugin

Formatter Maven Plugin
https://code.revelc.net/formatter-maven-plugin
Apache License 2.0
291 stars 91 forks source link

Support other formatters rather than just Eclipse #133

Closed rbaeta closed 6 years ago

rbaeta commented 8 years ago

If formatter could be abstracted from Eclipse IDE, it would be easy to use it in a maven project loaded in other IDEs, like Intellij and Netbeans. There are opensource code formatters out there that don't depend on m2e plugin. This way you would get rid of Eclipse compliance problems. Cheers!

ctubbsii commented 8 years ago

@rbaeta This plugin is specifically an Eclipse formatter. Part of the reason why it's so useful, is because you can reformat during the build, even if the developers are using another IDE.

Another formatter engine could be used (Eclipse's is probably no better/worse than any other), but if it did, what other formatters would you suggest it use?

huitseeker commented 7 years ago

There is an IntelliJ plugin available as well: https://plugins.jetbrains.com/plugin/8527-google-java-format

ctubbsii commented 6 years ago

Original reporter never responded to my question about the specific formatters being requested, and I think this issue is too broad to be of much value. Other formatters have been added, and I'm sure we could support additional formatters as separate mojos/tasks to execute from this plugin, but each would have to be considered on a case-by-case basis. So, I'm closing this issue.

rbaeta commented 6 years ago

@ctubbsii sorry for being so lazy... The idea was just that maven would not depend on a specific IDE formatters (like the Eclipse one, IDEA or any other - but the Eclipse one is a bit clumsy though); instead, this maven plugin may use the facade/adapter pattern, defining a common set of rules, with a common syntax, and then have each formatter as a plugable component that would act as an adapter, applying those rules to each formatter implementation. I wish I had one way to define the rules, in a IDE-neutral and enterprise wide manner; otherwise, each time I change the formatter engine, I would have the burden to migrate the rule set into that engine syntax. This happened many times when I tryed to import Eclipse rules into IDEA, each time they changed, and it was not an easy task.

ctubbsii commented 6 years ago

@rbaeta Your wish reminds me a bit of https://xkcd.com/927/ ; I think it's probably best if this plugin focuses on the Eclipse engine, as it was designed to do, and let other plugins focus on other formatting engines. Perhaps additional formatting engines could be supported, to enable consistent formatting using the user's preferred engine... but the point of this plugin is that it shouldn't matter what IDE you're using... let users use whatever IDE settings they want and let this plugin make everything consistent regardless of what they're doing.

Jack2code commented 4 years ago

As I use Intellij Idea as my primary IDE. I use Class count to use import with '*':999 and Names count to use static import with '*':999 configs as my code style, but I can't config it in formatter-maven-plugin, any help?

Jack2code commented 4 years ago

and it would be like as below in the idea code style file:

<option name="CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
<option name="NAMES_COUNT_TO_USE_IMPORT_ON_DEMAND" value="999" />
ctubbsii commented 4 years ago

@Jack2code Please create a new issue if you have a question, rather than commenting on a different topic. As for your question, I think that's a question for Eclipse, as this formatter plugin uses the Eclipse formatter. The only thing I would know how to do is create the formatting settings you want in the Eclipse UI, and then export it to XML to see how it's stored.