-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.eslintrc.js
311 lines (284 loc) · 9.08 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
const fs = require('fs');
module.exports = {
root: true,
// Use the typescript-eslint parser
parser: '@typescript-eslint/parser',
// Enable eslint and typescript-eslint
plugins: [
'eslint-plugin',
'@typescript-eslint',
'mocha',
'prettier',
'import',
],
env: {
es6: true,
node: true,
mocha: true,
},
parserOptions: {
sourceType: 'module',
/*
* The `project` setting is required for `@typescript-eslint/await-thenable`
* but it causes significant performance overhead (1m13s vs 13s)
* See https://github.com/typescript-eslint/typescript-eslint/issues/389
*/
project: getProjectFile(),
// See https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/parser#configuration
createDefaultProgram: true,
ecmaFeatures: {
ecmaVersion: 2017,
jsx: false,
},
noWatch: true,
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
/**
* Use `prettier` to override default formatting related rules
* See https://github.com/prettier/eslint-config-prettier
*/
'prettier',
'prettier/@typescript-eslint',
],
rules: {
'import/order': [
'error',
{
groups: [
'builtin',
'external',
'internal',
'parent',
'sibling',
'index',
],
pathGroups: [
{
pattern: '@/**',
group: 'internal',
position: 'after',
},
],
pathGroupsExcludedImportTypes: ['builtin'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
},
},
],
'sort-imports': [
1,
{
ignoreDeclarationSort: true,
},
],
'import/no-unresolved': 0,
'import/no-named-as-default': 0,
'no-await-in-loop': 1,
'prettier/prettier': 'error',
'prefer-const': 'error',
'no-mixed-operators': 'off',
'no-console': 'off',
// 'no-undef': 'off',
'no-inner-declarations': 'off',
// TypeScript allows method overloading
'no-dupe-class-members': 'off',
'no-useless-escape': 'off',
// TypeScript allows the same name for namespace and function
'no-redeclare': 'off',
// Avoid promise rewrapping
// https://exploringjs.com/es2016-es2017/ch_async-functions.html#_returned-promises-are-not-wrapped
'no-return-await': 'error',
/**
* Rules imported from eslint-config-loopback
*/
'mocha/handle-done-callback': 'error',
'mocha/no-exclusive-tests': 'error',
'mocha/no-identical-title': 'error',
'mocha/no-nested-tests': 'error',
'no-array-constructor': 'error',
/**
* TypeScript specific rules
* See https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules
*/
'@typescript-eslint/array-type': 'off',
'@typescript-eslint/indent': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/no-use-before-define': 'off',
'@typescript-eslint/no-object-literal-type-assertion': 'off',
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-angle-bracket-type-assertion': 'off',
'@typescript-eslint/prefer-interface': 'off',
'@typescript-eslint/no-namespace': 'off',
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/no-triple-slash-reference': 'off',
'@typescript-eslint/no-empty-interface': 'off',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
// Disable warning Missing return type on function for now
'@typescript-eslint/explicit-module-boundary-types': 'off',
/**
* The following rules are enforced to support legacy tslint configuration
*/
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/ROADMAP.md
// Rules mapped from `@loopback/tslint-config/tslint.common.json
'@typescript-eslint/adjacent-overload-signatures': 'error', // tslint:adjacent-overload-signatures
'@typescript-eslint/prefer-for-of': 'error', // tslint:prefer-for-of
'@typescript-eslint/unified-signatures': 'error', // tslint:unified-signatures
'@typescript-eslint/no-explicit-any': 'error', // tslint:no-any
'no-unused-labels': 'error', // tslint:label-position
'no-caller': 'error', // tslint:no-arg
'no-new-wrappers': 'error', // tslint:no-construct
// 'no-redeclare': 'error', // tslint:no-duplicate-variable
'no-invalid-this': 'off',
'@typescript-eslint/no-invalid-this': ['error'],
'@typescript-eslint/no-misused-new': 'error',
'no-shadow': 'error', // tslint:no-shadowed-variable
'no-throw-literal': 'error', // tslint:no-string-throw
'@typescript-eslint/no-unused-vars': [
'error',
{
vars: 'all',
args: 'none', // none - do not check arguments
/*
* The following is a workaround to the issue that parameter decorators
* are treated as `unused-vars`.
*
* See https://github.com/typescript-eslint/typescript-eslint/issues/571
*
* @example
* ```ts
* import {inject} from '@loopback/core';
* class MyController {
* constructor(@inject('foo') foo: string) {}
* }
* ```
*/
varsIgnorePattern: 'inject|(\\w+)Bindings',
ignoreRestSiblings: false,
},
], // tslint:no-unused-variable
'no-unused-expressions': 'error', // tslint:no-unused-expression
'no-var': 'error', // tslint:no-var-keyword
eqeqeq: ['error', 'smart'], // tslint:triple-equals: [true, 'allow-null-check', 'allow-undefined-check'],
// Rules mapped from `@loopback/tslint-config/tslint.build.json
'@typescript-eslint/await-thenable': 'error', // tslint:await-promise: [true, 'PromiseLike', 'RequestPromise'],
'@typescript-eslint/no-floating-promises': 'error',
'no-void': 'error', // tslint:no-void-expression: [true, 'ignore-arrow-function-shorthand'],
'@typescript-eslint/no-empty-function': 'off',
'@typescript-eslint/consistent-type-assertions': 'off',
'@typescript-eslint/no-misused-promises': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-nullish-coalescing': 'error',
'@typescript-eslint/no-extra-non-null-assertion': 'error',
'@typescript-eslint/return-await': 'error',
// https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/naming-convention.md
camelcase: 'off',
'@typescript-eslint/naming-convention': [
'error',
{
selector: 'default',
format: ['camelCase'],
},
{
selector: 'variable',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
},
{
selector: 'variable',
format: null,
filter: {
regex: '^_$',
match: true,
},
},
// For mixin functions
{
selector: 'function',
format: ['PascalCase'],
filter: {
regex: 'Mixin$',
match: true,
},
},
{
selector: 'parameter',
format: ['camelCase'],
leadingUnderscore: 'allow',
},
// For members such as `Content-Type`
{
selector: 'memberLike',
format: null,
filter: {
// you can expand this regex as you find more cases that require
// quoting that you want to allow
regex: '[- ]',
match: true,
},
},
// For enum members
{
selector: 'enumMember',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'allow',
},
// For properties
{
selector: 'property',
format: ['camelCase', 'UPPER_CASE', 'PascalCase'],
leadingUnderscore: 'allow',
},
{
selector: 'method',
format: ['camelCase'],
leadingUnderscore: 'allow',
},
// For static members
{
selector: 'memberLike',
modifiers: ['static'],
format: ['camelCase', 'UPPER_CASE'],
},
// For private members
{
selector: 'memberLike',
modifiers: ['private'],
format: ['camelCase'],
leadingUnderscore: 'allow',
},
// For protected members
{
selector: 'memberLike',
modifiers: ['protected'],
format: ['camelCase'],
leadingUnderscore: 'allow',
},
{
selector: 'typeLike',
format: ['PascalCase'],
},
],
},
overrides: [
{
files: ['**/*.js'],
rules: {
'@typescript-eslint/prefer-optional-chain': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off',
},
},
],
};
/**
* Detect tsconfig file
*/
function getProjectFile() {
if (fs.existsSync('./tsconfig.build.json')) return './tsconfig.build.json';
if (fs.existsSync('./tsconfig.json')) return './tsconfig.json';
return undefined;
}