Skip to content

JSON Formatting in mvn plugin #1445

Closed
Closed

Description

@blacelle

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 ?

Activity

  1. nedtwigg commented on Jan 3, 2023

    @nedtwigg
    Member
  2. blacelle commented on Jan 3, 2023

    @blacelle
    ContributorAuthor

    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)?

  3. nedtwigg commented on Jan 3, 2023

    @nedtwigg
    Member

    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.

  4. blacelle commented on Jan 4, 2023

    @blacelle
    ContributorAuthor

    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.)

  5. nedtwigg commented on Jan 4, 2023

    @nedtwigg
    Member

    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>
  6. blacelle commented on Jan 5, 2023

    @blacelle
    ContributorAuthor

    @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)

  7. nedtwigg commented on Jan 14, 2023

    @nedtwigg
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions