-
Notifications
You must be signed in to change notification settings - Fork 91
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
Provide a way to use my own formatters #435
Comments
I'm not necessarily opposed, but why bolt on additional formatters to this plugin, rather than just create a separate plugin? |
A separate plugin could also be implemented of course. But then I would need to implement some parts of this plugin myself, like caching formatted files so they do not get formatted over-and-over for no reason. I suppose the idea popped up because I saw this plugin does more than format Java. It also formats CSS, HTML, JSON, JavaScript... Why stop there? Or maybe the other way around: why weren't those formatters implemented in separate plugins? |
I think they should have been. I think this plugin is a bit too bloated and not as lightweight as it should be. There have been previous similar requests to extend the formatting functionality (see previous issues) and an open issue to at least move the existing ones into separate executions, if not separate plugins (#254) which would help address certain constraints on how to match up files to specific formatter executions (#427). I'm not a huge fan of adding a bunch of random unrelated formatters for different languages into a single monolithic plugin. However, I kind of like your suggestion to make it extensible. I think I'd be in favor of that, if the configuration were easy to use, and it was done as a separate mojo. In any case, if this were to be implemented, it would be a big change. |
I think the best way would be implementing a service loader, but I agree it would be a big change. Also, some thought needs to be given to how the configuration would look like. For example: should you configure the directories to format at a global level, or per formatter? What would be your take on this? |
Per-formatter, for sure. I was thinking something like: <plugin>
<groupId>net.revelc.core.formatter</groupId>
<artifactId>formatter-maven-plugin</artifactId>
<version>${formatter.version}</version>
<dependencies>
<dependency>
<groupId>com.example</groupId>
<artifactId>external-formatter</artifactId>
</dependency>
</dependencies>
<executions>
<execution>
<id>some-external-execution</id>
<goals>
<goal>external</goal>
</goals>
<configuration>
<formatterId>MyExternalFormatter</formatterId>
<includes>
<include>**/*.ext</include>
</includes>
<excludes>
<exclude>src/main/resources/alreadyformatted.ext</exclude>
</excludes>
<formatterOptions>
<!-- formatter-specific options -->
<configFile>value</configFile>
</formatterOptions>
</configuration>
</execution>
</executions>
</plugin> The |
That would work, but would this require me to configure things like file encoding and line endings on a per formatter basis? Those probably do not differ between formats, I would think? Wouldn't it be nice to be able to configure this on a global level? Maybe a global Another way would be to identify all stuff that you would want to configure globally, and have the interface define methods for that, like |
My suggestion to have a Global options could still be used as-is, for line-endings, encoding, etc. I just didn't include them as part of my example. You would place such things directly under the configuration of the plugin, rather than in a specific plugin execution's config, and they would be merged. Regarding line endings specifically, a way they can be consistent across formatters is to make the formatter interface be a mapping of |
We would also have to be careful about how the cache works. A separate cache per formatter makes the most sense, I think. So long as one formatter's cache hit doesn't prevent another formatter from doing its work. |
Looks good to me 😀
Hmm... I don't know enough about formatters to know if this would work or not. My gut feeling is that formatters expect a file rather than a |
Most of the formatters, if not all, read the whole file into memory already. This should be fine. If you can't fit a file into memory, you need to learn to organize your code better. 😺 |
Is your feature request related to a problem? Please describe.
Some of my files are in a format for which I have written a formatter myself. I would like to use that formatter.
Also, this would give the option for other people to use different formatters, for example using a different formatter for JavaScript.
Describe the solution you'd like
I would like to add a dependency to the formatter configuration, just like "Basic Configuration Using External Resource". The artifact should contain a class that implements an interface.
Describe alternatives you've considered
I didn't - I'm a lazy person 😀
The text was updated successfully, but these errors were encountered: