lint-staged 15.4.1 → 15.4.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ---
6
6
 
7
- Run linters against staged git files and don't let :poop: slip into your code base!
7
+ Run tasks like formatters and linters against staged git files and don't let :poop: slip into your code base!
8
8
 
9
9
  ```bash
10
10
  npm install --save-dev lint-staged # requires further setup
@@ -36,7 +36,7 @@ $ git commit
36
36
 
37
37
  ## Why
38
38
 
39
- 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.
39
+ Code quality tasks like formatters and linters make 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 task on a whole project can be slow, and opinionated tasks such as linting can sometimes produce irrelevant results. Ultimately you only want to check files that will be committed.
40
40
 
41
41
  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.
42
42
 
@@ -59,8 +59,8 @@ To install _lint-staged_ in the recommended way, you need to:
59
59
  1. Set up the `pre-commit` git hook to run _lint-staged_
60
60
  - [Husky](https://github.com/typicode/husky) is a popular choice for configuring git hooks
61
61
  - Read more about git hooks [here](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
62
- 1. Install some linters, like [ESLint](https://eslint.org) or [Prettier](https://prettier.io)
63
- 1. Configure _lint-staged_ to run linters and other tasks:
62
+ 1. Install some tools like [ESLint](https://eslint.org) or [Prettier](https://prettier.io)
63
+ 1. Configure _lint-staged_ to run code checkers and other tasks:
64
64
  - for example: `{ "*.js": "eslint" }` to run ESLint for all staged JS files
65
65
  - See [Configuration](#configuration) for more info
66
66
 
@@ -142,7 +142,7 @@ Any lost modifications can be restored from a git stash:
142
142
  > git stash apply --index stash@{0}
143
143
  ```
144
144
 
145
- - **`--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.
145
+ - **`--allow-empty`**: By default, when 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.
146
146
  - **`--concurrent [number|boolean]`**: Controls the [concurrency of tasks](#task-concurrency) being run by lint-staged. **NOTE**: This does NOT affect the concurrency of subtasks (they will always be run sequentially). Possible values are:
147
147
  - `false`: Run all tasks serially
148
148
  - `true` (default) : _Infinite_ concurrency. Runs as many tasks in parallel as possible.
@@ -153,14 +153,14 @@ Any lost modifications can be restored from a git stash:
153
153
  - 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*`.
154
154
  - uses [`verbose` renderer](https://listr2.kilic.dev/renderers/verbose-renderer/) for `listr2`; this causes serial, uncoloured output to the terminal, instead of the default (beautified, dynamic) output.
155
155
  (the [`verbose` renderer](https://listr2.kilic.dev/renderers/verbose-renderer/) can also be activated by setting the `TERM=dumb` or `NODE_ENV=test` environment variables)
156
- - **`--diff`**: By default linters are filtered against all files staged in git, generated from `git diff --staged`. This option allows you to override the `--staged` flag with arbitrary revisions. For example to get a list of changed files between two branches, use `--diff="branch1...branch2"`. You can also read more from about [git diff](https://git-scm.com/docs/git-diff) and [gitrevisions](https://git-scm.com/docs/gitrevisions). This option also implies `--no-stash`.
156
+ - **`--diff`**: By default tasks are filtered against all files staged in git, generated from `git diff --staged`. This option allows you to override the `--staged` flag with arbitrary revisions. For example to get a list of changed files between two branches, use `--diff="branch1...branch2"`. You can also read more from about [git diff](https://git-scm.com/docs/git-diff) and [gitrevisions](https://git-scm.com/docs/gitrevisions). This option also implies `--no-stash`.
157
157
  - **`--diff-filter`**: By default only files that are _added_, _copied_, _modified_, or _renamed_ are included. Use this flag to override the default `ACMR` value with something else: _added_ (`A`), _copied_ (`C`), _deleted_ (`D`), _modified_ (`M`), _renamed_ (`R`), _type changed_ (`T`), _unmerged_ (`U`), _unknown_ (`X`), or _pairing broken_ (`B`). See also the `git diff` docs for [--diff-filter](https://git-scm.com/docs/git-diff#Documentation/git-diff.txt---diff-filterACDMRTUXB82308203).
158
158
  - **`--max-arg-length`**: long commands (a lot of files) are automatically split into multiple chunks when it detects the current shell cannot handle them. Use this flag to override the maximum length of the generated command string.
159
159
  - **`--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. Can be re-enabled with `--stash`. This option also implies `--no-hide-partially-staged`.
160
160
  - **`--no-hide-partially-staged`**: By default, unstaged changes from partially staged files will be hidden. This option will disable this behavior and include all unstaged changes in partially staged files. Can be re-enabled with `--hide-partially-staged`
161
161
  - **`--quiet`**: Supress all CLI output, except from tasks.
162
162
  - **`--relative`**: Pass filepaths relative to `process.cwd()` (where `lint-staged` runs) to tasks. Default is `false`.
163
- - **`--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. To use a specific shell, use a path like `--shell "/bin/bash"`.
163
+ - **`--shell`**: By default task 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. To use a specific shell, use a path like `--shell "/bin/bash"`.
164
164
  - **`--verbose`**: Show task output even when tasks succeed. By default only failed output is shown.
165
165
 
166
166
  ## Configuration
@@ -282,7 +282,7 @@ Or, if necessary, you can limit the concurrency using `--concurrent <number>` or
282
282
 
283
283
  ## Filtering files
284
284
 
285
- 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:
285
+ 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:
286
286
 
287
287
  - If the glob pattern contains no slashes (`/`), micromatch's `matchBase` option will be enabled, so globs match a file's basename regardless of directory:
288
288
  - `"*.js"` will match all JS files, like `/test.js` and `/foo/bar/test.js`
@@ -297,9 +297,9 @@ When matching, lint-staged will do the following
297
297
  - Resolve the git root automatically, no configuration needed.
298
298
  - Pick the staged files which are present inside the project directory.
299
299
  - Filter them using the specified glob patterns.
300
- - Pass absolute paths to the linters as arguments.
300
+ - Pass absolute paths to the tasks as arguments.
301
301
 
302
- **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).
302
+ **NOTE:** `lint-staged` will pass _absolute_ paths to the tasks 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).
303
303
 
304
304
  Also see [How to use `lint-staged` in a multi-package monorepo?](#how-to-use-lint-staged-in-a-multi-package-monorepo)
305
305
 
@@ -589,12 +589,12 @@ The following is equivalent:
589
589
 
590
590
  </details>
591
591
 
592
- ### Use environment variables with linting commands
592
+ ### Use environment variables with task commands
593
593
 
594
594
  <details>
595
595
  <summary>Click to expand</summary>
596
596
 
597
- 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).
597
+ Task 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).
598
598
 
599
599
  For example, here is `jest` running on all `.js` files with the `NODE_ENV` variable being set to `"test"`:
600
600
 
@@ -849,7 +849,7 @@ _Thanks to [this comment](https://youtrack.jetbrains.com/issue/IDEA-135454#comme
849
849
  <details>
850
850
  <summary>Click to expand</summary>
851
851
 
852
- Install _lint-staged_ on the monorepo root level, and add separate configuration files in each package. When running, _lint-staged_ will always use the configuration closest to a staged file, so having separate configuration files makes sure linters do not "leak" into other packages.
852
+ Install _lint-staged_ on the monorepo root level, and add separate configuration files in each package. When running, _lint-staged_ will always use the configuration closest to a staged file, so having separate configuration files makes sure tasks do not "leak" into other packages.
853
853
 
854
854
  For example, in a monorepo with `packages/frontend/.lintstagedrc.json` and `packages/backend/.lintstagedrc.json`, a staged file inside `packages/frontend/` will only match that configuration, and not the one in `packages/backend/`.
855
855
 
@@ -887,7 +887,7 @@ To support backwards-compatibility, monorepo features require multiple _lint-sta
887
887
 
888
888
  tl;dr: Yes, but the pattern should start with `../`.
889
889
 
890
- By default, `lint-staged` executes linters only on the files present inside the project folder(where `lint-staged` is installed and run from).
890
+ By default, `lint-staged` executes tasks only on the files present inside the project folder(where `lint-staged` is installed and run from).
891
891
  So this question is relevant _only_ when the project folder is a child folder inside the git repo.
892
892
  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.
893
893
 
@@ -23,6 +23,15 @@ process.on('SIGINT', () => {})
23
23
 
24
24
  program.version(await getVersion())
25
25
 
26
+ /**
27
+ * This shouldn't be necessary for lint-staged, but add migration step just in case
28
+ * to preserve old behavior of "commander".
29
+ *
30
+ * @todo remove this in the major version
31
+ * @see https://github.com/tj/commander.js/releases/tag/v13.0.0
32
+ * */
33
+ program.allowExcessArguments()
34
+
26
35
  program.option('--allow-empty', 'allow empty commits when tasks revert all staged changes', false)
27
36
 
28
37
  program.option(
package/lib/index.js CHANGED
@@ -62,7 +62,7 @@ const getMaxArgLength = () => {
62
62
  * @param {boolean} [options.verbose] - Show task output even when tasks succeed; by default only failed output is shown
63
63
  * @param {Logger} [logger]
64
64
  *
65
- * @returns {Promise<boolean>} Promise of whether the linting passed or failed
65
+ * @returns {Promise<boolean>} Promise of whether the task passed or failed
66
66
  */
67
67
  const lintStaged = async (
68
68
  {
package/lib/types.d.ts CHANGED
@@ -93,9 +93,7 @@ type Logger = {
93
93
  }
94
94
 
95
95
  /**
96
- * @returns {boolean} `true` when linting was successful, `false` when some tasks failed with errors
96
+ * @returns {boolean} `true` when all tasks were successful, `false` when some tasks failed with errors
97
97
  * @throws {Error} when failed to some other errors
98
98
  */
99
- type lintStaged = (options: Options, logger?: Logger) => Promise<boolean>
100
-
101
- export default lintStaged
99
+ export default function lintStaged(options: Options, logger?: Logger): Promise<boolean>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "15.4.1",
3
+ "version": "15.4.3",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/lint-staged/lint-staged",
@@ -41,30 +41,30 @@
41
41
  "tag": "npx changeset tag"
42
42
  },
43
43
  "dependencies": {
44
- "chalk": "~5.4.1",
45
- "commander": "~12.1.0",
46
- "debug": "~4.4.0",
47
- "execa": "~8.0.1",
48
- "lilconfig": "~3.1.3",
49
- "listr2": "~8.2.5",
50
- "micromatch": "~4.0.8",
51
- "pidtree": "~0.6.0",
52
- "string-argv": "~0.3.2",
53
- "yaml": "~2.6.1"
44
+ "chalk": "^5.4.1",
45
+ "commander": "^13.1.0",
46
+ "debug": "^4.4.0",
47
+ "execa": "^8.0.1",
48
+ "lilconfig": "^3.1.3",
49
+ "listr2": "^8.2.5",
50
+ "micromatch": "^4.0.8",
51
+ "pidtree": "^0.6.0",
52
+ "string-argv": "^0.3.2",
53
+ "yaml": "^2.7.0"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@changesets/changelog-github": "0.5.0",
57
57
  "@changesets/cli": "2.27.11",
58
58
  "@commitlint/cli": "19.6.1",
59
59
  "@commitlint/config-conventional": "19.6.0",
60
- "@eslint/js": "9.17.0",
60
+ "@eslint/js": "9.18.0",
61
61
  "consolemock": "1.1.0",
62
62
  "cross-env": "7.0.3",
63
- "eslint": "9.17.0",
64
- "eslint-config-prettier": "9.1.0",
65
- "eslint-plugin-jest": "28.10.0",
63
+ "eslint": "9.18.0",
64
+ "eslint-config-prettier": "10.0.1",
65
+ "eslint-plugin-jest": "28.11.0",
66
66
  "eslint-plugin-n": "17.15.1",
67
- "eslint-plugin-prettier": "5.2.1",
67
+ "eslint-plugin-prettier": "5.2.3",
68
68
  "eslint-plugin-simple-import-sort": "12.1.1",
69
69
  "husky": "9.1.7",
70
70
  "jest": "29.7.0",