source: frontend/node_modules/eslint-plugin-import/docs/rules/no-unused-modules.md

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

Fix frontend appearance

  • Property mode set to 100644
File size: 3.3 KB
Line 
1# import/no-unused-modules
2
3<!-- end auto-generated rule header -->
4
5Reports:
6
7 - modules without any exports
8 - individual exports not being statically `import`ed or `require`ed from other modules in the same project
9 - dynamic imports are supported if argument is a literal string
10
11## Rule Details
12
13### Usage
14
15In order for this plugin to work, at least one of the options `missingExports` or `unusedExports` must be enabled (see "Options" section below). In the future, these options will be enabled by default (see <https://github.com/import-js/eslint-plugin-import/issues/1324>)
16
17Example:
18
19```json
20"rules": {
21 ...otherRules,
22 "import/no-unused-modules": [1, {"unusedExports": true}]
23}
24```
25
26### Options
27
28This rule takes the following option:
29
30 - **`missingExports`**: if `true`, files without any exports are reported (defaults to `false`)
31 - **`unusedExports`**: if `true`, exports without any static usage within other modules are reported (defaults to `false`)
32 - **`ignoreUnusedTypeExports`**: if `true`, TypeScript type exports without any static usage within other modules are reported (defaults to `false` and has no effect unless `unusedExports` is `true`)
33 - **`src`**: an array with files/paths to be analyzed. It only applies to unused exports. Defaults to `process.cwd()`, if not provided
34 - **`ignoreExports`**: an array with files/paths for which unused exports will not be reported (e.g module entry points in a published package)
35
36### Example for missing exports
37
38#### The following will be reported
39
40```js
41const class MyClass { /*...*/ }
42
43function makeClass() { return new MyClass(...arguments) }
44```
45
46#### The following will not be reported
47
48```js
49export default function () { /*...*/ }
50```
51
52```js
53export const foo = function () { /*...*/ }
54```
55
56```js
57export { foo, bar }
58```
59
60```js
61export { foo as bar }
62```
63
64### Example for unused exports
65
66given file-f:
67
68```js
69import { e } from 'file-a'
70import { f } from 'file-b'
71import * as fileC from 'file-c'
72export { default, i0 } from 'file-d' // both will be reported
73
74export const j = 99 // will be reported
75```
76
77and file-d:
78
79```js
80export const i0 = 9 // will not be reported
81export const i1 = 9 // will be reported
82export default () => {} // will not be reported
83```
84
85and file-c:
86
87```js
88export const h = 8 // will not be reported
89export default () => {} // will be reported, as export * only considers named exports and ignores default exports
90```
91
92and file-b:
93
94```js
95import two, { b, c, doAnything } from 'file-a'
96
97export const f = 6 // will not be reported
98```
99
100and file-a:
101
102```js
103const b = 2
104const c = 3
105const d = 4
106
107export const a = 1 // will be reported
108
109export { b, c } // will not be reported
110
111export { d as e } // will not be reported
112
113export function doAnything() {
114 // some code
115} // will not be reported
116
117export default 5 // will not be reported
118```
119
120### Unused exports with `ignoreUnusedTypeExports` set to `true`
121
122The following will not be reported:
123
124```ts
125export type Foo = {}; // will not be reported
126export interface Foo = {}; // will not be reported
127export enum Foo {}; // will not be reported
128```
129
130#### Important Note
131
132Exports from files listed as a main file (`main`, `browser`, or `bin` fields in `package.json`) will be ignored by default. This only applies if the `package.json` is not set to `private: true`
133
134## When not to use
135
136If you don't mind having unused files or dead code within your codebase, you can disable this rule
Note: See TracBrowser for help on using the repository browser.