d9d914a512454f6fd2daba8f28e4cb3cfaff74651440ad921d48cfe126392f05030bcd2766bb6c480b60079fb6f5a916f0696903738377076e26b6bdc08669 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. # 🚫💩 lint-staged ![GitHub Actions](https://github.com/okonet/lint-staged/workflows/CI/badge.svg) [![Build Status for Windows](https://ci.appveyor.com/api/projects/status/github/okonet/lint-staged?branch=master&svg=true)](https://ci.appveyor.com/project/okonet/lint-staged) [![npm version](https://badge.fury.io/js/lint-staged.svg)](https://badge.fury.io/js/lint-staged) [![Codecov](https://codecov.io/gh/okonet/lint-staged/branch/master/graph/badge.svg)](https://codecov.io/gh/okonet/lint-staged)
  2. Run linters against staged git files and don't let :poop: slip into your code base!
  3. [![asciicast](https://asciinema.org/a/199934.svg)](https://asciinema.org/a/199934)
  4. ## Why
  5. Linting makes more sense when run before committing your code. By doing so you can ensure no errors go into the repository and enforce code style. But running a lint process on a whole project is slow and linting results can be irrelevant. Ultimately you only want to lint files that will be committed.
  6. This project contains a script that will run arbitrary shell tasks with a list of staged files as an argument, filtered by a specified glob pattern.
  7. ## Related blogs posts and talks
  8. - [Introductory Medium post - Andrey Okonetchnikov, 2016](https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8#.8qepn2b5l)
  9. - [Running Jest Tests Before Each Git Commit - Ben McCormick, 2017](https://benmccormick.org/2017/02/26/running-jest-tests-before-each-git-commit/)
  10. - [AgentConf presentation - Andrey Okonetchnikov, 2018](https://www.youtube.com/watch?v=-mhY7e-EsC4)
  11. - [SurviveJS interview - Juho Vepsäläinen and Andrey Okonetchnikov, 2018](https://survivejs.com/blog/lint-staged-interview/)
  12. > If you've written one, please submit a PR with the link to it!
  13. ## Installation and setup
  14. The fastest way to start using lint-staged is to run following command in your terminal:
  15. ```bash
  16. npx mrm lint-staged
  17. ```
  18. It will install and configure [husky](https://github.com/typicode/husky) and lint-staged depending on code quality tools from `package.json` dependencies so please make sure you install (`npm install --save-dev`) and configure all code quality tools like [Prettier](https://prettier.io), [ESlint](https://eslint.org) prior that.
  19. Don't forget to commit changes to `package.json` to share this setup with your team!
  20. Now change a few files, `git add` or `git add --patch` some of them to your commit and try to `git commit` them.
  21. See [examples](#examples) and [configuration](#configuration) for more information.
  22. ## Changelog
  23. See [Releases](https://github.com/okonet/lint-staged/releases)
  24. ### Migration
  25. #### v10
  26. - From `v10.0.0` onwards any new modifications to originally staged files will be automatically added to the commit.
  27. If your task previously contained a `git add` step, please remove this.
  28. The automatic behaviour ensures there are less race-conditions,
  29. since trying to run multiple git operations at the same time usually results in an error.
  30. - From `v10.0.0` onwards _lint-staged_ uses git stashes to improve speed and provide backups while running.
  31. Since git stashes require at least an initial commit, you shouldn't run _lint-staged_ in an empty repo.
  32. - From `v10.0.0` onwards _lint-staged_ requires Node.js version 10.13.0 or later.
  33. - From `v10.0.0` onwards _lint-staged_ will abort the commit if linter tasks undo all staged changes. To allow creating empty commit, please use the `--allow-empty` option.
  34. ## Command line flags
  35. ```bash
  36. ❯ npx lint-staged --help
  37. Usage: lint-staged [options]
  38. Options:
  39. -V, --version output the version number
  40. --allow-empty allow empty commits when tasks revert all staged changes
  41. (default: false)
  42. -c, --config [path] path to configuration file, or - to read from stdin
  43. -d, --debug print additional debug information (default: false)
  44. --no-stash disable the backup stash, and do not revert in case of
  45. errors
  46. -p, --concurrent <parallel tasks> the number of tasks to run concurrently, or false to run
  47. tasks serially (default: true)
  48. -q, --quiet disable lint-staged’s own console output (default: false)
  49. -r, --relative pass relative filepaths to tasks (default: false)
  50. -x, --shell skip parsing of tasks for better shell support (default:
  51. false)
  52. -v, --verbose show task output even when tasks succeed; by default only
  53. failed output is shown (default: false)
  54. -h, --help display help for command
  55. ```
  56. - **`--allow-empty`**: By default, when linter tasks undo all staged changes, lint-staged will exit with an error and abort the commit. Use this flag to allow creating empty git commits.
  57. - **`--config [path]`**: Manually specify a path to a config file or npm package name. Note: when used, lint-staged won't perform the config file search and print an error if the specified file cannot be found. If '-' is provided as the filename then the config will be read from stdin, allowing piping in the config like `cat my-config.json | npx lint-staged --config -`.
  58. - **`--debug`**: Run in debug mode. When set, it does the following:
  59. - uses [debug](https://github.com/visionmedia/debug) internally to log additional information about staged files, commands being executed, location of binaries, etc. Debug logs, which are automatically enabled by passing the flag, can also be enabled by setting the environment variable `$DEBUG` to `lint-staged*`.
  60. - uses [`verbose` renderer](https://github.com/SamVerschueren/listr-verbose-renderer) for `listr`; this causes serial, uncoloured output to the terminal, instead of the default (beautified, dynamic) output.
  61. - **`--concurrent [number | (true/false)]`**: Controls the concurrency of tasks being run by lint-staged. **NOTE**: This does NOT affect the concurrency of subtasks (they will always be run sequentially). Possible values are:
  62. - `false`: Run all tasks serially
  63. - `true` (default) : _Infinite_ concurrency. Runs as many tasks in parallel as possible.
  64. - `{number}`: Run the specified number of tasks in parallel, where `1` is equivalent to `false`.
  65. - **`--no-stash`**: By default a backup stash will be created before running the tasks, and all task modifications will be reverted in case of an error. This option will disable creating the stash, and instead leave all modifications in the index when aborting the commit.
  66. - **`--quiet`**: Supress all CLI output, except from tasks.
  67. - **`--relative`**: Pass filepaths relative to `process.cwd()` (where `lint-staged` runs) to tasks. Default is `false`.
  68. - **`--shell`**: By default linter commands will be parsed for speed and security. This has the side-effect that regular shell scripts might not work as expected. You can skip parsing of commands with this option.
  69. - **`--verbose`**: Show task output even when tasks succeed. By default only failed output is shown.
  70. ## Configuration
  71. Starting with v3.1 you can now use different ways of configuring it:
  72. - `lint-staged` object in your `package.json`
  73. - `.lintstagedrc` file in JSON or YML format, or you can be explicit with the file extension:
  74. - `.lintstagedrc.json`
  75. - `.lintstagedrc.yaml`
  76. - `.lintstagedrc.yml`
  77. - `lint-staged.config.js`, `.lintstagedrc.js`, or `.lintstagedrc.cjs` file in JS format
  78. - Pass a configuration file using the `--config` or `-c` flag
  79. See [cosmiconfig](https://github.com/davidtheclark/cosmiconfig) for more details on what formats are supported.
  80. 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.
  81. #### `package.json` example:
  82. ```json
  83. {
  84. "lint-staged": {
  85. "*": "your-cmd"
  86. }
  87. }
  88. ```
  89. #### `.lintstagedrc` example
  90. ```json
  91. {
  92. "*": "your-cmd"
  93. }
  94. ```
  95. This config will execute `your-cmd` with the list of currently staged files passed as arguments.
  96. So, considering you did `git add file1.ext file2.ext`, lint-staged will run the following command:
  97. `your-cmd file1.ext file2.ext`
  98. ## Filtering files
  99. Linter 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:
  100. - If the glob pattern contains no slashes (`/`), micromatch's `matchBase` option will enabled, so globs match a file's basename regardless of directory:
  101. - **`"*.js"`** will match all JS files, like `/test.js` and `/foo/bar/test.js`
  102. - **`"!(*test).js"`**. will match all JS files, except those ending in `test.js`, so `foo.js` but not `foo.test.js`
  103. - If the glob pattern does contain a slash (`/`), it will match for paths as well:
  104. - **`"./*.js"`** will match all JS files in the git repo root, so `/test.js` but not `/foo/bar/test.js`
  105. - **`"foo/**/\*.js"`** will match all JS files inside the`/foo`directory, so`/foo/bar/test.js`but not`/test.js`
  106. When matching, `lint-staged` will do the following
  107. - Resolve the git root automatically, no configuration needed.
  108. - Pick the staged files which are present inside the project directory.
  109. - Filter them using the specified glob patterns.
  110. - Pass absolute paths to the linters as arguments.
  111. **NOTE:** `lint-staged` will pass _absolute_ paths to the linters to avoid any confusion in case they're executed in a different working directory (i.e. when your `.git` directory isn't the same as your `package.json` directory).
  112. Also see [How to use `lint-staged` in a multi package monorepo?](#how-to-use-lint-staged-in-a-multi-package-monorepo)
  113. ### Ignoring files
  114. The concept of `lint-staged` is to run configured linter (or other) tasks on files that are staged in git. `lint-staged` will always pass a list of all staged files to the task, and ignoring any files should be configured in the task itself.
  115. Consider a project that uses [`prettier`](https://prettier.io/) to keep code format consistent across all files. The project also stores minified 3rd-party vendor libraries in the `vendor/` directory. To keep `prettier` from throwing errors on these files, the vendor directory should be added to prettier's ignore configuration, the `.prettierignore` file. Running `npx prettier .` will ignore the entire vendor directory, throwing no errors. When `lint-staged` is added to the project and configured to run prettier, all modified and staged files in the vendor directory will be ignored by prettier, even though it receives them as input.
  116. In advanced scenarios, where it is impossible to configure the linter task itself to ignore files, but some staged files should still be ignored by `lint-staged`, it is possible to filter filepaths before passing them to tasks by using the function syntax. See [Example: Ignore files from match](#example-ignore-files-from-match).
  117. ## What commands are supported?
  118. Supported are any executables installed locally or globally via `npm` as well as any executable from your \$PATH.
  119. > Using globally installed scripts is discouraged, since lint-staged may not work for someone who doesn’t have it installed.
  120. `lint-staged` uses [execa](https://github.com/sindresorhus/execa#preferlocal) to locate locally installed scripts. So in your `.lintstagedrc` you can write:
  121. ```json
  122. {
  123. "*.js": "eslint --fix"
  124. }
  125. ```
  126. Pass arguments to your commands separated by space as you would do in the shell. See [examples](#examples) below.
  127. ## Running multiple commands in a sequence
  128. You can run multiple commands in a sequence on every glob. To do so, pass an array of commands instead of a single one. This is useful for running autoformatting tools like `eslint --fix` or `stylefmt` but can be used for any arbitrary sequences.
  129. For example:
  130. ```json
  131. {
  132. "*.js": ["eslint", "prettier --write"]
  133. }
  134. ```
  135. going to execute `eslint` and if it exits with `0` code, it will execute `prettier --write` on all staged `*.js` files.
  136. ## Using JS configuration file
  137. Writing the configuration file in JavaScript is the most powerful way to configure _lint-staged_ (`lint-staged.config.js`, [similar](https://github.com/okonet/lint-staged/README.md#configuration), or passed via `--config`). From the configuration file, you can export either a single function, or an object.
  138. If the `exports` value is a function, it will receive an array of all staged filenames. You can then build your own matchers for the files, and return a command string, or an array or command strings. These strings are considered complete and should include the filename arguments, if wanted.
  139. If the `exports` value is an object, its keys should be glob matches (like in the normal non-js config format). The values can either be like in the normal config, or individual functions like described above. Instead of receiving all matched files, the functions in the exported object will only receive the staged files matching the corresponding glob key.
  140. ### Function signature
  141. The function can also be async:
  142. ```ts
  143. (filenames: string[]) => string | string[] | Promise<string | string[]>
  144. ```
  145. ### Example: Export a function to build your own matchers
  146. ```js
  147. // lint-staged.config.js
  148. const micromatch = require('micromatch')
  149. module.exports = (allStagedFiles) => {
  150. const shFiles = micromatch(allStagedFiles, ['**/src/**/*.sh']);
  151. if (shFiles.length) {
  152. return `printf '%s\n' "Script files aren't allowed in src directory" >&2`
  153. }
  154. const codeFiles = micromatch(allStagedFiles, ['**/*.js', '**/*.ts']);
  155. const docFiles = micromatch(allStagedFiles, ['**/*.md']);
  156. return [`eslint ${codeFiles.join(' ')}`, `mdl ${docFiles.join(' ')}`];
  157. }
  158. ```
  159. ### Example: Wrap filenames in single quotes and run once per file
  160. ```js
  161. // .lintstagedrc.js
  162. module.exports = {
  163. '**/*.js?(x)': (filenames) => filenames.map((filename) => `prettier --write '${filename}'`)
  164. }
  165. ```
  166. ### Example: Run `tsc` on changes to TypeScript files, but do not pass any filename arguments
  167. ```js
  168. // lint-staged.config.js
  169. module.exports = {
  170. '**/*.ts?(x)': () => 'tsc -p tsconfig.json --noEmit'
  171. }
  172. ```
  173. ### Example: Run eslint on entire repo if more than 10 staged files
  174. ```js
  175. // .lintstagedrc.js
  176. module.exports = {
  177. '**/*.js?(x)': (filenames) =>
  178. filenames.length > 10 ? 'eslint .' : `eslint ${filenames.join(' ')}`
  179. }
  180. ```
  181. ### Example: Use your own globs
  182. It's better to use the [function-based configuration (seen above)](https://github.com/okonet/lint-staged/README.md#example-export-a-function-to-build-your-own-matchers), if your use case is this.
  183. ```js
  184. // lint-staged.config.js
  185. const micromatch = require('micromatch')
  186. module.exports = {
  187. '*': (allFiles) => {
  188. const codeFiles = micromatch(allFiles, ['**/*.js', '**/*.ts']);
  189. const docFiles = micromatch(allFiles, ['**/*.md']);
  190. return [`eslint ${codeFiles.join(' ')}`, `mdl ${docFiles.join(' ')}`];
  191. }
  192. }
  193. ```
  194. ### Example: Ignore files from match
  195. If for some reason you want to ignore files from the glob match, you can use `micromatch.not()`:
  196. ```js
  197. // lint-staged.config.js
  198. const micromatch = require('micromatch')
  199. module.exports = {
  200. '*.js': (files) => {
  201. // from `files` filter those _NOT_ matching `*test.js`
  202. const match = micromatch.not(files, '*test.js')
  203. return `eslint ${match.join(' ')}`
  204. }
  205. }
  206. ```
  207. Please note that for most cases, globs can achieve the same effect. For the above example, a matching glob would be `!(*test).js`.
  208. ### Example: Use relative paths for commands
  209. ```js
  210. const path = require('path')
  211. module.exports = {
  212. '*.ts': (absolutePaths) => {
  213. const cwd = process.cwd()
  214. const relativePaths = absolutePaths.map((file) => path.relative(cwd, file))
  215. return `ng lint myProjectName --files ${relativePaths.join(' ')}`
  216. }
  217. }
  218. ```
  219. ## Reformatting the code
  220. Tools like [Prettier](https://prettier.io), ESLint/TSLint, or stylelint can reformat your code according to an appropriate config by running `prettier --write`/`eslint --fix`/`tslint --fix`/`stylelint --fix`. Lint-staged will automatically add any modifications to the commit as long as there are no errors.
  221. ```json
  222. {
  223. "*.js": "prettier --write"
  224. }
  225. ```
  226. Prior to version 10, tasks had to manually include `git add` as the final step. This behavior has been integrated into lint-staged itself in order to prevent race conditions with multiple tasks editing the same files. If lint-staged detects `git add` in task configurations, it will show a warning in the console. Please remove `git add` from your configuration after upgrading.
  227. ## Examples
  228. All examples assuming you’ve already set up lint-staged and husky in the `package.json`.
  229. ```json
  230. {
  231. "name": "My project",
  232. "version": "0.1.0",
  233. "scripts": {
  234. "my-custom-script": "linter --arg1 --arg2"
  235. },
  236. "husky": {
  237. "hooks": {
  238. "pre-commit": "lint-staged"
  239. }
  240. },
  241. "lint-staged": {}
  242. }
  243. ```
  244. _Note we don’t pass a path as an argument for the runners. This is important since lint-staged will do this for you._
  245. ### ESLint with default parameters for `*.js` and `*.jsx` running as a pre-commit hook
  246. ```json
  247. {
  248. "*.{js,jsx}": "eslint"
  249. }
  250. ```
  251. ### Automatically fix code style with `--fix` and add to commit
  252. ```json
  253. {
  254. "*.js": "eslint --fix"
  255. }
  256. ```
  257. This will run `eslint --fix` and automatically add changes to the commit.
  258. ### Reuse npm script
  259. If you wish to reuse a npm script defined in your package.json:
  260. ```json
  261. {
  262. "*.js": "npm run my-custom-script --"
  263. }
  264. ```
  265. The following is equivalent:
  266. ```json
  267. {
  268. "*.js": "linter --arg1 --arg2"
  269. }
  270. ```
  271. ### Use environment variables with linting commands
  272. Linting commands _do not_ support the shell convention of expanding environment variables. To enable the convention yourself, use a tool like [`cross-env`](https://github.com/kentcdodds/cross-env).
  273. For example, here is `jest` running on all `.js` files with the `NODE_ENV` variable being set to `"test"`:
  274. ```json
  275. {
  276. "*.js": ["cross-env NODE_ENV=test jest --bail --findRelatedTests"]
  277. }
  278. ```
  279. ### Automatically fix code style with `prettier` for javascript, typescript, markdown, HTML, or CSS
  280. ```json
  281. {
  282. "*.{js,jsx,ts,tsx,md,html,css}": "prettier --write"
  283. }
  284. ```
  285. ### Stylelint for CSS with defaults and for SCSS with SCSS syntax
  286. ```json
  287. {
  288. "*.css": "stylelint",
  289. "*.scss": "stylelint --syntax=scss"
  290. }
  291. ```
  292. ### Run PostCSS sorting and Stylelint to check
  293. ```json
  294. {
  295. "*.scss": ["postcss --config path/to/your/config --replace", "stylelint"]
  296. }
  297. ```
  298. ### Minify the images
  299. ```json
  300. {
  301. "*.{png,jpeg,jpg,gif,svg}": "imagemin-lint-staged"
  302. }
  303. ```
  304. <details>
  305. <summary>More about <code>imagemin-lint-staged</code></summary>
  306. [imagemin-lint-staged](https://github.com/tomchentw/imagemin-lint-staged) is a CLI tool designed for lint-staged usage with sensible defaults.
  307. See more on [this blog post](https://medium.com/@tomchentw/imagemin-lint-staged-in-place-minify-the-images-before-adding-to-the-git-repo-5acda0b4c57e) for benefits of this approach.
  308. </details>
  309. ### Typecheck your staged files with flow
  310. ```json
  311. {
  312. "*.{js,jsx}": "flow focus-check"
  313. }
  314. ```
  315. ## Frequently Asked Questions
  316. ### Can I use `lint-staged` via node?
  317. Yes!
  318. ```js
  319. const lintStaged = require('lint-staged')
  320. try {
  321. const success = await lintStaged()
  322. console.log(success ? 'Linting was successful!' : 'Linting failed!')
  323. } catch (e) {
  324. // Failed to load configuration
  325. console.error(e)
  326. }
  327. ```
  328. Parameters to `lintStaged` are equivalent to their CLI counterparts:
  329. ```js
  330. const success = await lintStaged({
  331. allowEmpty: false,
  332. concurrent: true,
  333. configPath: './path/to/configuration/file',
  334. cwd: process.cwd(),
  335. debug: false,
  336. maxArgLength: null,
  337. quiet: false,
  338. relative: false,
  339. shell: false
  340. stash: true,
  341. verbose: false
  342. })
  343. ```
  344. You can also pass config directly with `config` option:
  345. ```js
  346. const success = await lintStaged({
  347. allowEmpty: false,
  348. concurrent: true,
  349. config: { '*.js': 'eslint --fix' },
  350. cwd: process.cwd(),
  351. debug: false,
  352. maxArgLength: null,
  353. quiet: false,
  354. relative: false,
  355. shell: false,
  356. stash: true,
  357. verbose: false
  358. })
  359. ```
  360. The `maxArgLength` option configures chunking of tasks into multiple parts that are run one after the other. This is to avoid issues on Windows platforms where the maximum length of the command line argument string is limited to 8192 characters. Lint-staged might generate a very long argument string when there are many staged files. This option is set automatically from the cli, but not via the Node.js API by default.
  361. ### Using with JetBrains IDEs _(WebStorm, PyCharm, IntelliJ IDEA, RubyMine, etc.)_
  362. _**Update**_: The latest version of JetBrains IDEs now support running hooks as you would expect.
  363. When using the IDE's GUI to commit changes with the `precommit` hook, you might see inconsistencies in the IDE and command line. This is [known issue](https://youtrack.jetbrains.com/issue/IDEA-135454) at JetBrains so if you want this fixed, please vote for it on YouTrack.
  364. Until the issue is resolved in the IDE, you can use the following config to work around it:
  365. husky v1.x
  366. ```json
  367. {
  368. "husky": {
  369. "hooks": {
  370. "pre-commit": "lint-staged",
  371. "post-commit": "git update-index --again"
  372. }
  373. }
  374. }
  375. ```
  376. husky v0.x
  377. ```json
  378. {
  379. "scripts": {
  380. "precommit": "lint-staged",
  381. "postcommit": "git update-index --again"
  382. }
  383. }
  384. ```
  385. _Thanks to [this comment](https://youtrack.jetbrains.com/issue/IDEA-135454#comment=27-2710654) for the fix!_
  386. ### How to use `lint-staged` in a multi package monorepo?
  387. Starting with v5.0, `lint-staged` automatically resolves the git root **without any** additional configuration. You configure `lint-staged` as you normally would if your project root and git root were the same directory.
  388. If you wish to use `lint-staged` in a multi package monorepo, it is recommended to install [`husky`](https://github.com/typicode/husky) in the root package.json.
  389. [`lerna`](https://github.com/lerna/lerna) can be used to execute the `precommit` script in all sub-packages.
  390. Example repo: [sudo-suhas/lint-staged-multi-pkg](https://github.com/sudo-suhas/lint-staged-multi-pkg).
  391. ### Can I lint files outside of the current project folder?
  392. tl;dr: Yes, but the pattern should start with `../`.
  393. By default, `lint-staged` executes linters only on the files present inside the project folder(where `lint-staged` is installed and run from).
  394. So this question is relevant _only_ when the project folder is a child folder inside the git repo.
  395. In certain project setups, it might be desirable to bypass this restriction. See [#425](https://github.com/okonet/lint-staged/issues/425), [#487](https://github.com/okonet/lint-staged/issues/487) for more context.
  396. `lint-staged` provides an escape hatch for the same(`>= v7.3.0`). For patterns that start with `../`, all the staged files are allowed to match against the pattern.
  397. Note that patterns like `*.js`, `**/*.js` will still only match the project files and not any of the files in parent or sibling directories.
  398. Example repo: [sudo-suhas/lint-staged-django-react-demo](https://github.com/sudo-suhas/lint-staged-django-react-demo).
  399. ### How can i ignore files from `.eslintignore` ?
  400. ESLint throws out `warning File ignored because of a matching ignore pattern. Use "--no-ignore" to override` warnings that breaks the linting process ( if you used `--max-warnings=0` which is recommended ).
  401. Based on the discussion from https://github.com/eslint/eslint/issues/9977 , it was decided that using [the outlined script ](https://github.com/eslint/eslint/issues/9977#issuecomment-406420893)is the best route to fix this.
  402. So you can setup a `.lintstagedrc.js` config file to do this:
  403. ```js
  404. const { CLIEngine } = require('eslint')
  405. const cli = new CLIEngine({})
  406. module.exports = {
  407. '*.js': (files) =>
  408. 'eslint --max-warnings=0 ' + files.filter((file) => !cli.isPathIgnored(file)).join(' ')
  409. }
  410. ```