-
Notifications
You must be signed in to change notification settings - Fork 311
/
.eslintrc.js
365 lines (356 loc) · 14.2 KB
/
.eslintrc.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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
const { rules: airbnbSharedRules } = require('eslint-config-airbnb-typescript/lib/shared');
const { rules: airbnbVariableRules } = require('eslint-config-airbnb-base/rules/variables');
module.exports = {
"root": true,
"ignorePatterns": [
"debian/**/*",
"docker/**/*",
"ports/**/*",
"scripts/**/*.js",
"tests/**/*",
"node_modules/**/*",
],
"overrides": [
{
"files": ["*.ts"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"createDefaultProgram": true,
"tsconfigRootDir": __dirname,
"project": true,
},
"extends": [
'airbnb-base',
"airbnb-typescript/base",
"plugin:@angular-eslint/recommended",
"plugin:@typescript-eslint/strict-type-checked",
"plugin:@typescript-eslint/stylistic-type-checked",
"plugin:rxjs/recommended",
"plugin:sonarjs/recommended"
],
"plugins": [
"rxjs",
"rxjs-angular",
"unicorn",
"angular-file-naming",
"@shopify",
"unused-imports",
"sonarjs",
"import",
],
"rules": {
// Conflicts with ngx-translate-extract
"prefer-template": "off",
// Consciously altered
"no-underscore-dangle": "off",
"class-methods-use-this": "off",
"import/prefer-default-export": "off",
"no-continue": "off",
"prefer-destructuring": "off",
"operator-assignment": "off",
"no-return-assign": "off",
"no-empty": ["error", { "allowEmptyCatch": true }],
"arrow-body-style": "off",
"no-bitwise": "off",
"max-len": ["error", 120, 2, {
"ignoreUrls": true,
"ignoreComments": false,
"ignoreRegExpLiterals": true,
"ignoreStrings": true, // TODO: Consider enabling later.
"ignoreTemplateLiterals": true
}],
"radix": "off",
"no-console": ["error", { allow: ["warn", "error", "info"] }],
"import/order": ["error", {
"groups": ["builtin", "external", ["internal", "parent", "sibling", "index"]],
"pathGroups": [
{
"pattern": "app/**",
"group": "parent",
"position": "before",
}
],
"pathGroupsExcludedImportTypes": ["builtin", "internal"],
"newlines-between": "never",
"alphabetize": {
"order": "asc",
"caseInsensitive": false
}
}],
"import/no-duplicates": ["error", {"considerQueryString": true}],
"import/extensions": ["error", "ignorePackages", {
"js": "never",
"jsx": "never",
"ts": "never",
"tsx": "never"
}],
"@typescript-eslint/no-use-before-define": ["error", "nofunc"],
"no-prototype-builtins": "off",
"no-trailing-spaces": ["error"],
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-misused-promises": ["error", { checksVoidReturn: false }],
'@typescript-eslint/naming-convention': [
'error',
{
selector: ['typeLike'],
format: ['StrictPascalCase'],
filter: {
// Allow two letter combinations at the start, like VDev
regex: '^[A-Z][A-Z]',
match: false,
}
},
{
selector: ['typeLike'],
format: ['PascalCase'],
},
{
selector: ['enumMember'],
format: ['StrictPascalCase'],
},
{
selector: 'function',
format: ['strictCamelCase'],
},
{
selector: ['classMethod', 'objectLiteralMethod', 'typeMethod'],
format: ['strictCamelCase'],
},
{
selector: ['classProperty'],
format: ['strictCamelCase', 'StrictPascalCase', 'UPPER_CASE'],
leadingUnderscore: 'allow', // TODO: Remove later
},
{
selector: ['variable', 'parameter'],
modifiers: ['unused'],
format: ['strictCamelCase'],
leadingUnderscore: 'allow',
},
{
selector: ['variable', 'parameter'],
format: ['strictCamelCase']
},
],
"@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true, allowAny: true }],
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/no-floating-promises": "off",
"@typescript-eslint/dot-notation": ["error", { allowIndexSignaturePropertyAccess: true }],
"sonarjs/prefer-single-boolean-return": ["off"],
"no-plusplus": "off",
"@typescript-eslint/prefer-nullish-coalescing": ["off"],
"@typescript-eslint/no-extraneous-class": ["off"],
"@typescript-eslint/no-confusing-void-expression": ["error", {
ignoreArrowShorthand: true,
}],
// TODO: Airbnb rules that are disabled for now as they cannot be fixed automatically
"no-restricted-syntax": ["error",
// TODO: Partially implemented. ForOfStatement is allowed for now.
{
"selector": "ForInStatement",
"message": "for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array."
},
{
"selector": "LabeledStatement",
"message": "Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand."
},
{
"selector": "WithStatement",
"message": "`with` is disallowed in strict mode because it makes code impossible to predict and optimize."
},
{
selector: 'MemberExpression[property.name="get"][object.name="form"], MemberExpression[property.name="get"] > MemberExpression[property.name="form"]',
message: "For type safety reasons prefer `controls.name` over `get('name')`",
},
{
selector: 'Identifier[name="mdDialog"]:has(Identifier[name="MatDialog"])',
message: "For consistency reasons prefer `matDialog` over `mdDialog`",
},
{
selector: 'Identifier[name="dialog"]:has(Identifier[name="MatDialog"])',
message: "For consistency reasons prefer `dialog` for `DialogService`",
},
{
selector: 'MemberExpression[property.name="email"][object.name="Validators"]',
message: 'For email validation, it is prefer to use the `emailValidator` validator.',
},
],
"no-param-reassign": "off",
"@typescript-eslint/no-loop-func": "off",
"no-await-in-loop": "off",
"no-multi-str": "off",
"no-mixed-operators": ["error", {
groups: [
// TODO: Some operators from default config not implemented.
["&", "|", "^", "~", "<<", ">>", ">>>"],
["==", "!=", "===", "!==", ">", ">=", "<", "<="],
["&&", "||"],
["in", "instanceof"]
],
allowSamePrecedence: true
}],
"default-case": "off",
"@typescript-eslint/member-ordering": "off",
"@typescript-eslint/no-unsafe-return": "off",
// Other temporary disables
"rxjs/no-implicit-any-catch": ["off"],
"rxjs/no-nested-subscribe": ["off"],
"sonarjs/cognitive-complexity": ["error", 40],
"@typescript-eslint/no-base-to-string": ["off"],
"@typescript-eslint/class-literal-property-style": ["off"],
"@typescript-eslint/no-unnecessary-condition": ["off"],
"@typescript-eslint/no-invalid-void-type": ["off"],
"@typescript-eslint/no-dynamic-delete": ["off"],
"@typescript-eslint/prefer-reduce-type-parameter": ["off"],
// Other overwrites
"@typescript-eslint/lines-between-class-members": "off",
"@typescript-eslint/indent": ["error", 2, {
...airbnbSharedRules['@typescript-eslint/indent'][2],
ignoredNodes: [
...airbnbSharedRules['@typescript-eslint/indent'][2]['ignoredNodes'],
"PropertyDefinition[decorators]",
]
}],
"@typescript-eslint/restrict-plus-operands": ["error", { allowAny: true }],
"no-restricted-globals": [
"error",
...airbnbVariableRules['no-restricted-globals'].slice(1),
{
"name": "window",
"message": "Use the injected window service instead. Search for @Inject(WINDOW)."
}
],
"sonarjs/no-duplicate-string": ["off"],
// Extra rules
"@angular-eslint/use-lifecycle-interface": ["error"],
"@angular-eslint/sort-lifecycle-methods": ["error"],
"@angular-eslint/use-component-selector": ["error"],
"@typescript-eslint/array-type": "error",
"@typescript-eslint/explicit-member-accessibility": ["error", { accessibility: "no-public" }],
"@typescript-eslint/no-inferrable-types": "error",
"@typescript-eslint/ban-tslint-comment": "error",
"@typescript-eslint/member-delimiter-style": "error",
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/ban-ts-comment": "error",
"@typescript-eslint/explicit-function-return-type": ["error", { allowExpressions: true }],
"@typescript-eslint/consistent-type-assertions": ["error"],
"@typescript-eslint/no-unnecessary-boolean-literal-compare": ["error"],
"@typescript-eslint/prefer-includes": ["error"],
"@typescript-eslint/prefer-for-of": ["error"],
"@typescript-eslint/prefer-as-const": ["error"],
"@typescript-eslint/consistent-generic-constructors": ["error"],
"@angular-eslint/use-component-view-encapsulation": ["error"],
"@typescript-eslint/no-unused-vars": "off",
"unused-imports/no-unused-imports": "error",
"unused-imports/no-unused-vars": ["error", {
vars: "local",
args: "after-used",
argsIgnorePattern: "^_$",
ignoreRestSiblings: true,
}],
"id-denylist": ["error", "res"],
"@typescript-eslint/ban-types": ["error", {
extendDefaults: true,
types: {
UntypedFormBuilder: 'Prefer normal typed FormBuilder.',
SimpleChanges: 'Prefer typed IxSimpleChanges<this>.',
}
}],
"unicorn/filename-case": ["error", { case: "kebabCase"}],
"unicorn/prefer-array-find": ["error"],
"@angular-eslint/component-selector": ["error", {
"type": "element",
"prefix": "ix",
"style": "kebab-case"
}],
"@angular-eslint/component-max-inline-declarations": ["error"],
"@angular-eslint/contextual-decorator": ["error"],
"@angular-eslint/contextual-lifecycle": ["error"],
"no-restricted-imports": ["error", {
"paths": [{
"name": "@ngneat/spectator",
"importNames": ["createComponentFactory", "createHostFactory", "createRoutingFactory", "mockProvider"],
"message": "Use imports from @ngneat/spectator/jest instead."
}, {
"name": "@angular/material/icon",
"importNames": ["MatIconModule"],
"message": "Use IxIconModule instead."
}],
"patterns": [{
"group": [ "../**"],
"message": "Use alias 'app' to replace part '../' of the path."
}],
}],
"@shopify/typescript/prefer-singular-enums": "error",
"@shopify/prefer-early-return": ["error", { maximumStatements: 3 }],
"import/no-default-export": "error",
"@typescript-eslint/consistent-indexed-object-style": "error",
"@angular-eslint/prefer-on-push-component-change-detection": "error",
// RxJS rules
"rxjs/no-unsafe-takeuntil": ["error", {
"alias": ["untilDestroyed"]
}],
"rxjs-angular/prefer-takeuntil": ["error", {
"alias": ["untilDestroyed"],
"checkComplete": false,
"checkDecorators": ["Component"],
"checkDestroy": false
}],
"rxjs/finnish": ["error", {
"parameters": true,
"properties": false, // TODO: Should be true, hard to implement now.
"variables": true,
"functions": false,
"methods": false,
}],
"rxjs/prefer-observer": ["error"],
"id-length": ["error", {
exceptions: ['a', 'b', 'x', 'y', '_', 'i', 'n'],
properties: 'never',
}],
// File Naming
"angular-file-naming/component-filename-suffix": "error",
"angular-file-naming/directive-filename-suffix": "error",
"angular-file-naming/module-filename-suffix": "error",
"angular-file-naming/pipe-filename-suffix": "error",
"angular-file-naming/service-filename-suffix": ["error", {
"suffixes": ["service", "effects", "store", "guard", "pipe"]
}],
}
},
{
"files": ["**/*.spec.ts"],
"plugins": ["jest"],
"extends": ["plugin:jest/recommended", "plugin:jest/style"],
"rules": {
"jest/no-large-snapshots": ["error"],
"jest/prefer-equality-matcher": ["error"],
"jest/prefer-lowercase-title": ["error", { "ignore": ["describe"] }],
"@typescript-eslint/consistent-indexed-object-style": "error",
"jest/expect-expect": [
"error",
{
"assertFunctionNames": ["expect", "expectObservable"],
}
]
}
},
{
"files": ["*.html"],
"extends": ["plugin:@angular-eslint/template/recommended"],
"plugins": ["angular-test-ids"],
"rules": {
"@angular-eslint/template/attributes-order": ["error"],
"@angular-eslint/template/no-duplicate-attributes": ['error'],
"@angular-eslint/template/no-interpolation-in-attributes": ['error'],
"angular-test-ids/require-test-id": ["error", {
"attribute": "ixTest",
"addElements": ["a", "mat-row", "mat-slider", "table"]
}],
// TODO: To be enabled later
'@angular-eslint/template/use-track-by-function': ['off'],
'@angular-eslint/template/no-negated-async': ['off'],
}
}
]
}