diff --git a/CHANGELOG.md b/CHANGELOG.md index dd6471a8d..ffc185b03 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel - TypeScript: Add nested namespace handling ([#1763], thanks [@julien1619]) - [`namespace`]/`ExportMap`: Fix interface declarations for TypeScript ([#1764], thanks [@julien1619]) - [`no-unused-modules`]: avoid order-dependence ([#1744], thanks [@darkartur]) +- [`no-internal-modules`]: also check `export from` syntax ([#1691], thanks [@adjerbetian]) ### Changed - [Refactor] `no-extraneous-dependencies`: use moduleVisitor ([#1735], thanks [@adamborowski]) @@ -702,6 +703,7 @@ for info on changes for earlier releases. [#1722]: https://github.com/benmosher/eslint-plugin-import/issues/1722 [#1719]: https://github.com/benmosher/eslint-plugin-import/pull/1719 [#1702]: https://github.com/benmosher/eslint-plugin-import/issues/1702 +[#1691]: https://github.com/benmosher/eslint-plugin-import/pull/1691 [#1690]: https://github.com/benmosher/eslint-plugin-import/pull/1690 [#1681]: https://github.com/benmosher/eslint-plugin-import/pull/1681 [#1676]: https://github.com/benmosher/eslint-plugin-import/pull/1676 @@ -1186,3 +1188,4 @@ for info on changes for earlier releases. [@MikeyBeLike]: https://github.com/MikeyBeLike [@barbogast]: https://github.com/barbogast [@adamborowski]: https://github.com/adamborowski +[@adjerbetian]: https://github.com/adjerbetian diff --git a/docs/rules/no-internal-modules.md b/docs/rules/no-internal-modules.md index 8d99c3529..7bbb2edd1 100644 --- a/docs/rules/no-internal-modules.md +++ b/docs/rules/no-internal-modules.md @@ -49,6 +49,9 @@ The following patterns are considered problems: import { settings } from './app/index'; // Reaching to "./app/index" is not allowed import userReducer from './reducer/user'; // Reaching to "./reducer/user" is not allowed import configureStore from './redux/configureStore'; // Reaching to "./redux/configureStore" is not allowed + +export { settings } from './app/index'; // Reaching to "./app/index" is not allowed +export * from './reducer/user'; // Reaching to "./reducer/user" is not allowed ``` The following patterns are NOT considered problems: @@ -61,4 +64,7 @@ The following patterns are NOT considered problems: import 'source-map-support/register'; import { settings } from '../app'; import getUser from '../actions/getUser'; + +export * from 'source-map-support/register'; +export { settings } from '../app'; ``` diff --git a/src/rules/no-internal-modules.js b/src/rules/no-internal-modules.js index 9987dfd5c..b5d7496a2 100644 --- a/src/rules/no-internal-modules.js +++ b/src/rules/no-internal-modules.js @@ -91,6 +91,12 @@ module.exports = { ImportDeclaration(node) { checkImportForReaching(node.source.value, node.source) }, + ExportAllDeclaration(node) { + checkImportForReaching(node.source.value, node.source) + }, + ExportNamedDeclaration(node) { + checkImportForReaching(node.source.value, node.source) + }, CallExpression(node) { if (isStaticRequire(node)) { const [ firstArgument ] = node.arguments diff --git a/tests/files/internal-modules/typescript/plugin2/app/index.ts b/tests/files/internal-modules/typescript/plugin2/app/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/internal-modules/typescript/plugin2/index.ts b/tests/files/internal-modules/typescript/plugin2/index.ts new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/internal-modules/typescript/plugin2/internal.ts b/tests/files/internal-modules/typescript/plugin2/internal.ts new file mode 100644 index 000000000..e69de29bb diff --git a/tests/files/internal-modules/typescript/plugins.ts b/tests/files/internal-modules/typescript/plugins.ts new file mode 100644 index 000000000..e69de29bb diff --git a/tests/src/rules/no-internal-modules.js b/tests/src/rules/no-internal-modules.js index 8ed1c623e..5058fcb34 100644 --- a/tests/src/rules/no-internal-modules.js +++ b/tests/src/rules/no-internal-modules.js @@ -7,6 +7,7 @@ const ruleTester = new RuleTester() ruleTester.run('no-internal-modules', rule, { valid: [ + // imports test({ code: 'import a from "./plugin2"', filename: testFilePath('./internal-modules/plugins/plugin.js'), @@ -57,9 +58,44 @@ ruleTester.run('no-internal-modules', rule, { allow: [ '**/index{.js,}' ], } ], }), + // exports + test({ + code: 'export {a} from "./internal.js"', + filename: testFilePath('./internal-modules/plugins/plugin2/index.js'), + }), + test({ + code: 'export * from "lodash.get"', + filename: testFilePath('./internal-modules/plugins/plugin2/index.js'), + }), + test({ + code: 'export {b} from "@org/package"', + filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'), + }), + test({ + code: 'export {b} from "../../api/service"', + filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'), + options: [ { + allow: [ '**/api/*' ], + } ], + }), + test({ + code: 'export * from "jquery/dist/jquery"', + filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'), + options: [ { + allow: [ 'jquery/dist/*' ], + } ], + }), + test({ + code: 'export * from "./app/index.js";\nexport * from "./app/index"', + filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'), + options: [ { + allow: [ '**/index{.js,}' ], + } ], + }), ], invalid: [ + // imports test({ code: 'import "./plugin2/index.js";\nimport "./plugin2/app/index"', filename: testFilePath('./internal-modules/plugins/plugin.js'), @@ -126,5 +162,72 @@ ruleTester.run('no-internal-modules', rule, { }, ], }), + // exports + test({ + code: 'export * from "./plugin2/index.js";\nexport * from "./plugin2/app/index"', + filename: testFilePath('./internal-modules/plugins/plugin.js'), + options: [ { + allow: [ '*/index.js' ], + } ], + errors: [ { + message: 'Reaching to "./plugin2/app/index" is not allowed.', + line: 2, + column: 15, + } ], + }), + test({ + code: 'export * from "./app/index.js"', + filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'), + errors: [ { + message: 'Reaching to "./app/index.js" is not allowed.', + line: 1, + column: 15, + } ], + }), + test({ + code: 'export {b} from "./plugin2/internal"', + filename: testFilePath('./internal-modules/plugins/plugin.js'), + errors: [ { + message: 'Reaching to "./plugin2/internal" is not allowed.', + line: 1, + column: 17, + } ], + }), + test({ + code: 'export {a} from "../api/service/index"', + filename: testFilePath('./internal-modules/plugins/plugin.js'), + options: [ { + allow: [ '**/internal-modules/*' ], + } ], + errors: [ + { + message: 'Reaching to "../api/service/index" is not allowed.', + line: 1, + column: 17, + }, + ], + }), + test({ + code: 'export {b} from "@org/package/internal"', + filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'), + errors: [ + { + message: 'Reaching to "@org/package/internal" is not allowed.', + line: 1, + column: 17, + }, + ], + }), + test({ + code: 'export {get} from "debug/node"', + filename: testFilePath('./internal-modules/plugins/plugin.js'), + errors: [ + { + message: 'Reaching to "debug/node" is not allowed.', + line: 1, + column: 19, + }, + ], + }), ], })