Skip to content

Commit 99b3fbf

Browse files
marcusdarmstrongljharb
authored andcommitted
[Fix] no-extraneous-dependencies: Add support for export from
Fixes #1049.
1 parent 21bf8c6 commit 99b3fbf

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
44
This change log adheres to standards from [Keep a CHANGELOG](http://keepachangelog.com).
55

66
## [Unreleased]
7+
- [`no-extraneous-dependencies`]: Check `export from` ([#1049], thanks [@marcusdarmstrong])
78

89
### Added
910
- [`internal-regex`]: regex pattern for marking packages "internal" ([#1491], thanks [@Librazy])
@@ -691,6 +692,7 @@ for info on changes for earlier releases.
691692
[#1093]: https://github.com/benmosher/eslint-plugin-import/pull/1093
692693
[#1085]: https://github.com/benmosher/eslint-plugin-import/pull/1085
693694
[#1068]: https://github.com/benmosher/eslint-plugin-import/pull/1068
695+
[#1049]: https://github.com/benmosher/eslint-plugin-import/pull/1049
694696
[#1046]: https://github.com/benmosher/eslint-plugin-import/pull/1046
695697
[#944]: https://github.com/benmosher/eslint-plugin-import/pull/944
696698
[#912]: https://github.com/benmosher/eslint-plugin-import/pull/912
@@ -1022,3 +1024,4 @@ for info on changes for earlier releases.
10221024
[@brettz9]: https://github.com/brettz9
10231025
[@Taranys]: https://github.com/Taranys
10241026
[@maxmalov]: https://github.com/maxmalov
1027+
[@marcusdarmstrong]: https://github.com/marcusdarmstrong

src/rules/no-extraneous-dependencies.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,12 @@ module.exports = {
205205
ImportDeclaration: function (node) {
206206
reportIfMissing(context, deps, depsOptions, node, node.source.value)
207207
},
208+
ExportNamedDeclaration: function (node) {
209+
reportIfMissing(context, deps, depsOptions, node, node.source.value)
210+
},
211+
ExportAllDeclaration: function (node) {
212+
reportIfMissing(context, deps, depsOptions, node, node.source.value)
213+
},
208214
CallExpression: function handleRequires(node) {
209215
if (isStaticRequire(node)) {
210216
reportIfMissing(context, deps, depsOptions, node, node.arguments[0].value)

tests/src/rules/no-extraneous-dependencies.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ ruleTester.run('no-extraneous-dependencies', rule, {
122122
code: 'import foo from "@generated/foo"',
123123
options: [{packageDir: packageDirBundledDepsRaceCondition}],
124124
}),
125+
test({ code: 'export { foo } from "lodash.cond"' }),
126+
test({ code: 'export * from "lodash.cond"' }),
125127
],
126128
invalid: [
127129
test({
@@ -319,5 +321,19 @@ ruleTester.run('no-extraneous-dependencies', rule, {
319321
options: [{packageDir: packageDirBundledDepsRaceCondition}],
320322
errors: ["'@generated/bar' should be listed in the project's dependencies. Run 'npm i -S @generated/bar' to add it"],
321323
}),
324+
test({
325+
code: 'export { foo } from "not-a-dependency";',
326+
errors: [{
327+
ruleId: 'no-extraneous-dependencies',
328+
message: '\'not-a-dependency\' should be listed in the project\'s dependencies. Run \'npm i -S not-a-dependency\' to add it',
329+
}],
330+
}),
331+
test({
332+
code: 'export * from "not-a-dependency";',
333+
errors: [{
334+
ruleId: 'no-extraneous-dependencies',
335+
message: '\'not-a-dependency\' should be listed in the project\'s dependencies. Run \'npm i -S not-a-dependency\' to add it',
336+
}],
337+
}),
322338
],
323339
})

0 commit comments

Comments
 (0)