-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModules.js
More file actions
120 lines (77 loc) · 2.51 KB
/
Modules.js
File metadata and controls
120 lines (77 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//: 10.1 => /* Always use modules (import/export) over a non-standard module system. You can always transpile to your preferred module system. */
// bad
const JsStyle = require("./Arrays");
module.exports = JsStyle.es6;
// ok
import JsStyle from "./Arrays";
export default JsStyle.es6;
// best
import { es5 } from "./Arrays";
export default es5;
//: 10.2 => Do Not use wildcard imports.
/* Why? This makes sure you have a single default export.*/
// bad
import * as JsStyle from './Arrays';
// good
import JsStyle from './Arrays';
//: 10.3 => And do not export directly from an import.
/* Why? Having multiple lines that import from the same path can make code harder to maintain */
// bad
export { es6 as default } from './Arrays';
// good
import { es6 } from './Arrays';
export default es6;
//: 10.4 => Only import from a path in one place. eslint: no-duplicate-imports
// bad
import foo from 'foo';
// some other imports
import { es5, es6 } from 'foo';
// good
import foo, { name1, named2 } from './Arrays';
//: 10.5 => Do not export mutable bindings. eslint: import/no-mutable-exports
/* Why? Mutation should be avoided in general, but in particular when exporting mutable bindings. While this technique may be needed for some special class, in general, only constant references should be exported. */
// bad
let foo = 3;
export { foo };
// good
const foo2 = 3;
export {foo2}
//: 10.6 => In modules with a single export, prefer defualt export over named export;
export default function foo() { }
//: 10.7 => Put all import s above non-import statement
/* Why? Since import are hoisted, keeping them all at the top prevents surprising behavior. */
// bad
import foo from 'foo';
foo.init();
import bar from 'bar';
// good
import foo from 'foo';
import bar from 'bar';
foo.init();
//: 10.8 => Multiline imports should be indented just like multiline array and object literal.
// bad
import {longNameA, longNameB, longNameC, longNameD, longNameE} from 'path';
// good
import {
longNameA,
longNameB,
longNameC,
longNameD,
longNameE,
} from 'path';
//: 10.9 => Disallow WebPack loader syntax in module import statement
// bad
import fooSass from 'css!sass!foo.scss';
import barCss from 'style!css!bar.css';
// good
import fooSass from 'foo.scss';
import barCss from 'bar.css';
//: 10.10 => Do not include JavaScript filename extensions
// bad
import foo from './foo.js';
import bar from './bar.jsx';
import baz from './baz/index.jsx';
// good
import foo from './foo';
import bar from './bar';
import baz from './baz';