source: frontend/node_modules/eslint-plugin-import/docs/rules/prefer-default-export.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: 3.2 KB
Line 
1# import/prefer-default-export
2
3<!-- end auto-generated rule header -->
4
5In exporting files, this rule checks if there is default export or not.
6
7## Rule Details
8
9### rule schema
10
11```javascript
12"import/prefer-default-export": [
13 ( "off" | "warn" | "error" ),
14 { "target": "single" | "any" } // default is "single"
15]
16```
17
18### Config Options
19
20There are two options available: `single` and `any`. By default, if you do not specify the option, rule will assume it is `single`.
21
22#### single
23
24**Definition**: When there is only a single export from a module, prefer using default export over named export.
25
26How to setup config file for this rule:
27
28```javascript
29// you can manually specify it
30"rules": {
31 "import/prefer-default-export": [
32 ( "off" | "warn" | "error" ),
33 { "target": "single" }
34 ]
35}
36
37// config setup below will also work
38"rules": {
39 "import/prefer-default-export": "off" | "warn" | "error"
40}
41```
42
43The following patterns are considered warnings:
44
45```javascript
46// bad.js
47
48// There is only a single module export and it's a named export.
49export const foo = 'foo';
50
51```
52
53The following patterns are not warnings:
54
55```javascript
56// good1.js
57
58// There is a default export.
59export const foo = 'foo';
60const bar = 'bar';
61export default bar;
62```
63
64```javascript
65// good2.js
66
67// There is more than one named export in the module.
68export const foo = 'foo';
69export const bar = 'bar';
70```
71
72```javascript
73// good3.js
74
75// There is more than one named export in the module
76const foo = 'foo';
77const bar = 'bar';
78export { foo, bar }
79```
80
81```javascript
82// good4.js
83
84// There is a default export.
85const foo = 'foo';
86export { foo as default }
87```
88
89```javascript
90// export-star.js
91
92// Any batch export will disable this rule. The remote module is not inspected.
93export * from './other-module'
94```
95
96#### any
97
98**Definition**: any exporting file must contain a default export.
99
100How to setup config file for this rule:
101
102```javascript
103// you have to manually specify it
104"rules": {
105 "import/prefer-default-export": [
106 ( "off" | "warn" | "error" ),
107 { "target": "any" }
108 ]
109}
110```
111
112The following patterns are *not* considered warnings:
113
114```javascript
115// good1.js
116
117//has default export
118export default function bar() {};
119```
120
121```javascript
122// good2.js
123
124// has default export
125let foo;
126export { foo as default }
127```
128
129```javascript
130// good3.js
131
132//contains multiple exports AND default export
133export const a = 5;
134export function bar(){};
135let foo;
136export { foo as default }
137```
138
139```javascript
140// good4.js
141
142// does not contain any exports => file is not checked by the rule
143import * as foo from './foo';
144```
145
146```javascript
147// export-star.js
148
149// Any batch export will disable this rule. The remote module is not inspected.
150export * from './other-module'
151```
152
153The following patterns are considered warnings:
154
155```javascript
156// bad1.js
157
158//has 2 named exports, but no default export
159export const foo = 'foo';
160export const bar = 'bar';
161```
162
163```javascript
164// bad2.js
165
166// does not have default export
167let foo, bar;
168export { foo, bar }
169```
170
171```javascript
172// bad3.js
173
174// does not have default export
175export { a, b } from "foo.js"
176```
177
178```javascript
179// bad4.js
180
181// does not have default export
182let item;
183export const foo = item;
184export { item };
185```
Note: See TracBrowser for help on using the repository browser.