-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.eslintrc.js
324 lines (293 loc) · 10.5 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
// ========================================================================
// Eslint Configuration (@starterkit)
// Now supports TypeScript!
//
// 🔗 https://babeljs.io/docs/en/config-files
// 🔗 https://new.babeljs.io/docs/en/next/babelconfigjs.html
//
// The philosophy behind these rules is that 99% should be autofix'able.
//
// ======================================================================== */
const js = ['.js', '.jsx', '*.mjs']
const ts = ['.ts', '.tsx', '*.mjs']
const extensions = { ts, all: [...js, ...ts] }
const OFF = 'off'
/**
* Helpers
* ----------------------------------------------------
*/
const paddingWildcard = (blankLine = 'always', rules = []) => {
return [
{ blankLine, prev: rules, next: '*' }, //
{ blankLine, prev: '*', next: rules },
]
}
const conf = {
config() {
// Uncomment for debugging / live editing rules
delete require.cache[require.resolve(__filename)]
// parser: '@typescript-eslint/parser',
const config = {}
config.parserOptions = {
ecmaVersion: 2022, // Allows for the parsing of modern ECMAScript features
sourceType: 'module', // Allows for the use of imports
project: ["tsconfig.json"],
// This setting is required if you want to use rules which require type information.
// Slows down linting a bit
// project: require('path').resolve(__dirname, './tsconfig.json'),
// tsconfigRootDir: __dirname,
}
config.settings = {
'import/extensions': extensions.all,
'import/parsers': {
'@typescript-eslint/parser': extensions.all,
},
'import/resolver': {
node: { extensions: extensions.all },
},
}
config.plugins = ['unicorn', 'sonarjs']
config.extends = [
// Uses the recommended rules from the @typescript-eslint/eslint-plugin
'plugin:@typescript-eslint/recommended',
// May be slow on large code bases
// "plugin:@typescript-eslint/recommended-requiring-type-checking",
// https://github.com/SonarSource/eslint-plugin-sonarjs
'plugin:sonarjs/recommended',
// https://github.com/standard/eslint-config-standard/blob/master/eslintrc.json
'standard',
// https://github.com/benmosher/eslint-plugin-import
'plugin:import/errors',
// Uses eslint-config-prettier to disable ESLint rules from
// @typescript-eslint/eslint-plugin that would conflict with prettier
// 'prettier/@typescript-eslint',
// 'eslint-config-prettier',
// Turns off all rules that are unnecessary or might conflict with Prettier.
// https://github.com/prettier/eslint-config-prettier/blob/master/standard.js
'prettier',
// Enables eslint-plugin-prettier and eslint-config-prettier.
// This will display prettier errors as ESLint errors.
// Make sure this is always the last configuration in the extends array.
'plugin:prettier/recommended',
]
config.env = {
browser: true,
es6: true,
node: true,
jest: true,
}
// Allow globals to exist without throwing an error.
// i.e: Sys, Environment, jQuery
config.globals = {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
__DEV__: true,
__DEBUG__: true,
__TEST__: true,
__PROD__: true,
__BUILD_DATE__: true,
__VERSION__: true,
__GITHASH__: true,
}
// Overrides
config.overrides = [
// Rules specifically for TypeScript files
{
files: ['*.ts', '*.tsx'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': ['error'],
},
},
// Rules specifically for Javascript files
{
files: ['*.js', '*.jsx', '*.mjs'],
rules: {
'@typescript-eslint/explicit-module-boundary-types': ['error'],
},
},
// Rules specifically for Test files
{
files: ['*.spec.*', '*.test.*', '*.e2e.*', 'test.*'],
rules: {
// Keep tests simple & clean
'padding-line-between-statements': [
'error',
...paddingWildcard('always', ['multiline-expression']),
],
'sonarjs/cognitive-complexity': ['error', 10],
'complexity': ['error', 5],
},
},
]
/**
Built-in Eslint Rules: https://eslint.org/docs/rules/
_______________________________
*/
config.rules = {
"require-await": "off",
"@typescript-eslint/require-await": "error",
// 'max-len': ['error', { code: 80 }],
'complexity': ['error', 20],
'camelcase': OFF,
'no-multi-spaces': [
1,
{
exceptions: {
VariableDeclarator: true,
ObjectExpression: true,
},
},
],
// indent: ['error', 4],
'dot-notation': OFF,
'indent': ['error', 2, { VariableDeclarator: { var: 2, let: 2, const: 3 } }],
'no-unused-expressions': OFF,
'no-unused-vars': OFF,
// 'one-var': ['error', 'always'],
'global-require': OFF,
'no-var': 'error',
// 'one-var': ['error', { var: 'never', let: 'consecutive', const: 'consecutive' }],
'prefer-const': 'error',
'prefer-template': 'error',
'object-shorthand': [
'error',
'always',
{
ignoreConstructors: true,
},
],
'lines-between-class-members': ['error', 'always', { exceptAfterSingleLine: true }],
// 'comma-dangle': ['error', 'always-multiline'],
/**
* Sonar rules
*/
'sonarjs/prefer-immediate-return': 'error',
'sonarjs/no-duplicate-string': OFF,
'sonarjs/no-identical-functions': OFF,
// Tweak cognitive complexity to your liking
'sonarjs/cognitive-complexity': ['error', 10],
/**
* Linebreak / Codestyle
* https://eslint.org/docs/rules/padding-line-between-statements
* Warning: Don't mess with these unless you know what you'e doing since
* they can interfere with prettier
*/
'padding-line-between-statements': [
'error',
...(() => {
// Common base rules to be used for line breaks
const alwaysUseLineBreak = [
'block-like',
'block',
'cjs-export',
'class',
'directive',
'for',
'function',
'if',
'throw',
'try',
]
return [
// 2. Enforces const,let to always create a block of code
{ blankLine: 'always', prev: ['const', 'let'], next: '*' },
// 3. Enforces exports to always create a block of code
// Allows const & export const to be grouped
{ blankLine: 'always', prev: '*', next: 'export' },
...paddingWildcard('any', ['const', 'let', 'export']),
// 4. Avoid unreadable multiline commands
{ blankLine: 'always', prev: 'multiline-expression', next: '*' },
// 5. Experimental
{ blankLine: 'always', prev: alwaysUseLineBreak, next: ['export'] },
// 1. Common rules to create linebreaks
...paddingWildcard('always', alwaysUseLineBreak),
]
})(),
],
/**
* Typescript-Eslint Rules
* https://www.npmjs.com/package/@typescript-eslint/eslint-plugin
* ----------------------------------------------------
*/
'@typescript-eslint/ban-types': OFF,
// '@typescript-eslint/no-floating-promises': OFF, // TODO: https://github.com/typescript-eslint/typescript-eslint/issues/464
"@typescript-eslint/no-floating-promises": "error",
// '@typescript-eslint/camelcase': ['error', { properties: 'never' }],
'@typescript-eslint/no-non-null-assertion': OFF,
'@typescript-eslint/no-use-before-define': ['error', { functions: false, variables: false }],
'@typescript-eslint/explicit-function-return-type': OFF,
'@typescript-eslint/explicit-member-accessibility': ['error', { accessibility: 'no-public' }],
'@typescript-eslint/no-var-requires': OFF,
'@typescript-eslint/no-parameter-properties': OFF,
'@typescript-eslint/no-explicit-any': OFF,
'@typescript-eslint/consistent-type-assertions': 'error',
'@typescript-eslint/no-unused-vars': [
'error',
{
vars: 'all',
varsIgnorePattern: '^[_$]|[_$]$',
args: 'after-used',
caughtErrors: 'none',
ignoreRestSiblings: true,
argsIgnorePattern: '^[_$]',
},
],
/**
* Import Plugin Rules
* ----------------------------------------------------
*/
'import/no-unresolved': OFF,
'import/no-useless-path-segments': ['error'],
'import/named': 'error',
'import/namespace': 'error',
'import/default': 'error',
'import/export': 'error',
'import/extensions': ['error', 'never'],
'import/newline-after-import': 'error',
'import/no-extraneous-dependencies': 'error',
'import/order': [
'error',
{
groups: ['builtin', 'external', 'internal', 'parent', 'sibling', 'index'],
},
],
/**
* Unicorn rules
* https://github.com/sindresorhus/eslint-plugin-unicorn
* ----------------------------------------------------
*/
'unicorn/catch-error-name': 'error',
'unicorn/custom-error-definition': OFF,
'unicorn/error-message': 'error',
// DISABLED due to not practical in global settings
// 'unicorn/filename-case': [
// 'error',
// {
// // https://github.com/sindresorhus/eslint-plugin-unicorn/blob/master/docs/rules/filename-case.md
// cases: {
// kebabCase: true,
// camelCase: true,
// pascalCase: true,
// snakeCase: false
// }
// }
// ],
'unicorn/import-index': 'error',
'unicorn/new-for-builtins': OFF,
'unicorn/no-abusive-eslint-disable': 'error',
'unicorn/no-array-instanceof': 'error',
'unicorn/no-console-spaces': 'error',
'unicorn/no-for-loop': OFF,
'unicorn/no-process-exit': 'error',
'unicorn/no-unreadable-array-destructuring': 'error',
'unicorn/no-unused-properties': 'error',
'unicorn/no-zero-fractions': 'error',
'unicorn/prefer-exponentiation-operator': 'error',
'unicorn/prefer-includes': 'error',
'unicorn/prefer-type-error': 'error',
'unicorn/regex-shorthand': 'error',
}
return config
},
}
module.exports = conf.config()