From 24c04b78fafe7d2ae8fe1aabbfd2028be72a9683 Mon Sep 17 00:00:00 2001 From: Ben Mosher Date: Tue, 20 Sep 2016 09:13:31 -0400 Subject: [PATCH] Fix #545: allow re-export of defaults from ignored files (i.e. node_modules) --- src/rules/default.js | 2 +- tests/files/default-export-from-ignored.js | 1 + tests/files/default-export-from-named.js | 1 + tests/files/default-export-from.js | 1 + tests/src/rules/default.js | 21 +++++++++++++++++++++ 5 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/files/default-export-from-ignored.js create mode 100644 tests/files/default-export-from-named.js create mode 100644 tests/files/default-export-from.js diff --git a/src/rules/default.js b/src/rules/default.js index 4aa5b965f..ed87e5442 100644 --- a/src/rules/default.js +++ b/src/rules/default.js @@ -19,7 +19,7 @@ module.exports = function (context) { if (imports.errors.length) { imports.reportErrors(context, node) - } else if (!imports.get('default')) { + } else if (imports.get('default') === undefined) { context.report(defaultSpecifier, 'No default export found in module.') } } diff --git a/tests/files/default-export-from-ignored.js b/tests/files/default-export-from-ignored.js new file mode 100644 index 000000000..3113adc1a --- /dev/null +++ b/tests/files/default-export-from-ignored.js @@ -0,0 +1 @@ +export { foo as default } from './common.js' diff --git a/tests/files/default-export-from-named.js b/tests/files/default-export-from-named.js new file mode 100644 index 000000000..916f7bafa --- /dev/null +++ b/tests/files/default-export-from-named.js @@ -0,0 +1 @@ +export { d as default } from './named-exports.js' diff --git a/tests/files/default-export-from.js b/tests/files/default-export-from.js new file mode 100644 index 000000000..1a3a112f5 --- /dev/null +++ b/tests/files/default-export-from.js @@ -0,0 +1 @@ +export default from './bar' diff --git a/tests/src/rules/default.js b/tests/src/rules/default.js index 4308d3483..003728295 100644 --- a/tests/src/rules/default.js +++ b/tests/src/rules/default.js @@ -66,6 +66,27 @@ ruleTester.run('default', rule, { parser: 'babel-eslint', }), + // #545: more ES7 cases + test({ + code: "import bar from './default-export-from.js';", + parser: 'babel-eslint', + }), + test({ + code: "import bar from './default-export-from-named.js';", + parser: 'babel-eslint', + }), + test({ + code: "import bar from './default-export-from-ignored.js';", + settings: { 'import/ignore': ['common'] }, + parser: 'babel-eslint', + }), + test({ + code: "export bar from './default-export-from-ignored.js';", + settings: { 'import/ignore': ['common'] }, + parser: 'babel-eslint', + }), + + ...SYNTAX_CASES, ],