From 4bef26e3b59a12ecf6c0aa764d4e6aea8a13bc89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iiro=20Ja=CC=88ppinen?= Date: Mon, 1 Jul 2019 06:49:44 +0300 Subject: [PATCH] feat: add deprecation error for advanced configuration --- src/runAll.js | 2 +- src/validateConfig.js | 26 +++- .../__snapshots__/validateConfig.spec.js.snap | 133 +++++++++++++++++- test/validateConfig.spec.js | 18 +++ 4 files changed, 176 insertions(+), 3 deletions(-) diff --git a/src/runAll.js b/src/runAll.js index 2aa0ecbc4..13ec747da 100644 --- a/src/runAll.js +++ b/src/runAll.js @@ -58,7 +58,7 @@ module.exports = async function runAll( console.warn( dedent`${symbols.warning} ${chalk.yellow( `lint-staged generated an argument string of ${argLength} characters, and commands might not run correctly on your platform. -It is recommended to use functions as linters and split your command based on the number of staged files. For more info, please read: +It is recommended to use functions as linters and split your command based on the number of staged files. For more info, please visit: https://github.com/okonet/lint-staged#using-js-functions-to-customize-linter-commands ` )}` diff --git a/src/validateConfig.js b/src/validateConfig.js index 1e0f9bfa3..795199c24 100644 --- a/src/validateConfig.js +++ b/src/validateConfig.js @@ -7,6 +7,17 @@ const format = require('stringify-object') const debug = require('debug')('lint-staged:cfg') +const TEST_DEPRECATED_KEYS = new Map([ + ['concurrent', key => typeof key === 'boolean'], + ['chunkSize', key => typeof key === 'number'], + ['globOptions', key => typeof key === 'object'], + ['linters', key => typeof key === 'object'], + ['ignore', key => Array.isArray(key)], + ['subTaskConcurrency', key => typeof key === 'number'], + ['renderer', key => typeof key === 'string'], + ['relative', key => typeof key === 'boolean'] +]) + const formatError = helpMsg => `● Validation Error: ${helpMsg} @@ -42,6 +53,19 @@ module.exports = function validateConfig(config) { } globs.forEach(key => { + if (TEST_DEPRECATED_KEYS.has(key)) { + const testFn = TEST_DEPRECATED_KEYS.get(key) + if (testFn(config[key])) { + errors.push( + createError( + key, + 'Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged', + config[key] + ) + ) + } + } + if ( (!Array.isArray(config[key]) || config[key].some(item => typeof item !== 'string' && typeof item !== 'function')) && @@ -52,7 +76,7 @@ module.exports = function validateConfig(config) { createError( key, 'Should be a string, a function, or an array of strings and functions', - key + config[key] ) ) } diff --git a/test/__snapshots__/validateConfig.spec.js.snap b/test/__snapshots__/validateConfig.spec.js.snap index 28be0a280..3026e73f7 100644 --- a/test/__snapshots__/validateConfig.spec.js.snap +++ b/test/__snapshots__/validateConfig.spec.js.snap @@ -11,9 +11,140 @@ exports[`validateConfig should throw and should print validation errors for inva Should be a string, a function, or an array of strings and functions. - Configured value is: 'foo' + Configured value is: false Please refer to https://github.com/okonet/lint-staged#configuration for more information..." `; exports[`validateConfig should throw and should print validation errors for invalid config 1 1`] = `"Configuration should be an object!"`; + +exports[`validateConfig should throw when detecting deprecated advanced configuration 1`] = ` +"● Validation Error: + + Invalid value for 'chunkSize'. + + Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged. + + Configured value is: 10 + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'chunkSize'. + + Should be a string, a function, or an array of strings and functions. + + Configured value is: 10 + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'concurrent'. + + Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged. + + Configured value is: false + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'concurrent'. + + Should be a string, a function, or an array of strings and functions. + + Configured value is: false + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'globOptions'. + + Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged. + + Configured value is: {matchBase: false} + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'globOptions'. + + Should be a string, a function, or an array of strings and functions. + + Configured value is: {matchBase: false} + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'ignore'. + + Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged. + + Configured value is: ['test.js'] + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'linters'. + + Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged. + + Configured value is: {'*.js': ['eslint']} + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'linters'. + + Should be a string, a function, or an array of strings and functions. + + Configured value is: {'*.js': ['eslint']} + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'relative'. + + Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged. + + Configured value is: true + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'relative'. + + Should be a string, a function, or an array of strings and functions. + + Configured value is: true + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'renderer'. + + Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged. + + Configured value is: 'silent' + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'subTaskConcurrency'. + + Advanced configuration has been deprecated. For more info, please visit: https://github.com/okonet/lint-staged. + + Configured value is: 10 + +Please refer to https://github.com/okonet/lint-staged#configuration for more information... +● Validation Error: + + Invalid value for 'subTaskConcurrency'. + + Should be a string, a function, or an array of strings and functions. + + Configured value is: 10 + +Please refer to https://github.com/okonet/lint-staged#configuration for more information..." +`; + +exports[`validateConfig should throw when detecting deprecated advanced configuration 2`] = `""`; diff --git a/test/validateConfig.spec.js b/test/validateConfig.spec.js index f682278af..992f9e09e 100644 --- a/test/validateConfig.spec.js +++ b/test/validateConfig.spec.js @@ -48,4 +48,22 @@ describe('validateConfig', () => { ).not.toThrow() expect(console.printHistory()).toMatchSnapshot() }) + + it('should throw when detecting deprecated advanced configuration', () => { + const advancedConfig = { + chunkSize: 10, + concurrent: false, + globOptions: { matchBase: false }, + ignore: ['test.js'], + linters: { + '*.js': ['eslint'] + }, + relative: true, + renderer: 'silent', + subTaskConcurrency: 10 + } + + expect(() => validateConfig(advancedConfig)).toThrowErrorMatchingSnapshot() + expect(console.printHistory()).toMatchSnapshot() + }) })