Skip to content

Commit

Permalink
docs: simplify configuration example for formatting any format Pretti…
Browse files Browse the repository at this point in the history
…er supports (#997)
  • Loading branch information
TimonVS committed Aug 2, 2021
1 parent f7302f4 commit f8807d7
Showing 1 changed file with 4 additions and 26 deletions.
30 changes: 4 additions & 26 deletions README.md
Expand Up @@ -445,36 +445,14 @@ For example, here is `jest` running on all `.js` files with the `NODE_ENV` varia
</details>
### Automatically fix code style with `prettier` for any format prettier supports
### Automatically fix code style with `prettier` for any format Prettier supports
<details>
<summary>Click to expand</summary>
You need to add `micromatch` as a dev dependency.
```sh
$ npm i --save-dev micromatch
```
```js
// lint-staged.config.js
const micromatch = require('micromatch')
const prettier = require('prettier')
const prettierSupportedExtensions = prettier
.getSupportInfo()
.languages.map(({ extensions }) => extensions)
.flat()
const addQuotes = (a) => `"${a}"`
module.exports = (allStagedFiles) => {
const prettierFiles = micromatch(
allStagedFiles,
prettierSupportedExtensions.map((extension) => `**/*${extension}`)
)
return prettierFiles.length > 0
? [`prettier --write ${prettierFiles.map(addQuotes).join(' ')}`]
: []
```json
{
"*": "prettier --ignore-unknown --write"
}
```
Expand Down

0 comments on commit f8807d7

Please sign in to comment.