Skip to content

Commit

Permalink
[patch] no-extraneous-dependencies: ensure node.source is truthy
Browse files Browse the repository at this point in the history
These tests already passed, implying that import-js#1589 is a non-issue. However,
the guards are still good to add.
  • Loading branch information
ljharb committed Jan 1, 2020
1 parent ae747c0 commit f790737
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -13,6 +13,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
- [`no-unused-modules`]: fix usage of `import/extensions` settings ([#1560], thanks [@stekycz])
- [`import/extensions`]: ignore non-main modules ([#1563], thanks [@saschanaz])
- TypeScript config: lookup for external modules in @types folder ([#1526], thanks [@joaovieira])
- [`no-extraneous-dependencies`]: ensure `node.source` is truthy ([#1589], thanks [@ljharb])

## [2.19.1] - 2019-12-08
### Fixed
Expand Down Expand Up @@ -628,6 +629,7 @@ for info on changes for earlier releases.

[`memo-parser`]: ./memo-parser/README.md

[#1589]: https://github.com/benmosher/eslint-plugin-import/issues/1589
[#1586]: https://github.com/benmosher/eslint-plugin-import/pull/1586
[#1563]: https://github.com/benmosher/eslint-plugin-import/pull/1563
[#1560]: https://github.com/benmosher/eslint-plugin-import/pull/1560
Expand Down
8 changes: 6 additions & 2 deletions src/rules/no-extraneous-dependencies.js
Expand Up @@ -203,15 +203,19 @@ module.exports = {
// todo: use module visitor from module-utils core
return {
ImportDeclaration: function (node) {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
if (node.source) {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
}
},
ExportNamedDeclaration: function (node) {
if (node.source) {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
}
},
ExportAllDeclaration: function (node) {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
if (node.source) {
reportIfMissing(context, deps, depsOptions, node, node.source.value)
}
},
CallExpression: function handleRequires(node) {
if (isStaticRequire(node)) {
Expand Down
3 changes: 3 additions & 0 deletions tests/src/rules/no-extraneous-dependencies.js
Expand Up @@ -125,6 +125,9 @@ ruleTester.run('no-extraneous-dependencies', rule, {
test({ code: 'export { foo } from "lodash.cond"' }),
test({ code: 'export * from "lodash.cond"' }),
test({ code: 'export function getToken() {}' }),
test({ code: 'export class Component extends React.Component {}' }),
test({ code: 'export function Component() {}' }),
test({ code: 'export const Component = () => {}' }),
],
invalid: [
test({
Expand Down

0 comments on commit f790737

Please sign in to comment.