Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update no internal modules with exports #1691

Merged
merged 1 commit into from Jun 2, 2020
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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])
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
6 changes: 6 additions & 0 deletions docs/rules/no-internal-modules.md
Expand Up @@ -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:
Expand All @@ -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';
```
6 changes: 6 additions & 0 deletions src/rules/no-internal-modules.js
Expand Up @@ -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
Expand Down
Empty file.
Empty file.
Empty file.
Empty file.
103 changes: 103 additions & 0 deletions tests/src/rules/no-internal-modules.js
Expand Up @@ -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'),
Expand Down Expand Up @@ -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'),
Expand Down Expand Up @@ -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,
},
],
}),
],
})