Skip to content

Commit d91be60

Browse files
hyperz111iiroj
authored andcommitted
docs: update readme to use picomatch
1 parent b392a9f commit d91be60

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

README.md

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ _Lint-staged_ can be configured in many ways:
227227
whether your project's _package.json_ contains the `"type": "module"` option or not.
228228
- Pass a configuration file using the `--config` or `-c` flag
229229

230-
Configuration should be an object where each value is a **command** to run and its key is a glob pattern to use for this command. This package uses [micromatch](https://github.com/micromatch/micromatch) for glob patterns. JavaScript files can also export advanced configuration as a function. See [Using JS configuration files](#using-js-configuration-files) for more info.
230+
Configuration should be an object where each value is a **command** to run and its key is a glob pattern to use for this command. This package uses [picomatch](https://github.com/micromatch/picomatch) for glob patterns. JavaScript files can also export advanced configuration as a function. See [Using JS configuration files](#using-js-configuration-files) for more info.
231231

232232
You can also place multiple configuration files in different directories inside a project. For a given staged file, the closest configuration file will always be used. See ["How to use `lint-staged` in a multi-package monorepo?"](#how-to-use-lint-staged-in-a-multi-package-monorepo) for more info and an example.
233233

@@ -329,9 +329,9 @@ Or, if necessary, you can limit the concurrency using `--concurrent <number>` or
329329

330330
## Filtering files
331331

332-
Task commands work on a subset of all staged files, defined by a _glob pattern_. lint-staged uses [micromatch](https://github.com/micromatch/micromatch) for matching files with the following rules:
332+
Task commands work on a subset of all staged files, defined by a _glob pattern_. lint-staged uses [picomatch](https://github.com/micromatch/picomatch) for matching files with the following rules:
333333

334-
- If the glob pattern contains no slashes (`/`), micromatch's `matchBase` option will be enabled, so globs match a file's basename regardless of directory:
334+
- If the glob pattern contains no slashes (`/`), picomatch's `matchBase` option will be enabled, so globs match a file's basename regardless of directory:
335335
- `"*.js"` will match all JS files, like `/test.js` and `/foo/bar/test.js`
336336
- `"!(*test).js"` will match all JS files, except those ending in `test.js`, so `foo.js` but not `foo.test.js`
337337
- `"!(*.css|*.js)"` will match all files except CSS and JS files
@@ -432,15 +432,15 @@ export default {
432432

433433
```js
434434
// lint-staged.config.js
435-
import micromatch from 'micromatch'
435+
import picomatch from 'picomatch'
436436

437437
export default (allStagedFiles) => {
438-
const shFiles = micromatch(allStagedFiles, ['**/src/**/*.sh'])
438+
const shFiles = allStagedFiles.filter((file) => picomatch.isMatch(file, ['**/src/**/*.sh']))
439439
if (shFiles.length) {
440440
return `printf '%s\n' "Script files aren't allowed in src directory" >&2`
441441
}
442-
const codeFiles = micromatch(allStagedFiles, ['**/*.js', '**/*.ts'])
443-
const docFiles = micromatch(allStagedFiles, ['**/*.md'])
442+
const codeFiles = allStagedFiles.filter((file) => picomatch.isMatch(file, ['**/*.js', '**/*.ts']))
443+
const docFiles = allStagedFiles.filter((file) => picomatch.isMatch(file, ['**/*.md']))
444444
return [`eslint ${codeFiles.join(' ')}`, `mdl ${docFiles.join(' ')}`]
445445
}
446446
```
@@ -499,12 +499,12 @@ It's better to use the [function-based configuration (seen above)](https://githu
499499

500500
```js
501501
// lint-staged.config.js
502-
import micromatch from 'micromatch'
502+
import picomatch from 'picomatch'
503503

504504
export default {
505505
'*': (allFiles) => {
506-
const codeFiles = micromatch(allFiles, ['**/*.js', '**/*.ts'])
507-
const docFiles = micromatch(allFiles, ['**/*.md'])
506+
const codeFiles = allFiles.filter((file) => picomatch.isMatch(file, ['**/*.js', '**/*.ts']))
507+
const docFiles = allFiles.filter((file) => picomatch.isMatch(file, ['**/*.md']))
508508
return [`eslint ${codeFiles.join(' ')}`, `mdl ${docFiles.join(' ')}`]
509509
},
510510
}
@@ -517,16 +517,16 @@ export default {
517517
<details>
518518
<summary>Click to expand</summary>
519519

520-
If for some reason you want to ignore files from the glob match, you can use `micromatch.not()`:
520+
If for some reason you want to ignore files from the glob match, you can use `picomatch.isMatch()` with negated pattern(s):
521521

522522
```js
523523
// lint-staged.config.js
524-
import micromatch from 'micromatch'
524+
import picomatch from 'picomatch'
525525

526526
export default {
527527
'*.js': (files) => {
528528
// from `files` filter those _NOT_ matching `*test.js`
529-
const match = micromatch.not(files, '*test.js')
529+
const match = files.filter((file) => picomatch.isMatch(file, '!*test.js'))
530530
return `eslint ${match.join(' ')}`
531531
},
532532
}

0 commit comments

Comments
 (0)