| [9af201e] | 1 | # import/no-internal-modules
|
|---|
| 2 |
|
|---|
| 3 | <!-- end auto-generated rule header -->
|
|---|
| 4 |
|
|---|
| 5 | Use this rule to prevent importing the submodules of other modules.
|
|---|
| 6 |
|
|---|
| 7 | ## Rule Details
|
|---|
| 8 |
|
|---|
| 9 | This rule has two mutally exclusive options that are arrays of [minimatch/glob patterns](https://github.com/isaacs/node-glob#glob-primer) patterns:
|
|---|
| 10 |
|
|---|
| 11 | - `allow` that include paths and import statements that can be imported with reaching.
|
|---|
| 12 | - `forbid` that exclude paths and import statements that can be imported with reaching.
|
|---|
| 13 |
|
|---|
| 14 | ### Examples
|
|---|
| 15 |
|
|---|
| 16 | Given the following folder structure:
|
|---|
| 17 |
|
|---|
| 18 | ```pt
|
|---|
| 19 | my-project
|
|---|
| 20 | ├── actions
|
|---|
| 21 | │ └── getUser.js
|
|---|
| 22 | │ └── updateUser.js
|
|---|
| 23 | ├── reducer
|
|---|
| 24 | │ └── index.js
|
|---|
| 25 | │ └── user.js
|
|---|
| 26 | ├── redux
|
|---|
| 27 | │ └── index.js
|
|---|
| 28 | │ └── configureStore.js
|
|---|
| 29 | └── app
|
|---|
| 30 | │ └── index.js
|
|---|
| 31 | │ └── settings.js
|
|---|
| 32 | └── entry.js
|
|---|
| 33 | ```
|
|---|
| 34 |
|
|---|
| 35 | And the .eslintrc file:
|
|---|
| 36 |
|
|---|
| 37 | ```json
|
|---|
| 38 | {
|
|---|
| 39 | ...
|
|---|
| 40 | "rules": {
|
|---|
| 41 | "import/no-internal-modules": [ "error", {
|
|---|
| 42 | "allow": [ "**/actions/*", "source-map-support/*" ],
|
|---|
| 43 | } ]
|
|---|
| 44 | }
|
|---|
| 45 | }
|
|---|
| 46 | ```
|
|---|
| 47 |
|
|---|
| 48 | The following patterns are considered problems:
|
|---|
| 49 |
|
|---|
| 50 | ```js
|
|---|
| 51 | /**
|
|---|
| 52 | * in my-project/entry.js
|
|---|
| 53 | */
|
|---|
| 54 |
|
|---|
| 55 | import { settings } from './app/index'; // Reaching to "./app/index" is not allowed
|
|---|
| 56 | import userReducer from './reducer/user'; // Reaching to "./reducer/user" is not allowed
|
|---|
| 57 | import configureStore from './redux/configureStore'; // Reaching to "./redux/configureStore" is not allowed
|
|---|
| 58 |
|
|---|
| 59 | export { settings } from './app/index'; // Reaching to "./app/index" is not allowed
|
|---|
| 60 | export * from './reducer/user'; // Reaching to "./reducer/user" is not allowed
|
|---|
| 61 | ```
|
|---|
| 62 |
|
|---|
| 63 | The following patterns are NOT considered problems:
|
|---|
| 64 |
|
|---|
| 65 | ```js
|
|---|
| 66 | /**
|
|---|
| 67 | * in my-project/entry.js
|
|---|
| 68 | */
|
|---|
| 69 |
|
|---|
| 70 | import 'source-map-support/register';
|
|---|
| 71 | import { settings } from '../app';
|
|---|
| 72 | import getUser from '../actions/getUser';
|
|---|
| 73 |
|
|---|
| 74 | export * from 'source-map-support/register';
|
|---|
| 75 | export { settings } from '../app';
|
|---|
| 76 | ```
|
|---|
| 77 |
|
|---|
| 78 | Given the following folder structure:
|
|---|
| 79 |
|
|---|
| 80 | ```pt
|
|---|
| 81 | my-project
|
|---|
| 82 | ├── actions
|
|---|
| 83 | │ └── getUser.js
|
|---|
| 84 | │ └── updateUser.js
|
|---|
| 85 | ├── reducer
|
|---|
| 86 | │ └── index.js
|
|---|
| 87 | │ └── user.js
|
|---|
| 88 | ├── redux
|
|---|
| 89 | │ └── index.js
|
|---|
| 90 | │ └── configureStore.js
|
|---|
| 91 | └── app
|
|---|
| 92 | │ └── index.js
|
|---|
| 93 | │ └── settings.js
|
|---|
| 94 | └── entry.js
|
|---|
| 95 | ```
|
|---|
| 96 |
|
|---|
| 97 | And the .eslintrc file:
|
|---|
| 98 |
|
|---|
| 99 | ```json
|
|---|
| 100 | {
|
|---|
| 101 | ...
|
|---|
| 102 | "rules": {
|
|---|
| 103 | "import/no-internal-modules": [ "error", {
|
|---|
| 104 | "forbid": [ "**/actions/*", "source-map-support/*" ],
|
|---|
| 105 | } ]
|
|---|
| 106 | }
|
|---|
| 107 | }
|
|---|
| 108 | ```
|
|---|
| 109 |
|
|---|
| 110 | The following patterns are considered problems:
|
|---|
| 111 |
|
|---|
| 112 | ```js
|
|---|
| 113 | /**
|
|---|
| 114 | * in my-project/entry.js
|
|---|
| 115 | */
|
|---|
| 116 |
|
|---|
| 117 | import 'source-map-support/register';
|
|---|
| 118 | import getUser from '../actions/getUser';
|
|---|
| 119 |
|
|---|
| 120 | export * from 'source-map-support/register';
|
|---|
| 121 | export getUser from '../actions/getUser';
|
|---|
| 122 | ```
|
|---|
| 123 |
|
|---|
| 124 | The following patterns are NOT considered problems:
|
|---|
| 125 |
|
|---|
| 126 | ```js
|
|---|
| 127 | /**
|
|---|
| 128 | * in my-project/entry.js
|
|---|
| 129 | */
|
|---|
| 130 |
|
|---|
| 131 | import 'source-map-support';
|
|---|
| 132 | import { getUser } from '../actions';
|
|---|
| 133 |
|
|---|
| 134 | export * from 'source-map-support';
|
|---|
| 135 | export { getUser } from '../actions';
|
|---|
| 136 | ```
|
|---|