From 2fd998840b5f0a64531ed807be94e26db02838bc Mon Sep 17 00:00:00 2001 From: Dennis Schroer Date: Sat, 12 Nov 2016 12:53:12 +0100 Subject: [PATCH 1/5] If extended config is from a plugin, use that one --- options-manager.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/options-manager.js b/options-manager.js index 32e8f752..b73081b3 100644 --- a/options-manager.js +++ b/options-manager.js @@ -145,6 +145,11 @@ function buildConfig(opts) { return name; } + // don't do anything if it's a config from a plugin + if (name.indexOf('plugin:') === 0) { + return name; + } + if (!name.includes('eslint-config-')) { name = `eslint-config-${name}`; } From 467bbfd5b1c539e16f8bce284e108a329967eac4 Mon Sep 17 00:00:00 2001 From: Dennis Schroer Date: Sat, 12 Nov 2016 13:10:14 +0100 Subject: [PATCH 2/5] Add tests for the extends option --- test/options-manager.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/test/options-manager.js b/test/options-manager.js index 4891a8a4..057c6ff4 100644 --- a/test/options-manager.js +++ b/test/options-manager.js @@ -88,6 +88,14 @@ test('buildConfig: settings', t => { t.deepEqual(config.baseConfig.settings, settings); }); +test('buildConfig: extends', t => { + const extendsOption = ['plugin:foo/bar', 'eslint-config-foo-bar', 'foo-bar-two']; + const config = manager.buildConfig({extends: extendsOption}); + t.is(config.baseConfig.extends[config.baseConfig.extends.length - 3], 'plugin:foo/bar'); + t.is(config.baseConfig.extends[config.baseConfig.extends.length - 2], 'cwd/eslint-config-foo-bar'); + t.is(config.baseConfig.extends[config.baseConfig.extends.length - 1], 'cwd/eslint-config-foo-bar-two'); +}); + test('findApplicableOverrides', t => { const result = manager.findApplicableOverrides('/user/dir/foo.js', [ {files: '**/f*.js'}, From 656daf8a33c17f9cab490ad0e3f5df44c18eede4 Mon Sep 17 00:00:00 2001 From: Dennis Schroer Date: Sat, 12 Nov 2016 13:15:01 +0100 Subject: [PATCH 3/5] Update README --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index bf676a10..bf22d053 100644 --- a/readme.md +++ b/readme.md @@ -212,7 +212,7 @@ Include third-party [plugins](http://eslint.org/docs/user-guide/configuring.html Type: `Array`, `string` -Use one or more [shareable configs](http://eslint.org/docs/developer-guide/shareable-configs.html) to override any of the default rules (like `rules` above). +Use one or more [shareable configs](http://eslint.org/docs/developer-guide/shareable-configs.html) or [plugin configs](http://eslint.org/docs/user-guide/configuring#using-the-configuration-from-a-plugin) to override any of the default rules (like `rules` above). ### extensions From 366625b85f1ee9ed4d900a5a75fef6fca7b411d0 Mon Sep 17 00:00:00 2001 From: Dennis Schroer Date: Sat, 12 Nov 2016 16:06:26 +0100 Subject: [PATCH 4/5] Apply requested changes --- options-manager.js | 2 +- test/options-manager.js | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/options-manager.js b/options-manager.js index b73081b3..dbd4bdcf 100644 --- a/options-manager.js +++ b/options-manager.js @@ -146,7 +146,7 @@ function buildConfig(opts) { } // don't do anything if it's a config from a plugin - if (name.indexOf('plugin:') === 0) { + if (name.startsWith('plugin:')) { return name; } diff --git a/test/options-manager.js b/test/options-manager.js index 057c6ff4..90a40cb4 100644 --- a/test/options-manager.js +++ b/test/options-manager.js @@ -91,9 +91,10 @@ test('buildConfig: settings', t => { test('buildConfig: extends', t => { const extendsOption = ['plugin:foo/bar', 'eslint-config-foo-bar', 'foo-bar-two']; const config = manager.buildConfig({extends: extendsOption}); - t.is(config.baseConfig.extends[config.baseConfig.extends.length - 3], 'plugin:foo/bar'); - t.is(config.baseConfig.extends[config.baseConfig.extends.length - 2], 'cwd/eslint-config-foo-bar'); - t.is(config.baseConfig.extends[config.baseConfig.extends.length - 1], 'cwd/eslint-config-foo-bar-two'); + const extendsConfig = config.baseConfig.extends; + t.is(extendsConfig[extendsConfig.length - 3], 'plugin:foo/bar'); + t.is(extendsConfig[extendsConfig.length - 2], 'cwd/eslint-config-foo-bar'); + t.is(extendsConfig[extendsConfig.length - 1], 'cwd/eslint-config-foo-bar-two'); }); test('findApplicableOverrides', t => { From 2180f382c699c0c834e9563fd230872ac1b36097 Mon Sep 17 00:00:00 2001 From: Dennis Schroer Date: Sun, 13 Nov 2016 12:38:43 +0100 Subject: [PATCH 5/5] Improve test by using Array#slice() --- test/options-manager.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/test/options-manager.js b/test/options-manager.js index 90a40cb4..be8c0278 100644 --- a/test/options-manager.js +++ b/test/options-manager.js @@ -89,12 +89,18 @@ test('buildConfig: settings', t => { }); test('buildConfig: extends', t => { - const extendsOption = ['plugin:foo/bar', 'eslint-config-foo-bar', 'foo-bar-two']; + const extendsOption = [ + 'plugin:foo/bar', + 'eslint-config-foo-bar', + 'foo-bar-two' + ]; const config = manager.buildConfig({extends: extendsOption}); const extendsConfig = config.baseConfig.extends; - t.is(extendsConfig[extendsConfig.length - 3], 'plugin:foo/bar'); - t.is(extendsConfig[extendsConfig.length - 2], 'cwd/eslint-config-foo-bar'); - t.is(extendsConfig[extendsConfig.length - 1], 'cwd/eslint-config-foo-bar-two'); + t.deepEqual(extendsConfig.slice(-3), [ + 'plugin:foo/bar', + 'cwd/eslint-config-foo-bar', + 'cwd/eslint-config-foo-bar-two' + ]); }); test('findApplicableOverrides', t => {