-
Notifications
You must be signed in to change notification settings - Fork 1
/
conventions.js
330 lines (298 loc) · 9.28 KB
/
conventions.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
"use strict";
/**
* Rules that enforce consistent coding conventions
*/
module.exports = {
rules: {
/**
* Requires using either `T[]` or `Array' for arrays.
*
* @see https://palantir.github.io/tslint/rules/array-type/
*/
"array-type": {
severity: "default",
options: [
"array-simple"
]
},
/**
* Requires parentheses around the parameters of arrow function definitions.
*
* @see https://palantir.github.io/tslint/rules/arrow-parens/
*/
"arrow-parens": true,
/**
* Suggests to convert `() => { return x; }` to `() => x`.
*
* @see https://palantir.github.io/tslint/rules/arrow-return-shorthand/
*/
"arrow-return-shorthand": true,
/**
* Bans specific types from being used. Does not ban the
* corresponding runtime objects from being used.
*
* @see https://palantir.github.io/tslint/rules/ban-types/
*/
"ban-types": {
severity: "default",
options: [
["Object", "Use `object` instead."],
["Boolean", "Use `boolean` instead."],
["Number", "Use `number` instead."],
["String", "Use `string` instead."],
["Symbol", "Use `symbol` instead."],
["Function", "Use a specific function type, like `() => void`."],
]
},
/**
* In a binary expression, a literal should always be on the right-hand side if possible.
* For example, prefer `x + 1` over `1 + x`.
*
* @see https://palantir.github.io/tslint/rules/binary-expression-operand-order/
*/
"binary-expression-operand-order": true,
/**
* An interface or literal type with just a call signature can be written as a function type.
*
* @see https://palantir.github.io/tslint/rules/callable-types/
*/
"callable-types": true,
/**
* Enforces braces for `if`/`for`/`do`/`while` statements.
*
* @see https://palantir.github.io/tslint/rules/curly/
*/
curly: {
severity: "default",
options: ["ignore-same-line"],
},
/**
* Enforces using explicit += 1 or -= 1 operators.
*
* @see https://palantir.github.io/tslint/rules/increment-decrement/
*
* This rule is disabled because the increment and decrement operators are nice syntax sugar.
*/
"increment-decrement": false,
/**
* Requires lines to be under a certain max length.
*
* @see https://palantir.github.io/tslint/rules/max-line-length/
*/
"max-line-length": {
severity: "default",
options: [{
limit: 120,
// Don't enforce line limit for import/export statements, class inheritance lines, or inline comments
"ignore-pattern": "(^import |^export |class \w+ (extends|implements) |// |@see |https?:\/\/)"
}],
},
/**
* Requires explicit visibility declarations for class members.
*
* @see https://palantir.github.io/tslint/rules/member-access/
*/
"member-access": {
severity: "default",
options: [
"check-accessor",
"check-constructor",
"check-parameter-property"
]
},
/**
* Enforces member ordering.
*
* @see https://palantir.github.io/tslint/rules/member-ordering/
*/
"member-ordering": {
severity: "default",
options: [{
alphabetize: false,
order: [
"static-field",
"instance-field",
"constructor",
"static-method",
"instance-method",
],
}],
},
/**
* Disallows explicit type declarations for variables or parameters initialized to a number, string, or boolean.
*
* @see https://palantir.github.io/tslint/rules/no-inferrable-types/
*/
"no-inferrable-types": {
severity: "default",
options: [
"ignore-params",
"ignore-properties"
],
},
/**
* Disallows use of the `null` keyword literal.
*
* @see https://palantir.github.io/tslint/rules/no-null-keyword/
*/
"no-null-keyword": true,
/**
* Flags throwing plain strings or concatenations of strings.
*
* @see https://palantir.github.io/tslint/rules/no-string-throw/
*/
"no-string-throw": true,
/**
* Checks that decimal literals should begin with `0.` instead of just `.`, and should not end with a trailing `0`.
*
* @see https://palantir.github.io/tslint/rules/number-literal-format/
*/
"number-literal-format": true,
/**
* Enforces consistent object literal property quote style.
*
* @see https://palantir.github.io/tslint/rules/object-literal-key-quotes/
*/
"object-literal-key-quotes": {
severity: "default",
options: [
"as-needed"
]
},
/**
* Enforces/disallows use of ES6 object literal shorthand.
*
* @see https://palantir.github.io/tslint/rules/object-literal-shorthand/
*/
"object-literal-shorthand": true,
/**
* Checks ordering of keys in object literals.
*
* When using the default alphabetical ordering, additional blank lines may be used to group
* object properties together while keeping the elements within each group in alphabetical order.
*
* @see https://palantir.github.io/tslint/rules/object-literal-sort-keys/
*
* This rule is disabled because it's often more clear to group related keys rather than
* sorting them alphabetically or as-defined.
*/
"object-literal-sort-keys": false,
/**
* Disallows multiple variable definitions in the same declaration statement.
*
* @see https://palantir.github.io/tslint/rules/one-variable-per-declaration/
*
* This rule is disabled because it's often convenient (and more concise) to combine
* varible declarations.
*/
"one-variable-per-declaration": false,
/**
* Requires that import statements be alphabetized and grouped.
*
* @see https://palantir.github.io/tslint/rules/ordered-imports/
*/
"ordered-imports": {
severity: "default",
options: [
{
"import-sources-order": "case-insensitive",
"grouped-imports": false,
"named-imports-order": "case-insensitive",
"module-source-path": "full"
}
]
},
/**
* Recommends to use a conditional expression instead of assigning to the same thing in each branch of an if statement.
*
* @see https://palantir.github.io/tslint/rules/prefer-conditional-expression/
*
* This rule is disabled because an `if...else` statement is often clearer than a conditional expression.
*/
"prefer-conditional-expression": false,
/**
* Requires that variable declarations use `const` instead of `let` and `var` if possible.
*
* @see https://palantir.github.io/tslint/rules/prefer-const/
*
* This rule is disabled because `const` should be reserved for things that represent constant
* values, not just any variable that happens to not be reassigned.
*/
"prefer-const": false,
/**
* Warns for class methods that do not use `this`.
*
* @see https://palantir.github.io/tslint/rules/prefer-function-over-method/
*/
"prefer-function-over-method": {
severity: "default",
options: [
"allow-public",
"allow-protected"
],
},
/**
* Enforces quote character for string literals.
*
* @see https://palantir.github.io/tslint/rules/quotemark/
*/
quotemark: {
severity: "default",
options: [
"double",
"avoid-escape",
"jsx-double"
]
},
/**
* Prefer `return;` in void functions and `return undefined;` in value-returning functions.
*
* @see https://palantir.github.io/tslint/rules/return-undefined/
*/
"return-undefined": true,
/**
* Enforces consistent semicolon usage at the end of every statement.
*
* @see https://palantir.github.io/tslint/rules/semicolon/
*/
semicolon: {
severity: "default",
options: ["always"]
},
/**
* Requires or disallows trailing commas in array and object literals, destructuring assignments, function typings,
* named imports and exports and function parameters.
*
* @see https://palantir.github.io/tslint/rules/trailing-comma/
*/
"trailing-comma": {
severity: "default",
options: [{
esSpecCompliant: true,
multiline: "ignore",
singleline: "never"
}],
},
/**
* Checks that type literal members are separated by semicolons.
* Enforces a trailing semicolon for multiline type literals.
*
* @see https://palantir.github.io/tslint/rules/type-literal-delimiter/
*/
"type-literal-delimiter": true,
/**
* Disallows `else` blocks for `if` blocks that end with `break`, `continue`, `return`, or `throw`.
*
* @see https://palantir.github.io/tslint/rules/unnecessary-else/
*
* This rule is disabled because `if...else` can make code more readable and the intent more obvious.
*/
"unnecessary-else": false,
/**
* Warns if an explicitly specified type argument is the default for that type parameter.
*
* @see https://palantir.github.io/tslint/rules/use-default-type-parameter/
*/
"use-default-type-parameter": true,
}
};