lint-staged 15.2.2 → 15.2.5

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
@@ -223,15 +223,43 @@ Pay extra attention when the configured globs overlap, and tasks make edits to f
223
223
  }
224
224
  ```
225
225
 
226
- If necessary, you can limit the concurrency using `--concurrent <number>` or disable it entirely with `--concurrent false`.
226
+ You can solve it using the negation pattern and the array syntax:
227
+
228
+ ```json
229
+ {
230
+ "!(*.ts)": "prettier --write",
231
+ "*.ts": ["eslint --fix", "prettier --write"]
232
+ }
233
+ ```
234
+
235
+ Another example in which tasks make edits to files and globs match multiple files but don't overlap:
236
+
237
+ ```json
238
+ {
239
+ "*.css": [
240
+ "stylelint --fix",
241
+ "prettier --write"
242
+ ],
243
+ "*.{js,jsx}": [
244
+ "eslint --fix",
245
+ "prettier --write"
246
+ ],
247
+ "!(*.css|*.js|*.jsx)": [
248
+ "prettier --write"
249
+ ]
250
+ }
251
+ ```
252
+
253
+ Or, if necessary, you can limit the concurrency using `--concurrent <number>` or disable it entirely with `--concurrent false`.
227
254
 
228
255
  ## Filtering files
229
256
 
230
257
  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:
231
258
 
232
- - If the glob pattern contains no slashes (`/`), micromatch's `matchBase` option will enabled, so globs match a file's basename regardless of directory:
259
+ - If the glob pattern contains no slashes (`/`), micromatch's `matchBase` option will be enabled, so globs match a file's basename regardless of directory:
233
260
  - `"*.js"` will match all JS files, like `/test.js` and `/foo/bar/test.js`
234
261
  - `"!(*test).js"` will match all JS files, except those ending in `test.js`, so `foo.js` but not `foo.test.js`
262
+ - `"!(*.css|*.js)"` will match all files except CSS and JS files
235
263
  - If the glob pattern does contain a slash (`/`), it will match for paths as well:
236
264
  - `"./*.js"` will match all JS files in the git repo root, so `/test.js` but not `/foo/bar/test.js`
237
265
  - `"foo/**/*.js"` will match all JS files inside the `/foo` directory, so `/foo/bar/test.js` but not `/test.js`
@@ -879,7 +907,7 @@ ESLint throws out `warning File ignored because of a matching ignore pattern. Us
879
907
  <details>
880
908
  <summary>Click to expand</summary>
881
909
 
882
- Based on the discussion from [this issue](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.
910
+ Based on the discussion from [this issue](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.
883
911
 
884
912
  So you can setup a `.lintstagedrc.js` config file to do this:
885
913
 
package/lib/loadConfig.js CHANGED
@@ -7,6 +7,7 @@ import debug from 'debug'
7
7
  import YAML from 'yaml'
8
8
 
9
9
  import { dynamicImport } from './dynamicImport.js'
10
+ import { failedToLoadConfig } from './messages.js'
10
11
  import { resolveConfig } from './resolveConfig.js'
11
12
  import {
12
13
  CONFIG_FILE_NAMES,
@@ -117,8 +118,8 @@ export const loadConfig = async ({ configPath, cwd }, logger) => {
117
118
 
118
119
  return { config, filepath }
119
120
  } catch (error) {
120
- debugLog('Failed to load configuration!')
121
- logger.error(error)
121
+ debugLog('Failed to load configuration from `%s` with error:\n', configPath, error)
122
+ logger.error(failedToLoadConfig(configPath))
122
123
  return {}
123
124
  }
124
125
  }
package/lib/messages.js CHANGED
@@ -85,3 +85,15 @@ export const RESTORE_STASH_EXAMPLE = ` Any lost modifications can be restored f
85
85
  `
86
86
 
87
87
  export const CONFIG_STDIN_ERROR = chalk.redBright(`${error} Failed to read config from stdin.`)
88
+
89
+ export const failedToLoadConfig = (filepath) =>
90
+ chalk.redBright(`${error} Failed to read config from file "${filepath}".`)
91
+
92
+ export const failedToParseConfig = (
93
+ filepath,
94
+ error
95
+ ) => `${chalk.redBright(`${error} Failed to parse config from file "${filepath}".`)}
96
+
97
+ ${error}
98
+
99
+ See https://github.com/okonet/lint-staged#configuration.`
@@ -96,7 +96,7 @@ const interruptExecutionOnError = (ctx, execaChildProcess) => {
96
96
  }
97
97
 
98
98
  /**
99
- * Create a error output dependding on process result.
99
+ * Create a error output depending on process result.
100
100
  *
101
101
  * @param {string} command
102
102
  * @param {Object} result
@@ -4,7 +4,7 @@ import { inspect } from 'node:util'
4
4
 
5
5
  import debug from 'debug'
6
6
 
7
- import { configurationError } from './messages.js'
7
+ import { configurationError, failedToParseConfig } from './messages.js'
8
8
  import { ConfigEmptyError, ConfigFormatError } from './symbols.js'
9
9
  import { validateBraces } from './validateBraces.js'
10
10
 
@@ -23,14 +23,7 @@ const TEST_DEPRECATED_KEYS = new Map([
23
23
  ['relative', (key) => typeof key === 'boolean'],
24
24
  ])
25
25
 
26
- /**
27
- * Runs config validation. Throws error if the config is not valid.
28
- * @param {Object} config
29
- * @param {string} configPath
30
- * @param {Logger} logger
31
- * @returns {Object} config
32
- */
33
- export const validateConfig = (config, configPath, logger) => {
26
+ export const validateConfigLogic = (config, configPath, logger) => {
34
27
  debugLog('Validating config from `%s`...', configPath)
35
28
 
36
29
  if (!config || (typeof config !== 'object' && typeof config !== 'function')) {
@@ -100,11 +93,7 @@ export const validateConfig = (config, configPath, logger) => {
100
93
  if (errors.length) {
101
94
  const message = errors.join('\n\n')
102
95
 
103
- logger.error(`Could not parse lint-staged config.
104
-
105
- ${message}
106
-
107
- See https://github.com/okonet/lint-staged#configuration.`)
96
+ logger.error(failedToParseConfig(configPath, message))
108
97
 
109
98
  throw new Error(message)
110
99
  }
@@ -114,3 +103,19 @@ See https://github.com/okonet/lint-staged#configuration.`)
114
103
 
115
104
  return validatedConfig
116
105
  }
106
+
107
+ /**
108
+ * Runs config validation. Throws error if the config is not valid.
109
+ * @param {Object} config
110
+ * @param {string} configPath
111
+ * @param {Logger} logger
112
+ * @returns {Object} config
113
+ */
114
+ export const validateConfig = (config, configPath, logger) => {
115
+ try {
116
+ return validateConfigLogic(config, configPath, logger)
117
+ } catch (error) {
118
+ logger.error(failedToParseConfig(configPath, error))
119
+ throw error
120
+ }
121
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lint-staged",
3
- "version": "15.2.2",
3
+ "version": "15.2.5",
4
4
  "description": "Lint files staged by git",
5
5
  "license": "MIT",
6
6
  "repository": "https://github.com/okonet/lint-staged",
@@ -36,34 +36,34 @@
36
36
  "tag": "npx changeset tag"
37
37
  },
38
38
  "dependencies": {
39
- "chalk": "5.3.0",
40
- "commander": "11.1.0",
41
- "debug": "4.3.4",
42
- "execa": "8.0.1",
43
- "lilconfig": "3.0.0",
44
- "listr2": "8.0.1",
45
- "micromatch": "4.0.5",
46
- "pidtree": "0.6.0",
47
- "string-argv": "0.3.2",
48
- "yaml": "2.3.4"
39
+ "chalk": "~5.3.0",
40
+ "commander": "~12.1.0",
41
+ "debug": "~4.3.4",
42
+ "execa": "~8.0.1",
43
+ "lilconfig": "~3.1.1",
44
+ "listr2": "~8.2.1",
45
+ "micromatch": "~4.0.7",
46
+ "pidtree": "~0.6.0",
47
+ "string-argv": "~0.3.2",
48
+ "yaml": "~2.4.2"
49
49
  },
50
50
  "devDependencies": {
51
51
  "@changesets/changelog-github": "0.5.0",
52
- "@changesets/cli": "2.27.1",
53
- "@commitlint/cli": "18.4.4",
54
- "@commitlint/config-conventional": "18.4.4",
52
+ "@changesets/cli": "2.27.3",
53
+ "@commitlint/cli": "19.3.0",
54
+ "@commitlint/config-conventional": "19.2.2",
55
55
  "consolemock": "1.1.0",
56
56
  "cross-env": "7.0.3",
57
- "eslint": "8.56.0",
57
+ "eslint": "8.57.0",
58
58
  "eslint-config-prettier": "9.1.0",
59
59
  "eslint-plugin-import": "2.29.1",
60
60
  "eslint-plugin-node": "11.1.0",
61
61
  "eslint-plugin-prettier": "5.1.3",
62
- "husky": "8.0.3",
62
+ "husky": "9.0.11",
63
63
  "jest": "29.7.0",
64
64
  "jest-snapshot-serializer-ansi": "2.1.0",
65
65
  "mock-stdin": "1.0.0",
66
- "prettier": "3.2.4"
66
+ "prettier": "3.2.5"
67
67
  },
68
68
  "keywords": [
69
69
  "lint",