Skip to content

Commit

Permalink
Showing 13 changed files with 43 additions and 43 deletions.
2 changes: 1 addition & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Added
* Add an `applyJsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
* Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
### Fixed
* Use latest versions of popular style guides for `eslint` tests to fix failing `useEslintXoStandardRules` test. ([#1761](https://github.com/diffplug/spotless/pull/1761), [#1756](https://github.com/diffplug/spotless/issues/1756))
* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -89,7 +89,7 @@ lib('java.CleanthatJavaStep') +'{{yes}} | {{yes}}
lib('json.gson.GsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('json.JacksonJsonStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('json.JsonSimpleStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('json.ApplyJsonPatchStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('json.JsonPatchStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('kotlin.KtLintStep') +'{{yes}} | {{yes}} | {{yes}} | {{no}} |',
lib('kotlin.KtfmtStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
lib('kotlin.DiktatStep') +'{{yes}} | {{yes}} | {{no}} | {{no}} |',
@@ -141,7 +141,7 @@ lib('yaml.JacksonYamlStep') +'{{yes}} | {{yes}}
| [`json.gson.GsonStep`](lib/src/main/java/com/diffplug/spotless/json/gson/GsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`json.JacksonJsonStep`](lib/src/main/java/com/diffplug/spotless/json/JacksonJsonStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`json.JsonSimpleStep`](lib/src/main/java/com/diffplug/spotless/json/JsonSimpleStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`json.ApplyJsonPatchStep`](lib/src/main/java/com/diffplug/spotless/json/ApplyJsonPatchStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`json.JsonPatchStep`](lib/src/main/java/com/diffplug/spotless/json/JsonPatchStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`kotlin.KtLintStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtLintStep.java) | :+1: | :+1: | :+1: | :white_large_square: |
| [`kotlin.KtfmtStep`](lib/src/main/java/com/diffplug/spotless/kotlin/KtfmtStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
| [`kotlin.DiktatStep`](lib/src/main/java/com/diffplug/spotless/kotlin/DiktatStep.java) | :+1: | :+1: | :white_large_square: | :white_large_square: |
Original file line number Diff line number Diff line change
@@ -28,12 +28,12 @@
import com.diffplug.spotless.JarState;
import com.diffplug.spotless.Provisioner;

public class ApplyJsonPatchStep {
public class JsonPatchStep {
// https://mvnrepository.com/artifact/com.flipkart.zjsonpatch/zjsonpatch
static final String MAVEN_COORDINATE = "com.flipkart.zjsonpatch:zjsonpatch";
static final String DEFAULT_VERSION = "0.4.14";

private ApplyJsonPatchStep() {}
private JsonPatchStep() {}

public static FormatterStep create(String patchString, Provisioner provisioner) {
return create(DEFAULT_VERSION, patchString, provisioner);
@@ -77,7 +77,7 @@ private State(String zjsonPatchVersion, String patchString, Provisioner provisio
}

FormatterFunc toFormatter() throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
Class<?> formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.json.ApplyJsonPatchFormatterFunc");
Class<?> formatterFunc = jarState.getClassLoader().loadClass("com.diffplug.spotless.glue.json.JsonPatchFormatterFunc");
if (this.patch != null) {
Constructor<?> constructor = formatterFunc.getConstructor(List.class);
return (FormatterFunc) constructor.newInstance(patch);
Original file line number Diff line number Diff line change
@@ -23,18 +23,18 @@

import com.diffplug.spotless.FormatterFunc;

public class ApplyJsonPatchFormatterFunc implements FormatterFunc {
public class JsonPatchFormatterFunc implements FormatterFunc {
private final ObjectMapper objectMapper;
private final List<Map<String, Object>> patch;
private final String patchString;

public ApplyJsonPatchFormatterFunc(String patchString) {
public JsonPatchFormatterFunc(String patchString) {
this.objectMapper = new ObjectMapper();
this.patch = null;
this.patchString = patchString;
}

public ApplyJsonPatchFormatterFunc(List<Map<String, Object>> patch) {
public JsonPatchFormatterFunc(List<Map<String, Object>> patch) {
this.objectMapper = new ObjectMapper();
this.patch = patch;
this.patchString = null;
2 changes: 1 addition & 1 deletion plugin-gradle/CHANGES.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Added
* Add an `applyJsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
* Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
### Fixed
* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
8 changes: 4 additions & 4 deletions plugin-gradle/README.md
Original file line number Diff line number Diff line change
@@ -811,7 +811,7 @@ spotless {
gson() // has its own section below
jackson() // has its own section below
rome() // has its own section below
applyJsonPatch([]) // has its own section below
jsonPatch([]) // has its own section below
}
}
```
@@ -873,7 +873,7 @@ spotless {
}
```
### applyJsonPatch
### jsonPatch
Uses [zjsonpatch](https://github.com/flipkart-incubator/zjsonpatch) to apply [JSON Patches](https://jsonpatch.com/) as per [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902/) to JSON documents.
@@ -893,7 +893,7 @@ For example, to apply the patch from the [JSON Patch homepage](https://jsonpatch
spotless {
json {
target 'src/**/*.json'
applyJsonPatch([
jsonPatch([
[op: 'replace', path: '/baz', value: 'boo'],
[op: 'add', path: '/hello', value: ['world']],
[op: 'remove', path: '/foo']
@@ -908,7 +908,7 @@ Or using the Kotlin DSL:
spotless {
json {
target("src/**/*.json")
applyJsonPatch(listOf(
jsonPatch(listOf(
mapOf("op" to "replace", "path" to "/baz", "value" to "boo"),
mapOf("op" to "add", "path" to "/hello", "value" to listOf("world")),
mapOf("op" to "remove", "path" to "/foo")
Original file line number Diff line number Diff line change
@@ -22,9 +22,9 @@
import javax.inject.Inject;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.json.ApplyJsonPatchStep;
import com.diffplug.spotless.json.JacksonJsonConfig;
import com.diffplug.spotless.json.JacksonJsonStep;
import com.diffplug.spotless.json.JsonPatchStep;
import com.diffplug.spotless.json.JsonSimpleStep;
import com.diffplug.spotless.json.gson.GsonStep;

@@ -75,12 +75,12 @@ public RomeJson rome(String version) {
return romeConfig;
}

public ApplyJsonPatchConfig applyJsonPatch(List<Map<String, Object>> patch) {
return new ApplyJsonPatchConfig(patch);
public JsonPatchConfig jsonPatch(List<Map<String, Object>> patch) {
return new JsonPatchConfig(patch);
}

public ApplyJsonPatchConfig applyJsonPatch(String zjsonPatchVersion, List<Map<String, Object>> patch) {
return new ApplyJsonPatchConfig(zjsonPatchVersion, patch);
public JsonPatchConfig jsonPatch(String zjsonPatchVersion, List<Map<String, Object>> patch) {
return new JsonPatchConfig(zjsonPatchVersion, patch);
}

public class SimpleConfig {
@@ -204,28 +204,28 @@ protected RomeJson getThis() {
}
}

public class ApplyJsonPatchConfig {
public class JsonPatchConfig {
private String zjsonPatchVersion;
private List<Map<String, Object>> patch;

public ApplyJsonPatchConfig(List<Map<String, Object>> patch) {
public JsonPatchConfig(List<Map<String, Object>> patch) {
this(DEFAULT_ZJSONPATCH_VERSION, patch);
}

public ApplyJsonPatchConfig(String zjsonPatchVersion, List<Map<String, Object>> patch) {
public JsonPatchConfig(String zjsonPatchVersion, List<Map<String, Object>> patch) {
this.zjsonPatchVersion = zjsonPatchVersion;
this.patch = patch;
addStep(createStep());
}

public ApplyJsonPatchConfig version(String zjsonPatchVersion) {
public JsonPatchConfig version(String zjsonPatchVersion) {
this.zjsonPatchVersion = zjsonPatchVersion;
replaceStep(createStep());
return this;
}

private FormatterStep createStep() {
return ApplyJsonPatchStep.create(zjsonPatchVersion, patch, provisioner());
return JsonPatchStep.create(zjsonPatchVersion, patch, provisioner());
}
}
}
Original file line number Diff line number Diff line change
@@ -158,7 +158,7 @@ void jacksonFormattingWithSortingByKeys() throws IOException {
}

@Test
void applyJsonPatchReplaceString() throws IOException {
void jsonPatchReplaceString() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'java'",
@@ -168,7 +168,7 @@ void applyJsonPatchReplaceString() throws IOException {
"spotless {",
" json {",
" target 'src/**/*.json'",
" applyJsonPatch([[op: 'replace', path: '/abc', value: 'ghi']])",
" jsonPatch([[op: 'replace', path: '/abc', value: 'ghi']])",
" gson()",
" }",
"}");
@@ -178,7 +178,7 @@ void applyJsonPatchReplaceString() throws IOException {
}

@Test
void applyJsonPatchReplaceWithObject() throws IOException {
void jsonPatchReplaceWithObject() throws IOException {
setFile("build.gradle").toLines(
"plugins {",
" id 'java'",
@@ -188,7 +188,7 @@ void applyJsonPatchReplaceWithObject() throws IOException {
"spotless {",
" json {",
" target 'src/**/*.json'",
" applyJsonPatch([[op: 'replace', path: '/abc', value: [def: 'ghi']]])",
" jsonPatch([[op: 'replace', path: '/abc', value: [def: 'ghi']]])",
" gson()",
" }",
"}");
2 changes: 1 addition & 1 deletion plugin-maven/CHANGES.md
Original file line number Diff line number Diff line change
@@ -4,7 +4,7 @@ We adhere to the [keepachangelog](https://keepachangelog.com/en/1.0.0/) format (

## [Unreleased]
### Added
* Add an `applyJsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
* Add a `jsonPatch` step to `json` formatter configurations. This allows patching of JSON documents using [JSON Patches](https://jsonpatch.com). ([#1753](https://github.com/diffplug/spotless/pull/1753))
### Fixed
* Add support for `prettier` version `3.0.0` and newer. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1751](https://github.com/diffplug/spotless/issues/1751))
* Fix npm install calls when npm cache is not up-to-date. ([#1760]https://github.com/diffplug/spotless/pull/1760), [#1750](https://github.com/diffplug/spotless/issues/1750))
8 changes: 4 additions & 4 deletions plugin-maven/README.md
Original file line number Diff line number Diff line change
@@ -901,7 +901,7 @@ For details, see the [npm detection](#npm-detection), [`.npmrc` detection](#npmr
<gson /> <!-- has its own section below -->
<jackson /> <!-- has its own section below -->
<rome /> <!-- has its own section below -->
<applyJsonPatch /> <!-- has its own section below -->
<jsonPatch /> <!-- has its own section below -->
</json>
</configuration>
```
@@ -958,7 +958,7 @@ Uses Jackson for formatting.

<a name="applying-prettier-to-javascript--flow--typescript--css--scss--less--jsx--graphql--yaml--etc"></a>

### applyJsonPatch
### jsonPatch

Uses [zjsonpatch](https://github.com/flipkart-incubator/zjsonpatch) to apply [JSON Patches](https://jsonpatch.com/) as per [RFC 6902](https://datatracker.ietf.org/doc/html/rfc6902/) to JSON documents.

@@ -967,11 +967,11 @@ This enables you to add, replace or remove properties at locations in the JSON d
For example, to apply the patch from the [JSON Patch homepage](https://jsonpatch.com/#the-patch):

```xml
<applyJsonPatch>[
<jsonPatch>[
{ "op": "replace", "path": "/baz", "value": "boo" },
{ "op": "add", "path": "/hello", "value": ["world"] },
{ "op": "remove", "path": "/foo" }
]</applyJsonPatch>
]</jsonPatch>
```

## YAML
Original file line number Diff line number Diff line change
@@ -54,7 +54,7 @@ public void addRome(RomeJson rome) {
addStepFactory(rome);
}

public void addApplyJsonPatch(ApplyJsonPatch applyJsonPatch) {
addStepFactory(applyJsonPatch);
public void addJsonPatch(JsonPatch jsonPatch) {
addStepFactory(jsonPatch);
}
}
Original file line number Diff line number Diff line change
@@ -18,14 +18,14 @@
import org.apache.maven.plugins.annotations.Parameter;

import com.diffplug.spotless.FormatterStep;
import com.diffplug.spotless.json.ApplyJsonPatchStep;
import com.diffplug.spotless.json.JsonPatchStep;
import com.diffplug.spotless.maven.FormatterStepConfig;
import com.diffplug.spotless.maven.FormatterStepFactory;

/**
* A {@link FormatterStepFactory} implementation that corresponds to {@code <applyJsonPatch>...</applyJsonPatch>} configuration element.
* A {@link FormatterStepFactory} implementation that corresponds to {@code <jsonPatch>...</jsonPatch>} configuration element.
*/
public class ApplyJsonPatch implements FormatterStepFactory {
public class JsonPatch implements FormatterStepFactory {
private static final String DEFAULT_ZJSONPATCH_VERSION = "0.4.14";

@Parameter
@@ -36,6 +36,6 @@ public class ApplyJsonPatch implements FormatterStepFactory {

@Override
public FormatterStep newFormatterStep(FormatterStepConfig stepConfig) {
return ApplyJsonPatchStep.create(zjsonPatchVersion, patch, stepConfig.getProvisioner());
return JsonPatchStep.create(zjsonPatchVersion, patch, stepConfig.getProvisioner());
}
}
Original file line number Diff line number Diff line change
@@ -91,8 +91,8 @@ public void testFormatJson_WithJackson_sortByKeys_spaceAfterKeySeparator() throw
}

@Test
public void testFormatJson_ApplyJsonPatch_replaceString() throws Exception {
writePomWithJsonSteps("<applyJsonPatch><patch>[{\"op\":\"replace\",\"path\":\"/abc\",\"value\":\"ghi\"}]</patch></applyJsonPatch><gson/>");
public void testFormatJson_JsonPatch_replaceString() throws Exception {
writePomWithJsonSteps("<jsonPatch><patch>[{\"op\":\"replace\",\"path\":\"/abc\",\"value\":\"ghi\"}]</patch></jsonPatch><gson/>");

setFile("json_test.json").toResource("json/patchObjectBefore.json");

@@ -101,8 +101,8 @@ public void testFormatJson_ApplyJsonPatch_replaceString() throws Exception {
}

@Test
public void testFormatJson_ApplyJsonPatch_replaceWithObject() throws Exception {
writePomWithJsonSteps("<applyJsonPatch><patch>[{\"op\":\"replace\",\"path\":\"/abc\",\"value\":{\"def\":\"ghi\"}}]</patch></applyJsonPatch><gson/>");
public void testFormatJson_JsonPatch_replaceWithObject() throws Exception {
writePomWithJsonSteps("<jsonPatch><patch>[{\"op\":\"replace\",\"path\":\"/abc\",\"value\":{\"def\":\"ghi\"}}]</patch></jsonPatch><gson/>");

setFile("json_test.json").toResource("json/patchObjectBefore.json");

0 comments on commit 1eb2a4f

Please sign in to comment.