Skip to content
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

Add JVM-based JSON formatter #850

Closed
jamietanna opened this issue Apr 22, 2021 · 1 comment · Fixed by #853
Closed

Add JVM-based JSON formatter #850

jamietanna opened this issue Apr 22, 2021 · 1 comment · Fixed by #853

Comments

@jamietanna
Copy link
Contributor

It would be good to have a JVM-only version of JSON formatters, without needing to have prettier installed.

I'd be happy to contribute this, for Gradle - would it be best to raise a PR to add this formatter, or shall I create it as a separate project?

@nedtwigg
Copy link
Member

JVM-only json formatter is very welcome! If you can implement it without any third-party dependencies, then it can live in lib like the sql formatter.

If it needs just third-party dependencies then it should live in lib-extra.

// misc useful utilities
implementation "com.diffplug.durian:durian-core:${VER_DURIAN}"
implementation "com.diffplug.durian:durian-collect:${VER_DURIAN}"
// needed by GitAttributesLineEndings
implementation "org.eclipse.jgit:org.eclipse.jgit:${VER_JGIT}"
implementation "com.googlecode.concurrent-trees:concurrent-trees:2.6.1"
// used for xml parsing in EclipseFormatter
implementation "org.codehaus.groovy:groovy-xml:3.0.7"

If the dependencies you need cause a lot of conflicts (ala #587), then we can always pull it out into a third-party lib later on.

jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 25, 2021
Currenly, if consumers of Spotless want to format their JSON files, they
need to do this by adding `prettier`, which increases the dependencies a
project needs.

To simplify things for consumers, as documented in diffplug#850, we can provide
a JVM-based JSON formatter, using `org.json`'s JSON formatting.

To follow how we've done this with other formatters, we can retrieve
`org.json`'s JAR at runtime, and retrieve the classes via Reflection,
instead of adding this as a `lib-extra` project, with an explicit
dependency.

To validate this fully, we want a few straightforward JSON files to
validate before/after, but we can also use [a sample Cucumber JSON
report] as a much more complex example of what happens, which we've
removed any `data` objects from its source, so the files are smaller.

We've added an `equality` test, but it doesn't really test too much
right now as there's nothing stored in the state.

[a sample Cucumber JSON report]: https://github.com/damianszczepanik/cucumber-reporting/raw/master/src/test/resources/json/sample.json
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 25, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 25, 2021
Currenly, if consumers of Spotless want to format their JSON files, they
need to do this by adding `prettier`, which increases the dependencies a
project needs.

To simplify things for consumers, as documented in diffplug#850, we can provide
a JVM-based JSON formatter, using `org.json`'s JSON formatting.

To follow how we've done this with other formatters, we can retrieve
`org.json`'s JAR at runtime, and retrieve the classes via Reflection,
instead of adding this as a `lib-extra` project, with an explicit
dependency.

To validate this fully, we want a few straightforward JSON files to
validate before/after, but we can also use [a sample Cucumber JSON
report] as a much more complex example of what happens, which we've
removed any `data` objects from its source, so the files are smaller.

We've added an `equality` test, but it doesn't really test too much
right now as there's nothing stored in the state.

[a sample Cucumber JSON report]: https://github.com/damianszczepanik/cucumber-reporting/raw/master/src/test/resources/json/sample.json
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 25, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 25, 2021
Currenly, if consumers of Spotless want to format their JSON files, they
need to do this by adding `prettier`, which increases the dependencies a
project needs.

To simplify things for consumers, as documented in diffplug#850, we can provide
a JVM-based JSON formatter, using `org.json`'s JSON formatting.

To follow how we've done this with other formatters, we can retrieve
`org.json`'s JAR at runtime, and retrieve the classes via Reflection,
instead of adding this as a `lib-extra` project, with an explicit
dependency.

To validate this fully, we want a few straightforward JSON files to
validate before/after, but we can also use [a sample Cucumber JSON
report] as a much more complex example of what happens, which we've
removed any `data` objects from its source, so the files are smaller.

We've added an `equality` test, but it doesn't really test too much
right now as there's nothing stored in the state.

[a sample Cucumber JSON report]: https://github.com/damianszczepanik/cucumber-reporting/raw/master/src/test/resources/json/sample.json
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 25, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 27, 2021
Currenly, if consumers of Spotless want to format their JSON files, they
need to do this by adding `prettier`, which increases the dependencies a
project needs.

To simplify things for consumers, as documented in diffplug#850, we can provide
a JVM-based JSON formatter, using `org.json`'s JSON formatting.

To follow how we've done this with other formatters, we can retrieve
`org.json`'s JAR at runtime, and retrieve the classes via Reflection,
instead of adding this as a `lib-extra` project, with an explicit
dependency.

To validate this fully, we want a few straightforward JSON files to
validate before/after, but we can also use [a sample Cucumber JSON
report] as a much more complex example of what happens, which we've
removed any `data` objects from its source, so the files are smaller.

We've added an `equality` test, but it doesn't really test too much
right now as there's nothing stored in the state.

[a sample Cucumber JSON report]: https://github.com/damianszczepanik/cucumber-reporting/raw/master/src/test/resources/json/sample.json
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 27, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 27, 2021
Currenly, if consumers of Spotless want to format their JSON files, they
need to do this by adding `prettier`, which increases the dependencies a
project needs.

To simplify things for consumers, as documented in diffplug#850, we can provide
a JVM-based JSON formatter, using `org.json`'s JSON formatting.

To follow how we've done this with other formatters, we can retrieve
`org.json`'s JAR at runtime, and retrieve the classes via Reflection,
instead of adding this as a `lib-extra` project, with an explicit
dependency.

To validate this fully, we want a few straightforward JSON files to
validate before/after, but we can also use [a sample Cucumber JSON
report] as a much more complex example of what happens, which we've
removed any `data` objects from its source, so the files are smaller.

We've added an `equality` test, but it doesn't really test too much
right now as there's nothing stored in the state.

[a sample Cucumber JSON report]: https://github.com/damianszczepanik/cucumber-reporting/raw/master/src/test/resources/json/sample.json
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 27, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 27, 2021
Currenly, if consumers of Spotless want to format their JSON files, they
need to do this by adding `prettier`, which increases the dependencies a
project needs.

To simplify things for consumers, as documented in diffplug#850, we can provide
a JVM-based JSON formatter, using `org.json`'s JSON formatting.

To follow how we've done this with other formatters, we can retrieve
`org.json`'s JAR at runtime, and retrieve the classes via Reflection,
instead of adding this as a `lib-extra` project, with an explicit
dependency.

To validate this fully, we want a few straightforward JSON files to
validate before/after, but we can also use [a sample Cucumber JSON
report] as a much more complex example of what happens, which we've
removed any `data` objects from its source, so the files are smaller.

We also want our consumers to be able to configure the indentation size.

[a sample Cucumber JSON report]: https://github.com/damianszczepanik/cucumber-reporting/raw/master/src/test/resources/json/sample.json
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 27, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 28, 2021
Currenly, if consumers of Spotless want to format their JSON files, they
need to do this by adding `prettier`, which increases the dependencies a
project needs.

To simplify things for consumers, as documented in diffplug#850, we can provide
a JVM-based JSON formatter, using `org.json`'s JSON formatting.

To follow how we've done this with other formatters, we can retrieve
`org.json`'s JAR at runtime, and retrieve the classes via Reflection,
instead of adding this as a `lib-extra` project, with an explicit
dependency.

To validate this fully, we want a few straightforward JSON files to
validate before/after, but we can also use [a sample Cucumber JSON
report] as a much more complex example of what happens, which we've
removed any `data` objects from its source, so the files are smaller.

We also want our consumers to be able to configure the indentation size.

[a sample Cucumber JSON report]: https://github.com/damianszczepanik/cucumber-reporting/raw/master/src/test/resources/json/sample.json
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 28, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 28, 2021
Currenly, if consumers of Spotless want to format their JSON files, they
need to do this by adding `prettier`, which increases the dependencies a
project needs.

To simplify things for consumers, as documented in diffplug#850, we can provide
a JVM-based JSON formatter, using `org.json`'s JSON formatting.

To follow how we've done this with other formatters, we can retrieve
`org.json`'s JAR at runtime, and retrieve the classes via Reflection,
instead of adding this as a `lib-extra` project, with an explicit
dependency.

To validate this fully, we want a few straightforward JSON files to
validate before/after, but we can also use [a sample Cucumber JSON
report] as a much more complex example of what happens, which we've
removed any `data` objects from its source, so the files are smaller.

We also want our consumers to be able to configure the indentation size.

[a sample Cucumber JSON report]: https://github.com/damianszczepanik/cucumber-reporting/raw/master/src/test/resources/json/sample.json
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 28, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 29, 2021
Currenly, if consumers of Spotless want to format their JSON files, they
need to do this by adding `prettier`, which increases the dependencies a
project needs.

To simplify things for consumers, as documented in diffplug#850, we can provide
a JVM-based JSON formatter, using `org.json`'s JSON formatting.

To follow how we've done this with other formatters, we can retrieve
`org.json`'s JAR at runtime, and retrieve the classes via Reflection,
instead of adding this as a `lib-extra` project, with an explicit
dependency.

To validate this fully, we want a few straightforward JSON files to
validate before/after, but we can also use [a sample Cucumber JSON
report] as a much more complex example of what happens, which we've
removed any `data` objects from its source, so the files are smaller.

We also want our consumers to be able to configure the indentation size.

We're calling this a `simple` formatter as it doesn't allow much to be
configured other than the indentation size in spaces.

[a sample Cucumber JSON report]: https://github.com/damianszczepanik/cucumber-reporting/raw/master/src/test/resources/json/sample.json
jamietanna added a commit to jamietanna/spotless that referenced this issue Apr 29, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Jun 16, 2021
Currenly, if consumers of Spotless want to format their JSON files, they
need to do this by adding `prettier`, which increases the dependencies a
project needs.

To simplify things for consumers, as documented in diffplug#850, we can provide
a JVM-based JSON formatter, using `org.json`'s JSON formatting.

To follow how we've done this with other formatters, we can retrieve
`org.json`'s JAR at runtime, and retrieve the classes via Reflection,
instead of adding this as a `lib-extra` project, with an explicit
dependency.

To validate this fully, we want a few straightforward JSON files to
validate before/after, but we can also use [a sample Cucumber JSON
report] as a much more complex example of what happens, which we've
removed any `data` objects from its source, so the files are smaller.

We also want our consumers to be able to configure the indentation size.

We're calling this a `simple` formatter as it doesn't allow much to be
configured other than the indentation size in spaces.

[a sample Cucumber JSON report]: https://github.com/damianszczepanik/cucumber-reporting/raw/master/src/test/resources/json/sample.json
jamietanna added a commit to jamietanna/spotless that referenced this issue Jun 16, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Jun 16, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Jun 16, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
jamietanna added a commit to jamietanna/spotless that referenced this issue Jun 16, 2021
As we've created a JVM JSON formatter as part of diffplug#850, we should make it
possible to use it natively in Gradle, which requires we add it as a new
supported type in `SpotlessExtension`.

When configured, we'll default to including any JSON files under the
`src` directory, while allowing it to be overriden if requested.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants