Skip to content

Commit 9dfef28

Browse files
Alexandre Djerbetianljharb
authored andcommitted
[Fix] no-internal-modules: also check export from syntax
Fixes #1481.
1 parent 6dd28ea commit 9dfef28

File tree

8 files changed

+118
-0
lines changed

8 files changed

+118
-0
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ This change log adheres to standards from [Keep a CHANGELOG](http://keepachangel
2121
- TypeScript: Add nested namespace handling ([#1763], thanks [@julien1619])
2222
- [`namespace`]/`ExportMap`: Fix interface declarations for TypeScript ([#1764], thanks [@julien1619])
2323
- [`no-unused-modules`]: avoid order-dependence ([#1744], thanks [@darkartur])
24+
- [`no-internal-modules`]: also check `export from` syntax ([#1691], thanks [@adjerbetian])
2425

2526
### Changed
2627
- [Refactor] `no-extraneous-dependencies`: use moduleVisitor ([#1735], thanks [@adamborowski])
@@ -702,6 +703,7 @@ for info on changes for earlier releases.
702703
[#1722]: https://github.com/benmosher/eslint-plugin-import/issues/1722
703704
[#1719]: https://github.com/benmosher/eslint-plugin-import/pull/1719
704705
[#1702]: https://github.com/benmosher/eslint-plugin-import/issues/1702
706+
[#1691]: https://github.com/benmosher/eslint-plugin-import/pull/1691
705707
[#1690]: https://github.com/benmosher/eslint-plugin-import/pull/1690
706708
[#1681]: https://github.com/benmosher/eslint-plugin-import/pull/1681
707709
[#1676]: https://github.com/benmosher/eslint-plugin-import/pull/1676
@@ -1186,3 +1188,4 @@ for info on changes for earlier releases.
11861188
[@MikeyBeLike]: https://github.com/MikeyBeLike
11871189
[@barbogast]: https://github.com/barbogast
11881190
[@adamborowski]: https://github.com/adamborowski
1191+
[@adjerbetian]: https://github.com/adjerbetian

docs/rules/no-internal-modules.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ The following patterns are considered problems:
4949
import { settings } from './app/index'; // Reaching to "./app/index" is not allowed
5050
import userReducer from './reducer/user'; // Reaching to "./reducer/user" is not allowed
5151
import configureStore from './redux/configureStore'; // Reaching to "./redux/configureStore" is not allowed
52+
53+
export { settings } from './app/index'; // Reaching to "./app/index" is not allowed
54+
export * from './reducer/user'; // Reaching to "./reducer/user" is not allowed
5255
```
5356

5457
The following patterns are NOT considered problems:
@@ -61,4 +64,7 @@ The following patterns are NOT considered problems:
6164
import 'source-map-support/register';
6265
import { settings } from '../app';
6366
import getUser from '../actions/getUser';
67+
68+
export * from 'source-map-support/register';
69+
export { settings } from '../app';
6470
```

src/rules/no-internal-modules.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,12 @@ module.exports = {
9191
ImportDeclaration(node) {
9292
checkImportForReaching(node.source.value, node.source)
9393
},
94+
ExportAllDeclaration(node) {
95+
checkImportForReaching(node.source.value, node.source)
96+
},
97+
ExportNamedDeclaration(node) {
98+
checkImportForReaching(node.source.value, node.source)
99+
},
94100
CallExpression(node) {
95101
if (isStaticRequire(node)) {
96102
const [ firstArgument ] = node.arguments

tests/files/internal-modules/typescript/plugin2/app/index.ts

Whitespace-only changes.

tests/files/internal-modules/typescript/plugin2/index.ts

Whitespace-only changes.

tests/files/internal-modules/typescript/plugin2/internal.ts

Whitespace-only changes.

tests/files/internal-modules/typescript/plugins.ts

Whitespace-only changes.

tests/src/rules/no-internal-modules.js

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const ruleTester = new RuleTester()
77

88
ruleTester.run('no-internal-modules', rule, {
99
valid: [
10+
// imports
1011
test({
1112
code: 'import a from "./plugin2"',
1213
filename: testFilePath('./internal-modules/plugins/plugin.js'),
@@ -57,9 +58,44 @@ ruleTester.run('no-internal-modules', rule, {
5758
allow: [ '**/index{.js,}' ],
5859
} ],
5960
}),
61+
// exports
62+
test({
63+
code: 'export {a} from "./internal.js"',
64+
filename: testFilePath('./internal-modules/plugins/plugin2/index.js'),
65+
}),
66+
test({
67+
code: 'export * from "lodash.get"',
68+
filename: testFilePath('./internal-modules/plugins/plugin2/index.js'),
69+
}),
70+
test({
71+
code: 'export {b} from "@org/package"',
72+
filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),
73+
}),
74+
test({
75+
code: 'export {b} from "../../api/service"',
76+
filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),
77+
options: [ {
78+
allow: [ '**/api/*' ],
79+
} ],
80+
}),
81+
test({
82+
code: 'export * from "jquery/dist/jquery"',
83+
filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),
84+
options: [ {
85+
allow: [ 'jquery/dist/*' ],
86+
} ],
87+
}),
88+
test({
89+
code: 'export * from "./app/index.js";\nexport * from "./app/index"',
90+
filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),
91+
options: [ {
92+
allow: [ '**/index{.js,}' ],
93+
} ],
94+
}),
6095
],
6196

6297
invalid: [
98+
// imports
6399
test({
64100
code: 'import "./plugin2/index.js";\nimport "./plugin2/app/index"',
65101
filename: testFilePath('./internal-modules/plugins/plugin.js'),
@@ -126,5 +162,72 @@ ruleTester.run('no-internal-modules', rule, {
126162
},
127163
],
128164
}),
165+
// exports
166+
test({
167+
code: 'export * from "./plugin2/index.js";\nexport * from "./plugin2/app/index"',
168+
filename: testFilePath('./internal-modules/plugins/plugin.js'),
169+
options: [ {
170+
allow: [ '*/index.js' ],
171+
} ],
172+
errors: [ {
173+
message: 'Reaching to "./plugin2/app/index" is not allowed.',
174+
line: 2,
175+
column: 15,
176+
} ],
177+
}),
178+
test({
179+
code: 'export * from "./app/index.js"',
180+
filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),
181+
errors: [ {
182+
message: 'Reaching to "./app/index.js" is not allowed.',
183+
line: 1,
184+
column: 15,
185+
} ],
186+
}),
187+
test({
188+
code: 'export {b} from "./plugin2/internal"',
189+
filename: testFilePath('./internal-modules/plugins/plugin.js'),
190+
errors: [ {
191+
message: 'Reaching to "./plugin2/internal" is not allowed.',
192+
line: 1,
193+
column: 17,
194+
} ],
195+
}),
196+
test({
197+
code: 'export {a} from "../api/service/index"',
198+
filename: testFilePath('./internal-modules/plugins/plugin.js'),
199+
options: [ {
200+
allow: [ '**/internal-modules/*' ],
201+
} ],
202+
errors: [
203+
{
204+
message: 'Reaching to "../api/service/index" is not allowed.',
205+
line: 1,
206+
column: 17,
207+
},
208+
],
209+
}),
210+
test({
211+
code: 'export {b} from "@org/package/internal"',
212+
filename: testFilePath('./internal-modules/plugins/plugin2/internal.js'),
213+
errors: [
214+
{
215+
message: 'Reaching to "@org/package/internal" is not allowed.',
216+
line: 1,
217+
column: 17,
218+
},
219+
],
220+
}),
221+
test({
222+
code: 'export {get} from "debug/node"',
223+
filename: testFilePath('./internal-modules/plugins/plugin.js'),
224+
errors: [
225+
{
226+
message: 'Reaching to "debug/node" is not allowed.',
227+
line: 1,
228+
column: 19,
229+
},
230+
],
231+
}),
129232
],
130233
})

0 commit comments

Comments
 (0)