Tim van der Lippe | fdbd42e | 2020-04-07 14:14:36 | [diff] [blame] | 1 | # import/no-internal-modules |
| 2 | |
| 3 | Use this rule to prevent importing the submodules of other modules. |
| 4 | |
| 5 | ## Rule Details |
| 6 | |
| 7 | This rule has one option, `allow` which is an array of [minimatch/glob patterns](https://github.com/isaacs/node-glob#glob-primer) patterns that whitelist paths and import statements that can be imported with reaching. |
| 8 | |
| 9 | ### Examples |
| 10 | |
| 11 | Given the following folder structure: |
| 12 | |
| 13 | ``` |
| 14 | my-project |
| 15 | ├── actions |
| 16 | │ └── getUser.js |
| 17 | │ └── updateUser.js |
| 18 | ├── reducer |
| 19 | │ └── index.js |
| 20 | │ └── user.js |
| 21 | ├── redux |
| 22 | │ └── index.js |
| 23 | │ └── configureStore.js |
| 24 | └── app |
| 25 | │ └── index.js |
| 26 | │ └── settings.js |
| 27 | └── entry.js |
| 28 | ``` |
| 29 | |
| 30 | And the .eslintrc file: |
| 31 | ``` |
| 32 | { |
| 33 | ... |
| 34 | "rules": { |
| 35 | "import/no-internal-modules": [ "error", { |
| 36 | "allow": [ "**/actions/*", "source-map-support/*" ] |
| 37 | } ] |
| 38 | } |
| 39 | } |
| 40 | ``` |
| 41 | |
| 42 | The following patterns are considered problems: |
| 43 | |
| 44 | ```js |
| 45 | /** |
| 46 | * in my-project/entry.js |
| 47 | */ |
| 48 | |
| 49 | import { settings } from './app/index'; // Reaching to "./app/index" is not allowed |
| 50 | import userReducer from './reducer/user'; // Reaching to "./reducer/user" is not allowed |
| 51 | import configureStore from './redux/configureStore'; // Reaching to "./redux/configureStore" is not allowed |
| 52 | ``` |
| 53 | |
| 54 | The following patterns are NOT considered problems: |
| 55 | |
| 56 | ```js |
| 57 | /** |
| 58 | * in my-project/entry.js |
| 59 | */ |
| 60 | |
| 61 | import 'source-map-support/register'; |
| 62 | import { settings } from '../app'; |
| 63 | import getUser from '../actions/getUser'; |
| 64 | ``` |