Skip to content

Commit 9bd07e7

Browse files
committed
Add more detailed documentation on importList and exportList.
1 parent d3082bd commit 9bd07e7

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

src/rules/no-unused-modules.js

+46
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,54 @@ const CLASS_DECLARATION = 'ClassDeclaration'
6666
const DEFAULT = 'default'
6767
const TYPE_ALIAS = 'TypeAlias'
6868

69+
/**
70+
* List of imports per file.
71+
*
72+
* Represented by a two-level Map to a Set of identifiers. The upper-level Map
73+
* keys are the paths to the modules containing the imports, while the
74+
* lower-level Map keys are the paths to the files which are being imported
75+
* from. Lastly, the Set of identifiers contains either names being imported
76+
* or a special AST node name listed above (e.g ImportDefaultSpecifier).
77+
*
78+
* For example, if we have a file named foo.js containing:
79+
*
80+
* import { o2 } from './bar.js';
81+
*
82+
* Then we will have a structure that looks like:
83+
*
84+
* Map { 'foo.js' => Map { 'bar.js' => Set { 'o2' } } }
85+
*
86+
* @type {Map<string, Map<string, Set<string>>>}
87+
*/
6988
const importList = new Map()
89+
90+
/**
91+
* List of exports per file.
92+
*
93+
* Represented by a two-level Map to an object of metadata. The upper-level Map
94+
* keys are the paths to the modules containing the exports, while the
95+
* lower-level Map keys are the specific identifiers or special AST node names
96+
* being exported. The leaf-level metadata object at the moment only contains a
97+
* `whereUsed` propoerty, which contains a Set of paths to modules that import
98+
* the name.
99+
*
100+
* For example, if we have a file named bar.js containing the following exports:
101+
*
102+
* const o2 = 'bar';
103+
* export { o2 };
104+
*
105+
* And a file named foo.js containing the following import:
106+
*
107+
* import { o2 } from './bar.js';
108+
*
109+
* Then we will have a structure that looks like:
110+
*
111+
* Map { 'bar.js' => Map { 'o2' => { whereUsed: Set { 'foo.js' } } } }
112+
*
113+
* @type {Map<string, Map<string, object>>}
114+
*/
70115
const exportList = new Map()
116+
71117
const ignoredFiles = new Set()
72118
const filesOutsideSrc = new Set()
73119

0 commit comments

Comments
 (0)