Skip to content

Commit 4bef26e

Browse files
Iiro Jäppinenokonet
Iiro Jäppinen
authored andcommittedJul 1, 2019
feat: add deprecation error for advanced configuration
1 parent e829646 commit 4bef26e

File tree

4 files changed

+176
-3
lines changed

4 files changed

+176
-3
lines changed
 

‎src/runAll.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ module.exports = async function runAll(
5858
console.warn(
5959
dedent`${symbols.warning} ${chalk.yellow(
6060
`lint-staged generated an argument string of ${argLength} characters, and commands might not run correctly on your platform.
61-
It is recommended to use functions as linters and split your command based on the number of staged files. For more info, please read:
61+
It is recommended to use functions as linters and split your command based on the number of staged files. For more info, please visit:
6262
https://github.com/okonet/lint-staged#using-js-functions-to-customize-linter-commands
6363
`
6464
)}`

‎src/validateConfig.js

+25-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,17 @@ const format = require('stringify-object')
77

88
const debug = require('debug')('lint-staged:cfg')
99

10+
const TEST_DEPRECATED_KEYS = new Map([
11+
['concurrent', key => typeof key === 'boolean'],
12+
['chunkSize', key => typeof key === 'number'],
13+
['globOptions', key => typeof key === 'object'],
14+
['linters', key => typeof key === 'object'],
15+
['ignore', key => Array.isArray(key)],
16+
['subTaskConcurrency', key => typeof key === 'number'],
17+
['renderer', key => typeof key === 'string'],
18+
['relative', key => typeof key === 'boolean']
19+
])
20+
1021
const formatError = helpMsg => `● Validation Error:
1122
1223
${helpMsg}
@@ -42,6 +53,19 @@ module.exports = function validateConfig(config) {
4253
}
4354

4455
globs.forEach(key => {
56+
if (TEST_DEPRECATED_KEYS.has(key)) {
57+
const testFn = TEST_DEPRECATED_KEYS.get(key)
58+
if (testFn(config[key])) {
59+
errors.push(
60+
createError(
61+
key,
62+
'Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged',
63+
config[key]
64+
)
65+
)
66+
}
67+
}
68+
4569
if (
4670
(!Array.isArray(config[key]) ||
4771
config[key].some(item => typeof item !== 'string' && typeof item !== 'function')) &&
@@ -52,7 +76,7 @@ module.exports = function validateConfig(config) {
5276
createError(
5377
key,
5478
'Should be a string, a function, or an array of strings and functions',
55-
key
79+
config[key]
5680
)
5781
)
5882
}

‎test/__snapshots__/validateConfig.spec.js.snap

+132-1
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,140 @@ exports[`validateConfig should throw and should print validation errors for inva
1111
1212
Should be a string, a function, or an array of strings and functions.
1313
14-
Configured value is: 'foo'
14+
Configured value is: false
1515
1616
Please refer to https://github.com/okonet/lint-staged#configuration for more information..."
1717
`;
1818

1919
exports[`validateConfig should throw and should print validation errors for invalid config 1 1`] = `"Configuration should be an object!"`;
20+
21+
exports[`validateConfig should throw when detecting deprecated advanced configuration 1`] = `
22+
"● Validation Error:
23+
24+
Invalid value for 'chunkSize'.
25+
26+
Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged.
27+
28+
Configured value is: 10
29+
30+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
31+
● Validation Error:
32+
33+
Invalid value for 'chunkSize'.
34+
35+
Should be a string, a function, or an array of strings and functions.
36+
37+
Configured value is: 10
38+
39+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
40+
● Validation Error:
41+
42+
Invalid value for 'concurrent'.
43+
44+
Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged.
45+
46+
Configured value is: false
47+
48+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
49+
● Validation Error:
50+
51+
Invalid value for 'concurrent'.
52+
53+
Should be a string, a function, or an array of strings and functions.
54+
55+
Configured value is: false
56+
57+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
58+
● Validation Error:
59+
60+
Invalid value for 'globOptions'.
61+
62+
Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged.
63+
64+
Configured value is: {matchBase: false}
65+
66+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
67+
● Validation Error:
68+
69+
Invalid value for 'globOptions'.
70+
71+
Should be a string, a function, or an array of strings and functions.
72+
73+
Configured value is: {matchBase: false}
74+
75+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
76+
● Validation Error:
77+
78+
Invalid value for 'ignore'.
79+
80+
Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged.
81+
82+
Configured value is: ['test.js']
83+
84+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
85+
● Validation Error:
86+
87+
Invalid value for 'linters'.
88+
89+
Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged.
90+
91+
Configured value is: {'*.js': ['eslint']}
92+
93+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
94+
● Validation Error:
95+
96+
Invalid value for 'linters'.
97+
98+
Should be a string, a function, or an array of strings and functions.
99+
100+
Configured value is: {'*.js': ['eslint']}
101+
102+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
103+
● Validation Error:
104+
105+
Invalid value for 'relative'.
106+
107+
Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged.
108+
109+
Configured value is: true
110+
111+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
112+
● Validation Error:
113+
114+
Invalid value for 'relative'.
115+
116+
Should be a string, a function, or an array of strings and functions.
117+
118+
Configured value is: true
119+
120+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
121+
● Validation Error:
122+
123+
Invalid value for 'renderer'.
124+
125+
Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged.
126+
127+
Configured value is: 'silent'
128+
129+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
130+
● Validation Error:
131+
132+
Invalid value for 'subTaskConcurrency'.
133+
134+
Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged.
135+
136+
Configured value is: 10
137+
138+
Please refer to https://github.com/okonet/lint-staged#configuration for more information...
139+
● Validation Error:
140+
141+
Invalid value for 'subTaskConcurrency'.
142+
143+
Should be a string, a function, or an array of strings and functions.
144+
145+
Configured value is: 10
146+
147+
Please refer to https://github.com/okonet/lint-staged#configuration for more information..."
148+
`;
149+
150+
exports[`validateConfig should throw when detecting deprecated advanced configuration 2`] = `""`;

‎test/validateConfig.spec.js

+18
Original file line numberDiff line numberDiff line change
@@ -48,4 +48,22 @@ describe('validateConfig', () => {
4848
).not.toThrow()
4949
expect(console.printHistory()).toMatchSnapshot()
5050
})
51+
52+
it('should throw when detecting deprecated advanced configuration', () => {
53+
const advancedConfig = {
54+
chunkSize: 10,
55+
concurrent: false,
56+
globOptions: { matchBase: false },
57+
ignore: ['test.js'],
58+
linters: {
59+
'*.js': ['eslint']
60+
},
61+
relative: true,
62+
renderer: 'silent',
63+
subTaskConcurrency: 10
64+
}
65+
66+
expect(() => validateConfig(advancedConfig)).toThrowErrorMatchingSnapshot()
67+
expect(console.printHistory()).toMatchSnapshot()
68+
})
5169
})

0 commit comments

Comments
 (0)
Please sign in to comment.