Skip to content

Commit 0808fc2

Browse files
committed
documenting the community-plugin benefit and adding more examples
1 parent 6f8c550 commit 0808fc2

File tree

5 files changed

+841
-2
lines changed

5 files changed

+841
-2
lines changed

lib/src/main/resources/com/diffplug/spotless/npm/prettier-serve.js

-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ app.post("/prettier/format", (req, res) => {
5555

5656
var formatted_file_content = "";
5757
try {
58-
console.log("format_data", format_data);
5958
formatted_file_content = prettier.format(format_data.file_content, format_data.config_options);
6059
} catch(err) {
6160
res.status(501).send("Error while formatting: " + err);

plugin-gradle/README.md

+21-1
Original file line numberDiff line numberDiff line change
@@ -468,8 +468,28 @@ spotless {
468468
}
469469
```
470470

471+
<a name="prettier-plugins"></a>
472+
### Using community plugins for prettier
473+
474+
Since spotless uses the actual npm prettier package behind the scenes, it is possible to use prettier with
475+
community-plugins in order to support even more file types.
476+
477+
```gradle
478+
spotless {
479+
format 'prettierJava', {
480+
target '**/*.java'
481+
482+
prettier(['prettier': '2.0.5', 'prettier-plugin-java': '0.8.0']).config(['parser': 'java', 'tabWidth': 4])
483+
}
484+
format 'php', {
485+
target '**/*.php'
486+
prettier(['prettier': '2.0.5', '@prettier/plugin-php': '0.14.2']).config(['parser': 'php', 'tabWidth': 3])
487+
}
488+
}
489+
```
490+
471491
<a name="typescript-prettier"></a>
472-
Prettier can also be applied from within the [typescript config block](#typescript-formatter):
492+
### Note: Prettier can also be applied from within the [typescript config block](#typescript-formatter)
473493

474494
```gradle
475495
spotless {

plugin-gradle/src/test/java/com/diffplug/gradle/spotless/PrettierIntegrationTest.java

+25
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,29 @@ public void useJavaCommunityPlugin() throws IOException {
9292
Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
9393
assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean");
9494
}
95+
96+
@Test
97+
public void usePhpCommunityPlugin() throws IOException {
98+
setFile("build.gradle").toLines(
99+
"buildscript { repositories { mavenCentral() } }",
100+
"plugins {",
101+
" id 'com.diffplug.gradle.spotless'",
102+
"}",
103+
"def prettierConfig = [:]",
104+
"prettierConfig['tabWidth'] = 3",
105+
"prettierConfig['parser'] = 'php'",
106+
"def prettierPackages = [:]",
107+
"prettierPackages['prettier'] = '2.0.5'",
108+
"prettierPackages['@prettier/plugin-php'] = '0.14.2'",
109+
"spotless {",
110+
" format 'php', {",
111+
" target 'php-example.php'",
112+
" prettier(prettierPackages).config(prettierConfig)",
113+
" }",
114+
"}");
115+
setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty");
116+
final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
117+
Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
118+
assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean");
119+
}
95120
}

0 commit comments

Comments
 (0)