Skip to content

Update README.md to increase readability of prettier plugin configuration #2011

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 22, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions plugin-gradle/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1086,16 +1086,34 @@ To apply prettier to more kinds of files, just add more formats
Since spotless uses the actual npm prettier package behind the scenes, it is possible to use prettier with
[plugins](https://prettier.io/docs/en/plugins.html#official-plugins) or [community-plugins](https://www.npmjs.com/search?q=prettier-plugin) in order to support even more file types.

#### prettier version below 3

```gradle
spotless {
java {
prettier(['prettier': '2.8.8', 'prettier-plugin-java': '2.2.0']).config(['parser': 'java', 'tabWidth': 4])
// prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0']).config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']]) // Prettier v3 requires additional 'plugins' config
}
format 'php', {
target 'src/**/*.php'
prettier(['prettier': '2.8.8', '@prettier/plugin-php': '0.19.6']).config(['parser': 'php', 'tabWidth': 3])
// prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1']).config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']]) // Prettier v3 requires additional 'plugins' config
}
}
```

#### prettier version 3+

With version 3 prettier it is required to pass in an additional 'plugins' parameter to the config block with a list of plugins you want to use.

```gradle
spotless {
java {
prettier(['prettier': '3.0.3', 'prettier-plugin-java': '2.3.0'])
.config(['parser': 'java', 'tabWidth': 4, 'plugins': ['prettier-plugin-java']])
}
format 'php', {
target 'src/**/*.php'
prettier(['prettier': '3.0.3', '@prettier/plugin-php': '0.20.1'])
.config(['parser': 'php', 'tabWidth': 3, 'plugins': ['@prettier/plugin-php']])
}
}
```
Expand Down