diff --git a/CHANGELOG.md b/CHANGELOG.md index cef8d8e53..4cb0ce9dc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,8 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel - [`prefer-default-export`], new rule. ([#308], thanks [@gavriguy]) ### Fixed -- ignore namespace / ES7 re-exports in [`no-mutable-exports`]. ([#317], fixed by [#322]. thanks [@borisyankov] + [@jfmengels]) +- Ignore namespace / ES7 re-exports in [`no-mutable-exports`]. ([#317], fixed by [#322]. thanks [@borisyankov] + [@jfmengels]) +- Make [`no-extraneous-dependencies`] handle scoped packages ([#316], thanks [@jfmengels]) ## [1.7.0] - 2016-05-06 ### Added @@ -18,7 +19,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel - add [`no-mutable-exports`] rule ([#290], thanks [@josh]) - [`import/extensions` setting]: a whitelist of file extensions to parse as modules and search for `export`s. If unspecified, all extensions are considered valid (for now). - In v2, this will likely default to `['.js', MODULE_EXT]`,. ([#297], to fix [#267]) + In v2, this will likely default to `['.js', MODULE_EXT]`. ([#297], to fix [#267]) ### Fixed - [`extensions`]: fallback to source path for extension enforcement if imported @@ -210,6 +211,7 @@ for info on changes for earlier releases. [`prefer-default-export`]: ./docs/rules/prefer-default-export.md [#322]: https://github.com/benmosher/eslint-plugin-import/pull/322 +[#316]: https://github.com/benmosher/eslint-plugin-import/pull/316 [#308]: https://github.com/benmosher/eslint-plugin-import/pull/308 [#298]: https://github.com/benmosher/eslint-plugin-import/pull/298 [#297]: https://github.com/benmosher/eslint-plugin-import/pull/297 diff --git a/src/rules/no-extraneous-dependencies.js b/src/rules/no-extraneous-dependencies.js index 8f571fe2a..becbad092 100644 --- a/src/rules/no-extraneous-dependencies.js +++ b/src/rules/no-extraneous-dependencies.js @@ -39,7 +39,10 @@ function reportIfMissing(context, deps, allowDevDeps, allowOptDeps, node, name) if (importType(name, context) !== 'external') { return } - const packageName = name.split('/')[0] + const splitName = name.split('/') + const packageName = splitName[0][0] === '@' + ? splitName.slice(0, 2).join('/') + : splitName[0] const isInDeps = deps.dependencies[packageName] !== undefined const isInDevDeps = deps.devDependencies[packageName] !== undefined diff --git a/tests/files/package.json b/tests/files/package.json index 3e2bd0fa0..d0ef9601b 100644 --- a/tests/files/package.json +++ b/tests/files/package.json @@ -7,6 +7,7 @@ "eslint": "2.x" }, "dependencies": { + "@scope/core": "^1.0.0", "lodash.cond": "^4.3.0", "pkg-up": "^1.0.0" }, diff --git a/tests/src/rules/no-extraneous-dependencies.js b/tests/src/rules/no-extraneous-dependencies.js index 7335e1fd3..e84988009 100644 --- a/tests/src/rules/no-extraneous-dependencies.js +++ b/tests/src/rules/no-extraneous-dependencies.js @@ -21,11 +21,12 @@ ruleTester.run('no-extraneous-dependencies', rule, { test({ code: 'import "fs"'}), test({ code: 'import "./foo"'}), test({ code: 'import "lodash.isarray"'}), + test({ code: 'import "@scope/core"'}), // 'project' type test({ code: 'import "importType"', - settings: { "import/resolver": { node: { paths: [ path.join(__dirname, '../../files') ] } } }, + settings: { 'import/resolver': { node: { paths: [ path.join(__dirname, '../../files') ] } } }, }), ], invalid: [ @@ -36,6 +37,20 @@ ruleTester.run('no-extraneous-dependencies', rule, { message: '\'not-a-dependency\' should be listed in the project\'s dependencies. Run \'npm i -S not-a-dependency\' to add it', }], }), + test({ + code: 'var donthaveit = require("@scope/donthaveit")', + errors: [{ + ruleId: 'no-extraneous-dependencies', + message: '\'@scope/donthaveit\' should be listed in the project\'s dependencies. Run \'npm i -S @scope/donthaveit\' to add it', + }], + }), + test({ + code: 'var donthaveit = require("@scope/donthaveit/lib/foo")', + errors: [{ + ruleId: 'no-extraneous-dependencies', + message: '\'@scope/donthaveit\' should be listed in the project\'s dependencies. Run \'npm i -S @scope/donthaveit\' to add it', + }], + }), test({ code: 'import "eslint"', options: [{devDependencies: false}],