lint-staged 10.5.4 → 11.1.1

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
@@ -6,11 +6,11 @@ Run linters against staged git files and don't let :poop: slip into your code ba
6
6
 
7
7
  ## Why
8
8
 
9
- 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.
9
+ 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.
10
10
 
11
11
  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.
12
12
 
13
- ## Related blogs posts and talks
13
+ ## Related blog posts and talks
14
14
 
15
15
  - [Introductory Medium post - Andrey Okonetchnikov, 2016](https://medium.com/@okonetchnikov/make-linting-great-again-f3890e1ad6b8#.8qepn2b5l)
16
16
  - [Running Jest Tests Before Each Git Commit - Ben McCormick, 2017](https://benmccormick.org/2017/02/26/running-jest-tests-before-each-git-commit/)
@@ -22,23 +22,23 @@ This project contains a script that will run arbitrary shell tasks with a list o
22
22
 
23
23
  ## Installation and setup
24
24
 
25
- The fastest way to start using lint-staged is to run following command in your terminal:
25
+ The fastest way to start using lint-staged is to run the following command in your terminal:
26
26
 
27
27
  ```bash
28
- npx mrm lint-staged
28
+ npx mrm@2 lint-staged
29
29
  ```
30
30
 
31
- 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.
31
+ This command will install and configure [husky](https://github.com/typicode/husky) and lint-staged depending on the code quality tools from your project's `package.json` dependencies, so please make sure you install (`npm install --save-dev`) and configure all code quality tools like [Prettier](https://prettier.io) and [ESLint](https://eslint.org) prior to that.
32
32
 
33
- Don't forget to commit changes to `package.json` to share this setup with your team!
33
+ Don't forget to commit changes to `package.json` and `.husky` to share this setup with your team!
34
34
 
35
- Now change a few files, `git add` or `git add --patch` some of them to your commit and try to `git commit` them.
35
+ Now change a few files, `git add` or `git add --patch` some of them to your commit, and try to `git commit` them.
36
36
 
37
37
  See [examples](#examples) and [configuration](#configuration) for more information.
38
38
 
39
39
  ## Changelog
40
40
 
41
- See [Releases](https://github.com/okonet/lint-staged/releases)
41
+ See [Releases](https://github.com/okonet/lint-staged/releases).
42
42
 
43
43
  ### Migration
44
44
 
@@ -48,10 +48,10 @@ See [Releases](https://github.com/okonet/lint-staged/releases)
48
48
  If your task previously contained a `git add` step, please remove this.
49
49
  The automatic behaviour ensures there are less race-conditions,
50
50
  since trying to run multiple git operations at the same time usually results in an error.
51
- - From `v10.0.0` onwards _lint-staged_ uses git stashes to improve speed and provide backups while running.
52
- Since git stashes require at least an initial commit, you shouldn't run _lint-staged_ in an empty repo.
53
- - From `v10.0.0` onwards _lint-staged_ requires Node.js version 10.13.0 or later.
54
- - 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.
51
+ - From `v10.0.0` onwards, lint-staged uses git stashes to improve speed and provide backups while running.
52
+ Since git stashes require at least an initial commit, you shouldn't run lint-staged in an empty repo.
53
+ - From `v10.0.0` onwards, lint-staged requires Node.js version 10.13.0 or later.
54
+ - From `v10.0.0` onwards, lint-staged will abort the commit if linter tasks undo all staged changes. To allow creating an empty commit, please use the `--allow-empty` option.
55
55
 
56
56
  ## Command line flags
57
57
 
@@ -71,7 +71,7 @@ Options:
71
71
  tasks serially (default: true)
72
72
  -q, --quiet disable lint-staged’s own console output (default: false)
73
73
  -r, --relative pass relative filepaths to tasks (default: false)
74
- -x, --shell skip parsing of tasks for better shell support (default:
74
+ -x, --shell [path] skip parsing of tasks for better shell support (default:
75
75
  false)
76
76
  -v, --verbose show task output even when tasks succeed; by default only
77
77
  failed output is shown (default: false)
@@ -79,7 +79,7 @@ Options:
79
79
  ```
80
80
 
81
81
  - **`--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.
82
- - **`--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 -`.
82
+ - **`--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 will 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 -`.
83
83
  - **`--debug`**: Run in debug mode. When set, it does the following:
84
84
  - 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*`.
85
85
  - 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.
@@ -90,12 +90,12 @@ Options:
90
90
  - **`--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.
91
91
  - **`--quiet`**: Supress all CLI output, except from tasks.
92
92
  - **`--relative`**: Pass filepaths relative to `process.cwd()` (where `lint-staged` runs) to tasks. Default is `false`.
93
- - **`--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.
93
+ - **`--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"`.
94
94
  - **`--verbose`**: Show task output even when tasks succeed. By default only failed output is shown.
95
95
 
96
96
  ## Configuration
97
97
 
98
- Starting with v3.1 you can now use different ways of configuring it:
98
+ Starting with v3.1 you can now use different ways of configuring lint-staged:
99
99
 
100
100
  - `lint-staged` object in your `package.json`
101
101
  - `.lintstagedrc` file in JSON or YML format, or you can be explicit with the file extension:
@@ -135,7 +135,7 @@ So, considering you did `git add file1.ext file2.ext`, lint-staged will run the
135
135
 
136
136
  ## Filtering files
137
137
 
138
- 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:
138
+ 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:
139
139
 
140
140
  - If the glob pattern contains no slashes (`/`), micromatch's `matchBase` option will enabled, so globs match a file's basename regardless of directory:
141
141
  - **`"*.js"`** will match all JS files, like `/test.js` and `/foo/bar/test.js`
@@ -144,7 +144,7 @@ Linter commands work on a subset of all staged files, defined by a _glob pattern
144
144
  - **`"./*.js"`** will match all JS files in the git repo root, so `/test.js` but not `/foo/bar/test.js`
145
145
  - **`"foo/**/\*.js"`** will match all JS files inside the`/foo`directory, so`/foo/bar/test.js`but not`/test.js`
146
146
 
147
- When matching, `lint-staged` will do the following
147
+ When matching, lint-staged will do the following
148
148
 
149
149
  - Resolve the git root automatically, no configuration needed.
150
150
  - Pick the staged files which are present inside the project directory.
@@ -153,11 +153,11 @@ When matching, `lint-staged` will do the following
153
153
 
154
154
  **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).
155
155
 
156
- Also see [How to use `lint-staged` in a multi package monorepo?](#how-to-use-lint-staged-in-a-multi-package-monorepo)
156
+ Also see [How to use `lint-staged` in a multi-package monorepo?](#how-to-use-lint-staged-in-a-multi-package-monorepo)
157
157
 
158
158
  ### Ignoring files
159
159
 
160
- 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.
160
+ The concept of `lint-staged` is to run configured linter tasks (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.
161
161
 
162
162
  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.
163
163
 
@@ -167,7 +167,7 @@ In advanced scenarios, where it is impossible to configure the linter task itsel
167
167
 
168
168
  Supported are any executables installed locally or globally via `npm` as well as any executable from your \$PATH.
169
169
 
170
- > Using globally installed scripts is discouraged, since lint-staged may not work for someone who doesnt have it installed.
170
+ > Using globally installed scripts is discouraged, since lint-staged may not work for someone who doesn't have it installed.
171
171
 
172
172
  `lint-staged` uses [execa](https://github.com/sindresorhus/execa#preferlocal) to locate locally installed scripts. So in your `.lintstagedrc` you can write:
173
173
 
@@ -195,11 +195,11 @@ going to execute `eslint` and if it exits with `0` code, it will execute `pretti
195
195
 
196
196
  ## Using JS configuration file
197
197
 
198
- 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.
198
+ 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.
199
199
 
200
- 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.
200
+ 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 of command strings. These strings are considered complete and should include the filename arguments, if wanted.
201
201
 
202
- 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.
202
+ 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.
203
203
 
204
204
  ### Function signature
205
205
 
@@ -259,7 +259,7 @@ module.exports = {
259
259
 
260
260
  </details>
261
261
 
262
- ### Example: Run eslint on entire repo if more than 10 staged files
262
+ ### Example: Run ESLint on entire repo if more than 10 staged files
263
263
 
264
264
  <details>
265
265
  <summary>Click to expand</summary>
@@ -353,7 +353,7 @@ Prior to version 10, tasks had to manually include `git add` as the final step.
353
353
 
354
354
  ## Examples
355
355
 
356
- All examples assuming youve already set up lint-staged and husky in the `package.json`.
356
+ All examples assume you've already set up lint-staged in the `package.json` file and [husky](https://github.com/typicode/husky) in its own config file.
357
357
 
358
358
  ```json
359
359
  {
@@ -362,16 +362,20 @@ All examples assuming you’ve already set up lint-staged and husky in the `pack
362
362
  "scripts": {
363
363
  "my-custom-script": "linter --arg1 --arg2"
364
364
  },
365
- "husky": {
366
- "hooks": {
367
- "pre-commit": "lint-staged"
368
- }
369
- },
370
365
  "lint-staged": {}
371
366
  }
372
367
  ```
373
368
 
374
- _Note we don’t pass a path as an argument for the runners. This is important since lint-staged will do this for you._
369
+ In `.husky/pre-commit`
370
+
371
+ ```shell
372
+ #!/bin/sh
373
+ . "$(dirname "$0")/_/husky.sh"
374
+
375
+ npx lint-staged
376
+ ```
377
+
378
+ _Note: we don't pass a path as an argument for the runners. This is important since lint-staged will do this for you._
375
379
 
376
380
  ### ESLint with default parameters for `*.js` and `*.jsx` running as a pre-commit hook
377
381
 
@@ -468,13 +472,15 @@ module.exports = (allStagedFiles) => {
468
472
  allStagedFiles,
469
473
  prettierSupportedExtensions.map((extension) => `**/*${extension}`)
470
474
  )
471
- return [`prettier --write ${prettierFiles.map(addQuotes).join(' ')}`]
475
+ return prettierFiles.length > 0
476
+ ? [`prettier --write ${prettierFiles.map(addQuotes).join(' ')}`]
477
+ : []
472
478
  }
473
479
  ```
474
480
 
475
481
  </details>
476
482
 
477
- ### Automatically fix code style with `prettier` for javascript, typescript, markdown, HTML, or CSS
483
+ ### Automatically fix code style with `prettier` for JavaScript, TypeScript, Markdown, HTML, or CSS
478
484
 
479
485
  <details>
480
486
  <summary>Click to expand</summary>
@@ -648,7 +654,7 @@ _Thanks to [this comment](https://youtrack.jetbrains.com/issue/IDEA-135454#comme
648
654
 
649
655
  </details>
650
656
 
651
- ### How to use `lint-staged` in a multi package monorepo?
657
+ ### How to use `lint-staged` in a multi-package monorepo?
652
658
 
653
659
  <details>
654
660
  <summary>Click to expand</summary>
@@ -680,7 +686,7 @@ Example repo: [sudo-suhas/lint-staged-django-react-demo](https://github.com/sudo
680
686
 
681
687
  </details>
682
688
 
683
- ### How can i ignore files from `.eslintignore` ?
689
+ ### How can I ignore files from `.eslintignore`?
684
690
 
685
691
  <details>
686
692
  <summary>Click to expand</summary>
@@ -711,16 +717,16 @@ module.exports = {
711
717
 
712
718
  </details>
713
719
 
714
- #### ESlint >= 7
720
+ #### ESLint >= 7
715
721
 
716
722
  <details>
717
723
  <summary>Click to expand</summary>
718
724
 
719
- In versions of ESlint > 7, [isPathIgnored](https://eslint.org/docs/developer-guide/nodejs-api#-eslintispathignoredfilepath) is an async function and now returns a promise. The code below can be used to reinstate the above functionality.
725
+ In versions of ESLint > 7, [isPathIgnored](https://eslint.org/docs/developer-guide/nodejs-api#-eslintispathignoredfilepath) is an async function and now returns a promise. The code below can be used to reinstate the above functionality.
720
726
 
721
727
  This particular code uses a tiny package, [node-filter-async](https://www.npmjs.com/package/node-filter-async), to filter the files array with an async function. If you prefer to not have an extra dependency, it is quite simple to write a similar function.
722
728
 
723
- Since [10.5.3](https://github.com/okonet/lint-staged/releases), any errors due to a bad eslint config will come through to the console.
729
+ Since [10.5.3](https://github.com/okonet/lint-staged/releases), any errors due to a bad ESLint config will come through to the console.
724
730
 
725
731
  ```js
726
732
  const { ESLint } = require('eslint')
@@ -17,7 +17,7 @@ const pkg = require('../package.json')
17
17
  require('please-upgrade-node')(
18
18
  Object.assign({}, pkg, {
19
19
  engines: {
20
- node: '>=10.13.0', // First LTS release of 'Dubnium'
20
+ node: '>=12.13.0', // First LTS release of 'Erbium'
21
21
  },
22
22
  })
23
23
  )
@@ -42,7 +42,7 @@ cmdline
42
42
  )
43
43
  .option('-q, --quiet', 'disable lint-staged’s own console output', false)
44
44
  .option('-r, --relative', 'pass relative filepaths to tasks', false)
45
- .option('-x, --shell', 'skip parsing of tasks for better shell support', false)
45
+ .option('-x, --shell [path]', 'skip parsing of tasks for better shell support', false)
46
46
  .option(
47
47
  '-v, --verbose',
48
48
  'show task output even when tasks succeed; by default only failed output is shown',
@@ -74,17 +74,19 @@ const getMaxArgLength = () => {
74
74
  }
75
75
  }
76
76
 
77
+ const cmdlineOptions = cmdline.opts()
78
+
77
79
  const options = {
78
- allowEmpty: !!cmdline.allowEmpty,
79
- concurrent: JSON.parse(cmdline.concurrent),
80
- configPath: cmdline.config,
81
- debug: !!cmdline.debug,
80
+ allowEmpty: !!cmdlineOptions.allowEmpty,
81
+ concurrent: JSON.parse(cmdlineOptions.concurrent),
82
+ configPath: cmdlineOptions.config,
83
+ debug: !!cmdlineOptions.debug,
82
84
  maxArgLength: getMaxArgLength() / 2,
83
- stash: !!cmdline.stash, // commander inverts `no-<x>` flags to `!x`
84
- quiet: !!cmdline.quiet,
85
- relative: !!cmdline.relative,
86
- shell: !!cmdline.shell,
87
- verbose: !!cmdline.verbose,
85
+ stash: !!cmdlineOptions.stash, // commander inverts `no-<x>` flags to `!x`
86
+ quiet: !!cmdlineOptions.quiet,
87
+ relative: !!cmdlineOptions.relative,
88
+ shell: cmdlineOptions.shell /* Either a boolean or a string pointing to the shell */,
89
+ verbose: !!cmdlineOptions.verbose,
88
90
  }
89
91
 
90
92
  debug('Options parsed from command-line:', options)
package/lib/index.js CHANGED
@@ -8,13 +8,18 @@ const stringifyObject = require('stringify-object')
8
8
  const { PREVENTED_EMPTY_COMMIT, GIT_ERROR, RESTORE_STASH_EXAMPLE } = require('./messages')
9
9
  const printTaskOutput = require('./printTaskOutput')
10
10
  const runAll = require('./runAll')
11
- const { ApplyEmptyCommitError, GetBackupStashError, GitError } = require('./symbols')
11
+ const {
12
+ ApplyEmptyCommitError,
13
+ ConfigNotFoundError,
14
+ GetBackupStashError,
15
+ GitError,
16
+ InvalidOptionsError,
17
+ } = require('./symbols')
12
18
  const formatConfig = require('./formatConfig')
13
19
  const validateConfig = require('./validateConfig')
20
+ const validateOptions = require('./validateOptions')
14
21
 
15
- const errConfigNotFound = new Error('Config could not be found')
16
-
17
- function resolveConfig(configPath) {
22
+ const resolveConfig = (configPath) => {
18
23
  try {
19
24
  return require.resolve(configPath)
20
25
  } catch {
@@ -22,7 +27,7 @@ function resolveConfig(configPath) {
22
27
  }
23
28
  }
24
29
 
25
- function loadConfig(configPath) {
30
+ const loadConfig = (configPath) => {
26
31
  const explorer = cosmiconfig('lint-staged', {
27
32
  searchPlaces: [
28
33
  'package.json',
@@ -56,14 +61,14 @@ function loadConfig(configPath) {
56
61
  * @param {number} [options.maxArgLength] - Maximum argument string length
57
62
  * @param {boolean} [options.quiet] - Disable lint-staged’s own console output
58
63
  * @param {boolean} [options.relative] - Pass relative filepaths to tasks
59
- * @param {boolean} [options.shell] - Skip parsing of tasks for better shell support
64
+ * @param {boolean|string} [options.shell] - Skip parsing of tasks for better shell support
60
65
  * @param {boolean} [options.stash] - Enable the backup stash, and revert in case of errors
61
66
  * @param {boolean} [options.verbose] - Show task output even when tasks succeed; by default only failed output is shown
62
67
  * @param {Logger} [logger]
63
68
  *
64
69
  * @returns {Promise<boolean>} Promise of whether the linting passed or failed
65
70
  */
66
- module.exports = async function lintStaged(
71
+ const lintStaged = async (
67
72
  {
68
73
  allowEmpty = false,
69
74
  concurrent = true,
@@ -79,20 +84,27 @@ module.exports = async function lintStaged(
79
84
  verbose = false,
80
85
  } = {},
81
86
  logger = console
82
- ) {
87
+ ) => {
83
88
  try {
89
+ await validateOptions({ shell }, logger)
90
+
84
91
  debugLog('Loading config using `cosmiconfig`')
85
92
 
86
93
  const resolved = configObject
87
94
  ? { config: configObject, filepath: '(input)' }
88
95
  : await loadConfig(configPath)
89
- if (resolved == null) throw errConfigNotFound
96
+
97
+ if (resolved == null) {
98
+ throw ConfigNotFoundError
99
+ }
90
100
 
91
101
  debugLog('Successfully loaded config from `%s`:\n%O', resolved.filepath, resolved.config)
102
+
92
103
  // resolved.config is the parsed configuration object
93
104
  // resolved.filepath is the path to the config file that was found
94
105
  const formattedConfig = formatConfig(resolved.config)
95
106
  const config = validateConfig(formattedConfig)
107
+
96
108
  if (debug) {
97
109
  // Log using logger to be able to test through `consolemock`.
98
110
  logger.log('Running lint-staged with the following config:')
@@ -148,7 +160,13 @@ module.exports = async function lintStaged(
148
160
  throw runAllError
149
161
  }
150
162
  } catch (lintStagedError) {
151
- if (lintStagedError === errConfigNotFound) {
163
+ /** throw early because `validateOptions` options contains own logging */
164
+ if (lintStagedError === InvalidOptionsError) {
165
+ throw InvalidOptionsError
166
+ }
167
+
168
+ /** @todo move logging to `validateConfig` and remove this try/catch block */
169
+ if (lintStagedError === ConfigNotFoundError) {
152
170
  logger.error(`${lintStagedError.message}.`)
153
171
  } else {
154
172
  // It was probably a parsing error
@@ -168,3 +186,5 @@ module.exports = async function lintStaged(
168
186
  throw lintStagedError
169
187
  }
170
188
  }
189
+
190
+ module.exports = lintStaged
package/lib/messages.js CHANGED
@@ -27,6 +27,14 @@ const SKIPPED_GIT_ERROR = 'Skipped because of previous git error.'
27
27
 
28
28
  const GIT_ERROR = `\n ${error} ${chalk.red(`lint-staged failed due to a git error.`)}`
29
29
 
30
+ const invalidOption = (name, value, message) => `${chalk.redBright(`${error} Validation Error:`)}
31
+
32
+ Invalid value for option ${chalk.bold(name)}: ${chalk.bold(value)}
33
+
34
+ ${message}
35
+
36
+ See https://github.com/okonet/lint-staged#command-line-flags`
37
+
30
38
  const PREVENTED_EMPTY_COMMIT = `
31
39
  ${warning} ${chalk.yellow(`lint-staged prevented an empty git commit.
32
40
  Use the --allow-empty option to continue, or check your task configuration`)}
@@ -42,16 +50,17 @@ const RESTORE_STASH_EXAMPLE = ` Any lost modifications can be restored from a g
42
50
  const CONFIG_STDIN_ERROR = 'Error: Could not read config from stdin.'
43
51
 
44
52
  module.exports = {
45
- NOT_GIT_REPO,
53
+ CONFIG_STDIN_ERROR,
54
+ DEPRECATED_GIT_ADD,
46
55
  FAILED_GET_STAGED_FILES,
56
+ GIT_ERROR,
57
+ invalidOption,
47
58
  NO_STAGED_FILES,
48
59
  NO_TASKS,
49
- skippingBackup,
50
- DEPRECATED_GIT_ADD,
51
- TASK_ERROR,
52
- SKIPPED_GIT_ERROR,
53
- GIT_ERROR,
60
+ NOT_GIT_REPO,
54
61
  PREVENTED_EMPTY_COMMIT,
55
62
  RESTORE_STASH_EXAMPLE,
56
- CONFIG_STDIN_ERROR,
63
+ SKIPPED_GIT_ERROR,
64
+ skippingBackup,
65
+ TASK_ERROR,
57
66
  }
package/lib/runAll.js CHANGED
@@ -147,7 +147,8 @@ const runAll = async (
147
147
  matchedFiles.add(file)
148
148
  })
149
149
 
150
- hasDeprecatedGitAdd = subTasks.some((subTask) => subTask.command === 'git add')
150
+ hasDeprecatedGitAdd =
151
+ hasDeprecatedGitAdd || subTasks.some((subTask) => subTask.command === 'git add')
151
152
 
152
153
  chunkListrTasks.push({
153
154
  title: `Running tasks for ${task.pattern}`,
package/lib/symbols.js CHANGED
@@ -1,11 +1,13 @@
1
1
  'use strict'
2
2
 
3
3
  const ApplyEmptyCommitError = Symbol('ApplyEmptyCommitError')
4
+ const ConfigNotFoundError = new Error('Config could not be found')
4
5
  const GetBackupStashError = Symbol('GetBackupStashError')
5
6
  const GetStagedFilesError = Symbol('GetStagedFilesError')
6
7
  const GitError = Symbol('GitError')
7
8
  const GitRepoError = Symbol('GitRepoError')
8
9
  const HideUnstagedChangesError = Symbol('HideUnstagedChangesError')
10
+ const InvalidOptionsError = new Error('Invalid Options')
9
11
  const RestoreMergeStatusError = Symbol('RestoreMergeStatusError')
10
12
  const RestoreOriginalStateError = Symbol('RestoreOriginalStateError')
11
13
  const RestoreUnstagedChangesError = Symbol('RestoreUnstagedChangesError')
@@ -13,10 +15,12 @@ const TaskError = Symbol('TaskError')
13
15
 
14
16
  module.exports = {
15
17
  ApplyEmptyCommitError,
18
+ ConfigNotFoundError,
16
19
  GetBackupStashError,
17
20
  GetStagedFilesError,
18
21
  GitError,
19
22
  GitRepoError,
23
+ InvalidOptionsError,
20
24
  HideUnstagedChangesError,
21
25
  RestoreMergeStatusError,
22
26
  RestoreOriginalStateError,
@@ -0,0 +1,31 @@
1
+ const { promises: fs, constants } = require('fs')
2
+
3
+ const { invalidOption } = require('./messages')
4
+ const { InvalidOptionsError } = require('./symbols')
5
+
6
+ const debug = require('debug')('lint-staged:options')
7
+
8
+ /**
9
+ * Validate lint-staged options, either from the Node.js API or the command line flags.
10
+ * @param {*} options
11
+ * @param {boolean|string} [options.shell] - Skip parsing of tasks for better shell support
12
+ *
13
+ * @throws {InvalidOptionsError}
14
+ */
15
+ const validateOptions = async (options = {}, logger) => {
16
+ debug('Validating options...')
17
+
18
+ /** Ensure the passed shell option is executable */
19
+ if (typeof options.shell === 'string') {
20
+ try {
21
+ await fs.access(options.shell, constants.X_OK)
22
+ } catch (error) {
23
+ logger.error(invalidOption('shell', options.shell, error.message))
24
+ throw InvalidOptionsError
25
+ }
26
+ }
27
+
28
+ debug('Validated options!')
29
+ }
30
+
31
+ module.exports = validateOptions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "10.5.4",
3
+ "version": "11.1.1",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/okonet/lint-staged",
@@ -26,45 +26,40 @@
26
26
  "test": "jest --coverage",
27
27
  "test:watch": "jest --watch"
28
28
  },
29
- "husky": {
30
- "hooks": {
31
- "pre-commit": "./bin/lint-staged.js"
32
- }
33
- },
34
29
  "dependencies": {
35
- "chalk": "^4.1.0",
30
+ "chalk": "^4.1.1",
36
31
  "cli-truncate": "^2.1.0",
37
- "commander": "^6.2.0",
32
+ "commander": "^7.2.0",
38
33
  "cosmiconfig": "^7.0.0",
39
- "debug": "^4.2.0",
34
+ "debug": "^4.3.1",
40
35
  "dedent": "^0.7.0",
41
36
  "enquirer": "^2.3.6",
42
- "execa": "^4.1.0",
43
- "listr2": "^3.2.2",
44
- "log-symbols": "^4.0.0",
45
- "micromatch": "^4.0.2",
37
+ "execa": "^5.0.0",
38
+ "listr2": "^3.8.2",
39
+ "log-symbols": "^4.1.0",
40
+ "micromatch": "^4.0.4",
46
41
  "normalize-path": "^3.0.0",
47
42
  "please-upgrade-node": "^3.2.0",
48
43
  "string-argv": "0.3.1",
49
44
  "stringify-object": "^3.3.0"
50
45
  },
51
46
  "devDependencies": {
52
- "@babel/core": "^7.12.3",
53
- "@babel/plugin-proposal-object-rest-spread": "^7.12.1",
54
- "@babel/preset-env": "^7.12.1",
47
+ "@babel/core": "^7.14.0",
48
+ "@babel/plugin-proposal-object-rest-spread": "^7.13.8",
49
+ "@babel/preset-env": "^7.14.1",
55
50
  "babel-eslint": "10.1.0",
56
- "babel-jest": "^26.6.1",
51
+ "babel-jest": "^26.6.3",
57
52
  "consolemock": "^1.1.0",
58
- "eslint": "^7.12.1",
59
- "eslint-config-prettier": "^6.15.0",
53
+ "eslint": "^7.25.0",
54
+ "eslint-config-prettier": "^8.3.0",
60
55
  "eslint-plugin-import": "^2.22.1",
61
56
  "eslint-plugin-node": "^11.1.0",
62
- "eslint-plugin-prettier": "^3.1.4",
63
- "fs-extra": "^9.0.1",
64
- "husky": "^4.3.0",
65
- "jest": "^26.6.1",
57
+ "eslint-plugin-prettier": "^3.4.0",
58
+ "fs-extra": "^10.0.0",
59
+ "husky": "^6.0.0",
60
+ "jest": "^26.6.3",
66
61
  "jest-snapshot-serializer-ansi": "^1.0.0",
67
- "prettier": "^2.1.2"
62
+ "prettier": "^2.2.1"
68
63
  },
69
64
  "config": {
70
65
  "commitizen": {