Skip to content

no-extraneous-dependencies: Handle scoped packages. Fixes #316 #324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agh, thanks for catching this


### Fixed
- [`extensions`]: fallback to source path for extension enforcement if imported
Expand Down Expand Up @@ -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
Expand Down
5 changes: 4 additions & 1 deletion src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/files/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"eslint": "2.x"
},
"dependencies": {
"@scope/core": "^1.0.0",
"lodash.cond": "^4.3.0",
"pkg-up": "^1.0.0"
},
Expand Down
17 changes: 16 additions & 1 deletion tests/src/rules/no-extraneous-dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -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}],
Expand Down