-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathbest-practices.js
239 lines (170 loc) · 6.23 KB
/
best-practices.js
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
/**
* These rules relate to better ways of doing things to help you avoid problems
*/
module.exports = {
rules: {
// enfores getter/setter pairs in objects
'accessor-pairs': 'off',
// enforces return statements in callbacks of array’s methods
'array-callback-return': 'error',
// treat var as block scoped
'block-scoped-var': 'error',
// enforce that class methods utilize this
'class-methods-use-this': 'error',
// limit cyclomatic complexity
'complexity': 'off',
// require return statements to either always or never specify values
'consistent-return': 'off',
// require following curly brace conventions
'curly': ['error', 'multi-line'],
// require default case in switch statements
'default-case': 'off',
// enforce newline before and after dot
'dot-location': ['error', 'property'],
// require dot notation
// encourages use of dot notation whenever possible
'dot-notation': ['error', { allowKeywords: true }],
// require the use of === and !==
'eqeqeq': ['error', 'always', { null: 'ignore' }],
// require guarding for-in
'guard-for-in': 'off',
// disallow the use of alert, confirm, and prompt
'no-alert': 'off',
// disallow use of arguments.caller or arguments.callee
'no-caller': 'error',
// disallow lexical declarations in case/default clauses
'no-case-declarations': 'error',
// disallow division operators explicitly at beginning of regular expression
'no-div-regex': 'off',
// disallow return before else
'no-else-return': 'error',
// disallow empty functions, except for standalone funcs/arrows
'no-empty-function': ['error', {
allow: [
'arrowFunctions',
'functions',
'methods',
]
}],
// disallow empty destructuring patterns
'no-empty-pattern': 'error',
// disallow null comparisons
'no-eq-null': 'off',
// disallow use of eval()
'no-eval': 'error',
// disallow extending of native objects
'no-extend-native': 'error',
// disallow unnecessary function binding
'no-extra-bind': 'error',
// disallow unnecessary labels
'no-extra-label': 'error',
// disallow fallthrough of case statements
'no-fallthrough': 'error',
// disallow floating decimals
'no-floating-decimal': 'error',
// disallow assignment to native objects or read-only global variables
'no-global-assign': 'error',
// disallow the type conversion with shorter notations
'no-implicit-coercion': 'off',
// disallow variable and function declarations in the global scope
'no-implicit-globals': 'off',
// disallow use of eval()-like methods
'no-implied-eval': 'error',
// disallow this keywords outside of classes or class-like objects
'no-invalid-this': 'off',
// disallow usage of __iterator__ property
'no-iterator': 'error',
// disallow labeled statements
'no-labels': ['error', { allowLoop: false, allowSwitch: false }],
// disallow unnecessary nested blocks
'no-lone-blocks': 'error',
// disallow functions in loops
'no-loop-func': 'error',
// disallow magic numbers
'no-magic-numbers': 'off',
// disallow multiple spaces
'no-multi-spaces': 'error',
// disallow multiline strings
'no-multi-str': 'error',
// disallow new for side effects
'no-new': 'error',
// disallow function constructor
'no-new-func': 'error',
// disallow primitive wrapper instances
'no-new-wrappers': 'error',
// disallow use of (old style) octal literals
'no-octal': 'error',
// disallow use of octal escape sequences in string literals, such as
// var foo = 'Copyright \251';
'no-octal-escape': 'error',
// disallow reassignment of function parameters
'no-param-reassign': 'off',
// disallow use of __proto__ property
'no-proto': 'error',
// disallow variable redeclaration
'no-redeclare': 'error',
// disallow certain object properties
'no-restricted-properties': ['error', {
object: 'arguments',
property: 'callee',
message: 'arguments.callee is deprecated',
}, {
property: '__defineGetter__',
message: 'Please use Object.defineProperty instead.',
}, {
property: '__defineSetter__',
message: 'Please use Object.defineProperty instead.',
}],
// disallow assignment in return statement
'no-return-assign': 'error',
// disallows unnecessary return await
'no-return-await': 'error',
// disallow script URLs
// such as: location.href = 'javascript:void(0)'
'no-script-url': 'error',
// disallow self assignment
'no-self-assign': 'error',
// disallow self compare
'no-self-compare': 'error',
// disallow use of comma operator
'no-sequences': 'error',
// restrict what can be thrown as an exception
'no-throw-literal': 'error',
// disallow unmodified conditions of loops
'no-unmodified-loop-condition': 'off',
// disallow unused expressions
'no-unused-expressions': ['error', {
allowShortCircuit: true,
allowTernary: true,
allowTaggedTemplates: true
}],
// disallow unused labels
'no-unused-labels': 'error',
// disallow unnecessary .call() and .apply()
'no-useless-call': 'error',
// disallow useless string concatenation
'no-useless-concat': 'error',
// disallow unnecessary string escaping
'no-useless-escape': 'error',
// disallow redundant return statements
'no-useless-return': 'error',
// disallow use of void operator
'no-void': 'error',
// disallow warning comments
'no-warning-comments': 'off',
// disallow with statements
'no-with': 'error',
// require using Error objects as Promise rejection reasons
'prefer-promise-reject-errors': ['off', { allowEmptyReject: true }],
// require radix parameter
'radix': 'off',
// disallow async functions which have no await expression
'require-await': 'off',
// require variable declarations to be at the top of their scope
'vars-on-top': 'off',
// require IIFEs to be wrapped
'wrap-iife': ['error', 'any', { functionPrototypeMethods: true }],
// require or disallow Yoda conditions
'yoda': ['error', 'never']
}
}