source: frontend/node_modules/eslint-plugin-import/docs/rules/max-dependencies.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.8 KB
Line 
1# import/max-dependencies
2
3<!-- end auto-generated rule header -->
4
5Forbid modules to have too many dependencies (`import` or `require` statements).
6
7This is a useful rule because a module with too many dependencies is a code smell, and usually indicates the module is doing too much and/or should be broken up into smaller modules.
8
9Importing multiple named exports from a single module will only count once (e.g. `import {x, y, z} from './foo'` will only count as a single dependency).
10
11## Options
12
13This rule has the following options, with these defaults:
14
15```js
16"import/max-dependencies": ["error", {
17 "max": 10,
18 "ignoreTypeImports": false,
19}]
20```
21
22### `max`
23
24This option sets the maximum number of dependencies allowed. Anything over will trigger the rule. **Default is 10** if the rule is enabled and no `max` is specified.
25
26Given a max value of `{"max": 2}`:
27
28### Fail
29
30```js
31import a from './a'; // 1
32const b = require('./b'); // 2
33import c from './c'; // 3 - exceeds max!
34```
35
36### Pass
37
38```js
39import a from './a'; // 1
40const anotherA = require('./a'); // still 1
41import {x, y, z} from './foo'; // 2
42```
43
44### `ignoreTypeImports`
45
46Ignores `type` imports. Type imports are a feature released in TypeScript 3.8, you can [read more here](https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-8.html#type-only-imports-and-export). Defaults to `false`.
47
48Given `{"max": 2, "ignoreTypeImports": true}`:
49
50<!-- markdownlint-disable-next-line MD024 -- duplicate header -->
51### Fail
52
53```ts
54import a from './a';
55import b from './b';
56import c from './c';
57```
58
59<!-- markdownlint-disable-next-line MD024 -- duplicate header -->
60### Pass
61
62```ts
63import a from './a';
64import b from './b';
65import type c from './c'; // Doesn't count against max
66```
67
68## When Not To Use It
69
70If you don't care how many dependencies a module has.
Note: See TracBrowser for help on using the repository browser.