lint-staged 12.4.0 → 12.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
@@ -594,7 +594,7 @@ const success = await lintStaged({
594
594
  maxArgLength: null,
595
595
  quiet: false,
596
596
  relative: false,
597
- shell: false
597
+ shell: false,
598
598
  stash: true,
599
599
  verbose: false
600
600
  })
@@ -4,7 +4,7 @@ import fs from 'fs'
4
4
  import path from 'path'
5
5
  import { fileURLToPath } from 'url'
6
6
 
7
- import cmdline from 'commander'
7
+ import { Option, program } from 'commander'
8
8
  import debug from 'debug'
9
9
  import supportsColor from 'supports-color'
10
10
 
@@ -23,50 +23,75 @@ const packageJsonPath = path.join(fileURLToPath(import.meta.url), '../../package
23
23
  const packageJson = JSON.parse(fs.readFileSync(packageJsonPath))
24
24
  const version = packageJson.version
25
25
 
26
- cmdline
27
- .version(version)
28
- .option('--allow-empty', 'allow empty commits when tasks revert all staged changes', false)
29
- .option(
30
- '-p, --concurrent <number|boolean>',
31
- 'the number of tasks to run concurrently, or false for serial',
32
- true
26
+ const debugLog = debug('lint-staged:bin')
27
+ debugLog('Running `lint-staged@%s`', version)
28
+
29
+ const cli = program.version(version)
30
+
31
+ cli.option('--allow-empty', 'allow empty commits when tasks revert all staged changes', false)
32
+
33
+ cli.option(
34
+ '-p, --concurrent <number|boolean>',
35
+ 'the number of tasks to run concurrently, or false for serial',
36
+ true
37
+ )
38
+
39
+ cli.option('-c, --config [path]', 'path to configuration file, or - to read from stdin')
40
+
41
+ cli.option('--cwd [path]', 'run all tasks in specific directory, instead of the current')
42
+
43
+ cli.option('-d, --debug', 'print additional debug information', false)
44
+
45
+ cli.option('--max-arg-length [number]', 'maximum length of the command-line argument string', 0)
46
+
47
+ /**
48
+ * We don't want to show the `--stash` flag because it's on by default, and only show the
49
+ * negatable flag `--no-stash` in stead. There seems to be a bug in Commander.js where
50
+ * configuring only the latter won't actually set the default value.
51
+ */
52
+ cli
53
+ .addOption(
54
+ new Option('--stash', 'enable the backup stash, and revert in case of errors')
55
+ .default(true)
56
+ .hideHelp()
33
57
  )
34
- .option('-c, --config [path]', 'path to configuration file, or - to read from stdin')
35
- .option('--cwd [path]', 'run all tasks in specific directory, instead of the current')
36
- .option('-d, --debug', 'print additional debug information', false)
37
- .option('--max-arg-length', 'maximum length of the command-line argument string')
38
- .option('--no-stash', 'disable the backup stash, and do not revert in case of errors', false)
39
- .option('-q, --quiet', 'disable lint-staged’s own console output', false)
40
- .option('-r, --relative', 'pass relative filepaths to tasks', false)
41
- .option('-x, --shell [path]', 'skip parsing of tasks for better shell support', false)
42
- .option(
43
- '-v, --verbose',
44
- 'show task output even when tasks succeed; by default only failed output is shown',
45
- false
58
+ .addOption(
59
+ new Option(
60
+ '--no-stash',
61
+ 'disable the backup stash, and do not revert in case of errors'
62
+ ).default(false)
46
63
  )
47
- .parse(process.argv)
48
64
 
49
- const cmdlineOptions = cmdline.opts()
65
+ cli.option('-q, --quiet', 'disable lint-staged’s own console output', false)
66
+
67
+ cli.option('-r, --relative', 'pass relative filepaths to tasks', false)
68
+
69
+ cli.option('-x, --shell [path]', 'skip parsing of tasks for better shell support', false)
70
+
71
+ cli.option(
72
+ '-v, --verbose',
73
+ 'show task output even when tasks succeed; by default only failed output is shown',
74
+ false
75
+ )
50
76
 
51
- if (cmdlineOptions.debug) {
77
+ const cliOptions = cli.parse(process.argv).opts()
78
+
79
+ if (cliOptions.debug) {
52
80
  debug.enable('lint-staged*')
53
81
  }
54
82
 
55
- const debugLog = debug('lint-staged:bin')
56
- debugLog('Running `lint-staged@%s`', version)
57
-
58
83
  const options = {
59
- allowEmpty: !!cmdlineOptions.allowEmpty,
60
- concurrent: JSON.parse(cmdlineOptions.concurrent),
61
- configPath: cmdlineOptions.config,
62
- cwd: cmdlineOptions.cwd,
63
- debug: !!cmdlineOptions.debug,
64
- maxArgLength: JSON.parse(cmdlineOptions.maxArgLength || null),
65
- quiet: !!cmdlineOptions.quiet,
66
- relative: !!cmdlineOptions.relative,
67
- shell: cmdlineOptions.shell /* Either a boolean or a string pointing to the shell */,
68
- stash: !!cmdlineOptions.stash, // commander inverts `no-<x>` flags to `!x`
69
- verbose: !!cmdlineOptions.verbose,
84
+ allowEmpty: !!cliOptions.allowEmpty,
85
+ concurrent: JSON.parse(cliOptions.concurrent),
86
+ configPath: cliOptions.config,
87
+ cwd: cliOptions.cwd,
88
+ debug: !!cliOptions.debug,
89
+ maxArgLength: cliOptions.maxArgLength || undefined,
90
+ quiet: !!cliOptions.quiet,
91
+ relative: !!cliOptions.relative,
92
+ shell: cliOptions.shell /* Either a boolean or a string pointing to the shell */,
93
+ stash: !!cliOptions.stash, // commander inverts `no-<x>` flags to `!x`
94
+ verbose: !!cliOptions.verbose,
70
95
  }
71
96
 
72
97
  debugLog('Options parsed from command-line:', options)
@@ -14,7 +14,8 @@ const debugLog = debug('lint-staged:searchConfigs')
14
14
 
15
15
  const EXEC_GIT = ['ls-files', '-z', '--full-name']
16
16
 
17
- const filterPossibleConfigFiles = (file) => searchPlaces.includes(basename(file))
17
+ const filterPossibleConfigFiles = (files) =>
18
+ files.filter((file) => searchPlaces.includes(basename(file)))
18
19
 
19
20
  const numberOfLevels = (file) => file.split('/').length
20
21
 
@@ -58,20 +59,18 @@ export const searchConfigs = async (
58
59
  return { [configPath]: validateConfig(config, filepath, logger) }
59
60
  }
60
61
 
61
- /** Get all possible config files known to git */
62
- const cachedFiles = parseGitZOutput(await execGit(EXEC_GIT, { cwd: gitDir })).filter(
63
- filterPossibleConfigFiles
64
- )
65
-
66
- /** Get all possible config files from uncommitted files */
67
- const otherFiles = parseGitZOutput(
68
- await execGit([...EXEC_GIT, '--others', '--exclude-standard'], { cwd: gitDir })
69
- ).filter(filterPossibleConfigFiles)
62
+ const [cachedFiles, otherFiles] = await Promise.all([
63
+ /** Get all possible config files known to git */
64
+ execGit(EXEC_GIT, { cwd: gitDir }).then(parseGitZOutput).then(filterPossibleConfigFiles),
65
+ /** Get all possible config files from uncommitted files */
66
+ execGit([...EXEC_GIT, '--others', '--exclude-standard'], { cwd: gitDir })
67
+ .then(parseGitZOutput)
68
+ .then(filterPossibleConfigFiles),
69
+ ])
70
70
 
71
71
  /** Sort possible config files so that deepest is first */
72
72
  const possibleConfigFiles = [...cachedFiles, ...otherFiles]
73
- .map((file) => join(gitDir, file))
74
- .map((file) => normalize(file))
73
+ .map((file) => normalize(join(gitDir, file)))
75
74
  .filter(isInsideDirectory(cwd))
76
75
  .sort(sortDeepestParth)
77
76
 
@@ -85,15 +84,17 @@ export const searchConfigs = async (
85
84
 
86
85
  /** Load and validate all configs to the above object */
87
86
  await Promise.all(
88
- possibleConfigFiles
89
- .map((configPath) => loadConfig({ configPath }, logger))
90
- .map((promise) =>
91
- promise.then(({ config, filepath }) => {
92
- if (config) {
93
- configs[filepath] = validateConfig(config, filepath, logger)
87
+ Object.keys(configs).map((configPath) =>
88
+ loadConfig({ configPath }, logger).then(({ config, filepath }) => {
89
+ if (config) {
90
+ if (configPath !== filepath) {
91
+ debugLog('Config file "%s" resolved to "%s"', configPath, filepath)
94
92
  }
95
- })
96
- )
93
+
94
+ configs[configPath] = validateConfig(config, filepath, logger)
95
+ }
96
+ })
97
+ )
97
98
  )
98
99
 
99
100
  /** Get validated configs from the above object, without any `null` values (not found) */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "12.4.0",
3
+ "version": "12.4.3",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/okonet/lint-staged",
@@ -34,35 +34,36 @@
34
34
  "dependencies": {
35
35
  "cli-truncate": "^3.1.0",
36
36
  "colorette": "^2.0.16",
37
- "commander": "^8.3.0",
38
- "debug": "^4.3.3",
37
+ "commander": "^9.3.0",
38
+ "debug": "^4.3.4",
39
39
  "execa": "^5.1.1",
40
- "lilconfig": "2.0.4",
41
- "listr2": "^4.0.1",
42
- "micromatch": "^4.0.4",
40
+ "lilconfig": "2.0.5",
41
+ "listr2": "^4.0.5",
42
+ "micromatch": "^4.0.5",
43
43
  "normalize-path": "^3.0.0",
44
- "object-inspect": "^1.12.0",
44
+ "object-inspect": "^1.12.2",
45
45
  "pidtree": "^0.5.0",
46
46
  "string-argv": "^0.3.1",
47
- "supports-color": "^9.2.1",
47
+ "supports-color": "^9.2.2",
48
48
  "yaml": "^1.10.2"
49
49
  },
50
50
  "devDependencies": {
51
- "@babel/core": "^7.16.12",
52
- "@babel/eslint-parser": "^7.16.5",
53
- "@babel/preset-env": "^7.16.11",
54
- "babel-jest": "^27.4.6",
51
+ "@babel/core": "^7.18.2",
52
+ "@babel/eslint-parser": "^7.18.2",
53
+ "@babel/preset-env": "^7.18.2",
54
+ "babel-jest": "^28.1.0",
55
+ "babel-plugin-transform-imports": "2.0.0",
55
56
  "consolemock": "^1.1.0",
56
- "eslint": "^8.7.0",
57
- "eslint-config-prettier": "^8.3.0",
58
- "eslint-plugin-import": "^2.25.4",
57
+ "eslint": "^8.16.0",
58
+ "eslint-config-prettier": "^8.5.0",
59
+ "eslint-plugin-import": "^2.26.0",
59
60
  "eslint-plugin-node": "^11.1.0",
60
61
  "eslint-plugin-prettier": "^4.0.0",
61
- "fs-extra": "^10.0.0",
62
- "husky": "^7.0.4",
63
- "jest": "^27.4.7",
62
+ "fs-extra": "^10.1.0",
63
+ "husky": "^8.0.1",
64
+ "jest": "^28.1.0",
64
65
  "jest-snapshot-serializer-ansi": "^1.0.0",
65
- "prettier": "^2.5.1"
66
+ "prettier": "^2.6.2"
66
67
  },
67
68
  "keywords": [
68
69
  "lint",