Skip to content

JSON Formatting in mvn plugin #1445

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

Closed
blacelle opened this issue Jan 3, 2023 · 7 comments
Closed

JSON Formatting in mvn plugin #1445

blacelle opened this issue Jan 3, 2023 · 7 comments

Comments

@blacelle
Copy link
Contributor

blacelle commented Jan 3, 2023

The maven plugin seems not to support JSON formatting. Is there a good reason for this? Or would it be considered a good contribution from a new-comer ?

@nedtwigg
Copy link
Member

nedtwigg commented Jan 3, 2023

There is no reason for it, and it would be a great contribution from a newcomer!

@blacelle
Copy link
Contributor Author

blacelle commented Jan 3, 2023

A PR is open. I see this will not fulfil my own need ('\t' as tabulation). Ecryd sortPom accepts -1 spaces to trigger tabulation indentation (https://github.com/Ekryd/sortpom/wiki/Parameters#for-both-the-sort-and-verify-goal). Is it OK I open another PR to accept such a parameter in com.diffplug.spotless.json.gson.GsonStep.State.generateIndent(int)?

@nedtwigg
Copy link
Member

nedtwigg commented Jan 3, 2023

Thanks for the PR

If the only problem is indenting with tabs vs space, I would recommend the indentWithTabs step instead of adding a feature/mode to an existing step. If it's a small amount of new code I'd be okay to merge another PR, but if it's a lot of code I'd rather point people to indentWithTabs.

@blacelle
Copy link
Contributor Author

blacelle commented Jan 4, 2023

Thanks @nedtwigg. The existing PR does not hold anything relating to tabs.

Being new to Spotless, it took few a few seconds to understand your point. My suggested changes (-1 for tabulation) would be very minimal. I agree it is awkward, still it is the way some plugin works (e.g. Ecryd SortPom, then some formatting-plugins users are used to it (at the very least myself,, which is of course veryopinionated xD)).

I see the gradlePlugin enables Prettier and other external formatters to enable JSON formatting. However, it seems more difficult to reach with maven. Could you provide a snippet of the mvn pom.xml <configuration /> section how you would recommend reaching tabs in json formatting? (If it is an existing feature, I could open a dedicated ticket, else it would help me understand how to best implement this feature.)

@nedtwigg
Copy link
Member

nedtwigg commented Jan 4, 2023

I am terrible at maven, I just merge things that

  • people actually want for themselves
  • doesn't break and has tests so it stays not broken
  • won't be hard for the Spotless team to maintain into the future

So whatever -1 flags you want to add are okay with me, but I still think this existing feature is easier to use and definitely easier to build (already done!)

        <indent>
          <tabs>true</tabs>
          <spacesPerTab>4</spacesPerTab>
        </indent>

@blacelle
Copy link
Contributor Author

blacelle commented Jan 5, 2023

@nedtwigg I now better understand your point. Something unclear to me was how <formats> and <json> would interleave themselves. I suppose formats are applied after specialized formatters (as mvn is much less expressive in term of ordering/customization than gradle), in which case tab indentation is already feasible.

The PR for JSON formatting in mvn is ready.

I open another issue which may describe an issue related to interleaving formats and specialized formatters (#1455)

@nedtwigg
Copy link
Member

Published in plugin-maven 2.30.0, thanks for the great PR @blacelle.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants