source: frontend/node_modules/eslint-plugin-import/docs/rules/group-exports.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: 2.4 KB
Line 
1# import/group-exports
2
3<!-- end auto-generated rule header -->
4
5Reports when named exports are not grouped together in a single `export` declaration or when multiple assignments to CommonJS `module.exports` or `exports` object are present in a single file.
6
7**Rationale:** An `export` declaration or `module.exports` assignment can appear anywhere in the code. By requiring a single export declaration all your exports will remain at one place, making it easier to see what exports a module provides.
8
9## Rule Details
10
11This rule warns whenever a single file contains multiple named export declarations or multiple assignments to `module.exports` (or `exports`).
12
13### Valid
14
15```js
16// A single named export declaration -> ok
17export const valid = true
18```
19
20```js
21const first = true
22const second = true
23
24// A single named export declaration -> ok
25export {
26 first,
27 second,
28}
29```
30
31```js
32// Aggregating exports -> ok
33export { default as module1 } from 'module-1'
34export { default as module2 } from 'module-2'
35```
36
37```js
38// A single exports assignment -> ok
39module.exports = {
40 first: true,
41 second: true
42}
43```
44
45```js
46const first = true
47const second = true
48
49// A single exports assignment -> ok
50module.exports = {
51 first,
52 second,
53}
54```
55
56```js
57function test() {}
58test.property = true
59test.another = true
60
61// A single exports assignment -> ok
62module.exports = test
63```
64
65```ts
66const first = true;
67type firstType = boolean
68
69// A single named export declaration (type exports handled separately) -> ok
70export {first}
71export type {firstType}
72```
73
74### Invalid
75
76```js
77// Multiple named export statements -> not ok!
78export const first = true
79export const second = true
80```
81
82```js
83// Aggregating exports from the same module -> not ok!
84export { module1 } from 'module-1'
85export { module2 } from 'module-1'
86```
87
88```js
89// Multiple exports assignments -> not ok!
90exports.first = true
91exports.second = true
92```
93
94```js
95// Multiple exports assignments -> not ok!
96module.exports = {}
97module.exports.first = true
98```
99
100```js
101// Multiple exports assignments -> not ok!
102module.exports = () => {}
103module.exports.first = true
104module.exports.second = true
105```
106
107```ts
108type firstType = boolean
109type secondType = any
110
111// Multiple named type export statements -> not ok!
112export type {firstType}
113export type {secondType}
114```
115
116## When Not To Use It
117
118If you do not mind having your exports spread across the file, you can safely turn this rule off.
Note: See TracBrowser for help on using the repository browser.