Skip to content

Commit 0afd327

Browse files
committed
Add rome format step to json/javascript/typescript languages
1 parent afd0edb commit 0afd327

File tree

4 files changed

+127
-3
lines changed

4 files changed

+127
-3
lines changed

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/FormatExtension.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ protected final FileCollection parseTarget(Object target) {
232232

233233
private final FileCollection parseTargetIsExclude(Object target, boolean isExclude) {
234234
if (target instanceof Collection) {
235-
return parseTargetsIsExclude(((Collection) target).toArray(), isExclude);
235+
return parseTargetsIsExclude(((Collection<?>) target).toArray(), isExclude);
236236
} else if (target instanceof FileCollection) {
237237
return (FileCollection) target;
238238
} else if (target instanceof String) {
@@ -963,12 +963,12 @@ public PrettierConfig prettier(Map<String, String> devDependencies) {
963963
* offline, you can specify the path to the Rome executable via
964964
* {@code rome().pathToExe(...)}.
965965
*/
966-
public RomeGeneric rome() {
966+
public RomeStepConfig<?> rome() {
967967
return rome(null);
968968
}
969969

970970
/** Downloads the given Rome version from the network. */
971-
public RomeGeneric rome(String version) {
971+
public RomeStepConfig<?> rome(String version) {
972972
var romeConfig = new RomeGeneric(version);
973973
addStep(romeConfig.createStep());
974974
return romeConfig;

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JavascriptExtension.java

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,51 @@ public PrettierConfig prettier(Map<String, String> devDependencies) {
138138
return prettierConfig;
139139
}
140140

141+
/**
142+
* Defaults to downloading the default Rome version from the network. To work
143+
* offline, you can specify the path to the Rome executable via
144+
* {@code rome().pathToExe(...)}.
145+
*/
146+
public RomeJs rome() {
147+
return rome(null);
148+
}
149+
150+
/** Downloads the given Rome version from the network. */
151+
public RomeJs rome(String version) {
152+
var romeConfig = new RomeJs(version);
153+
addStep(romeConfig.createStep());
154+
return romeConfig;
155+
}
156+
141157
private static final String DEFAULT_PRETTIER_JS_PARSER = "babel";
142158
private static final ImmutableList<String> PRETTIER_JS_PARSERS = ImmutableList.of(DEFAULT_PRETTIER_JS_PARSER, "babel-flow", "flow");
143159

160+
/**
161+
* Rome formatter step for JavaScript.
162+
*/
163+
public class RomeJs extends RomeStepConfig<RomeJs> {
164+
165+
/**
166+
* Creates a new Rome formatter step config for formatting JavaScript files. Unless
167+
* overwritten, the given Rome version is downloaded from the network.
168+
*
169+
* @param version Rome version to use.
170+
*/
171+
public RomeJs(String version) {
172+
super(getProject(), JavascriptExtension.this::replaceStep, version);
173+
}
174+
175+
@Override
176+
protected String getLanguage() {
177+
return "js?";
178+
}
179+
180+
@Override
181+
protected RomeJs getThis() {
182+
return this;
183+
}
184+
}
185+
144186
/**
145187
* Overrides the parser to be set to a js parser.
146188
*/

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/JsonExtension.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,22 @@ public JacksonJsonGradleConfig jackson() {
5555
return new JacksonJsonGradleConfig(this);
5656
}
5757

58+
/**
59+
* Defaults to downloading the default Rome version from the network. To work
60+
* offline, you can specify the path to the Rome executable via
61+
* {@code rome().pathToExe(...)}.
62+
*/
63+
public RomeJson rome() {
64+
return rome(null);
65+
}
66+
67+
/** Downloads the given Rome version from the network. */
68+
public RomeJson rome(String version) {
69+
var romeConfig = new RomeJson(version);
70+
addStep(romeConfig.createStep());
71+
return romeConfig;
72+
}
73+
5874
public class SimpleConfig {
5975
private int indent;
6076

@@ -145,4 +161,29 @@ protected final FormatterStep createStep() {
145161
return JacksonJsonStep.create(jacksonConfig, version, formatExtension.provisioner());
146162
}
147163
}
164+
165+
/**
166+
* Rome formatter step for JSON.
167+
*/
168+
public class RomeJson extends RomeStepConfig<RomeJson> {
169+
/**
170+
* Creates a new Rome formatter step config for formatting JSON files. Unless
171+
* overwritten, the given Rome version is downloaded from the network.
172+
*
173+
* @param version Rome version to use.
174+
*/
175+
public RomeJson(String version) {
176+
super(getProject(), JsonExtension.this::replaceStep, version);
177+
}
178+
179+
@Override
180+
protected String getLanguage() {
181+
return "json";
182+
}
183+
184+
@Override
185+
protected RomeJson getThis() {
186+
return this;
187+
}
188+
}
148189
}

plugin-gradle/src/main/java/com/diffplug/gradle/spotless/TypescriptExtension.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,47 @@ protected EslintConfig eslintConfig() {
229229
}
230230
}
231231

232+
/**
233+
* Defaults to downloading the default Rome version from the network. To work
234+
* offline, you can specify the path to the Rome executable via
235+
* {@code rome().pathToExe(...)}.
236+
*/
237+
public RomeTs rome() {
238+
return rome(null);
239+
}
240+
241+
/** Downloads the given Rome version from the network. */
242+
public RomeTs rome(String version) {
243+
var romeConfig = new RomeTs(version);
244+
addStep(romeConfig.createStep());
245+
return romeConfig;
246+
}
247+
248+
/**
249+
* Rome formatter step for TypeScript.
250+
*/
251+
public class RomeTs extends RomeStepConfig<RomeTs> {
252+
/**
253+
* Creates a new Rome formatter step config for formatting TypeScript files. Unless
254+
* overwritten, the given Rome version is downloaded from the network.
255+
*
256+
* @param version Rome version to use.
257+
*/
258+
public RomeTs(String version) {
259+
super(getProject(), TypescriptExtension.this::replaceStep, version);
260+
}
261+
262+
@Override
263+
protected String getLanguage() {
264+
return "ts?";
265+
}
266+
267+
@Override
268+
protected RomeTs getThis() {
269+
return this;
270+
}
271+
}
272+
232273
@Override
233274
protected void setupTask(SpotlessTask task) {
234275
if (target == null) {

0 commit comments

Comments
 (0)