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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JVM-based JSON formatter #853

Merged
merged 3 commits into from Jun 17, 2021
Merged

Commits on Jun 16, 2021

  1. Add simple JVM-based JSON formatter

    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 committed Jun 16, 2021
    Configuration menu
    Copy the full SHA
    42c59c8 View commit details
    Browse the repository at this point in the history
  2. Add Gradle bindings for JSON formatter

    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 committed Jun 16, 2021
    Configuration menu
    Copy the full SHA
    ca814b4 View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    965d2ff View commit details
    Browse the repository at this point in the history