Skip to content

Commit

Permalink
documenting the community-plugin benefit and adding more examples
Browse files Browse the repository at this point in the history
  • Loading branch information
simschla committed Jun 11, 2020
1 parent 6f8c550 commit 89b99a4
Show file tree
Hide file tree
Showing 4 changed files with 841 additions and 1 deletion.
22 changes: 21 additions & 1 deletion plugin-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -468,8 +468,28 @@ spotless {
}
```

<a name="prettier-plugins"></a>
### Using community plugins for prettier

Since spotless uses the actual npm prettier package behind the scenes, it is possible to use prettier with
community-plugins in order to support even more file types.

```gradle
spotless {
format 'prettierJava', {
target '**/*.java'
prettier(['prettier': '2.0.5', 'prettier-plugin-java': '0.8.0']).config(['parser': 'java', 'tabWidth': 4])
}
format 'php', {
target '**/*.php'
prettier(['prettier': '2.0.5', '@prettier/plugin-php': '0.14.2']).config(['parser': 'php', 'tabWidth': 3])
}
}
```

<a name="typescript-prettier"></a>
Prettier can also be applied from within the [typescript config block](#typescript-formatter):
### Note: Prettier can also be applied from within the [typescript config block](#typescript-formatter)

```gradle
spotless {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,29 @@ public void useJavaCommunityPlugin() throws IOException {
Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
assertFile("JavaTest.java").sameAsResource("npm/prettier/plugins/java-test.clean");
}

@Test
public void usePhpCommunityPlugin() throws IOException {
setFile("build.gradle").toLines(
"buildscript { repositories { mavenCentral() } }",
"plugins {",
" id 'com.diffplug.gradle.spotless'",
"}",
"def prettierConfig = [:]",
"prettierConfig['tabWidth'] = 3",
"prettierConfig['parser'] = 'php'",
"def prettierPackages = [:]",
"prettierPackages['prettier'] = '2.0.5'",
"prettierPackages['@prettier/plugin-php'] = '0.14.2'",
"spotless {",
" format 'php', {",
" target 'php-example.php'",
" prettier(prettierPackages).config(prettierConfig)",
" }",
"}");
setFile("php-example.php").toResource("npm/prettier/plugins/php.dirty");
final BuildResult spotlessApply = gradleRunner().withArguments("--stacktrace", "spotlessApply").build();
Assertions.assertThat(spotlessApply.getOutput()).contains("BUILD SUCCESSFUL");
assertFile("php-example.php").sameAsResource("npm/prettier/plugins/php.clean");
}
}
Loading

0 comments on commit 89b99a4

Please sign in to comment.