forked from finos/legend-engine-ide-client-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.eslintrc.cjs
218 lines (210 loc) · 8.39 KB
/
.eslintrc.cjs
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
/**
* Copyright (c) 2020-present, Goldman Sachs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/* eslint-env node */
const OFF = 0;
const WARN = 1;
const ERROR = 2;
/**
* Since we use `prettier`, we try to keep this config as close to `prettier`
* standard as possible, especially in terms of spacing.
*/
const ES_RULES = {
'array-bracket-spacing': [ERROR, 'never'],
'arrow-body-style': [WARN, 'as-needed'],
'array-callback-return': ERROR,
'arrow-parens': WARN,
'arrow-spacing': WARN,
'block-spacing': [WARN, 'always'],
'brace-style': OFF, // this will be managed by `prettier`
'comma-dangle': [ERROR, 'only-multiline'],
'comma-spacing': [WARN, { before: false, after: true }],
'comma-style': [ERROR, 'last'],
'consistent-return': ERROR,
'consistent-this': [ERROR, 'self'],
'constructor-super': ERROR,
curly: ERROR,
'default-case': ERROR,
'dot-location': [ERROR, 'property'],
'dot-notation': [ERROR, { allowKeywords: true }],
'eol-last': [WARN, 'always'],
eqeqeq: ERROR,
'func-call-spacing': OFF,
'guard-for-in': ERROR,
'jsx-quotes': ERROR,
'key-spacing': WARN,
'keyword-spacing': [WARN, { before: true, after: true }],
'no-console': WARN,
'no-const-assign': ERROR,
'no-debugger': WARN,
// NOTE: this rule is useful for us to enforce usage of inline type imports and exports
// e.g. `import { type A, B } from ...` over `import type { A } from ...; import { B } from ...;`
// We would not need to enable rule `import/no-duplicates` anymore
// Also we could include the duplication detection to include exports using `includeExports` flag
// See https://github.com/typescript-eslint/typescript-eslint/issues/4338
'no-duplicate-imports': [WARN, { includeExports: true }],
'no-fallthrough': ERROR,
'no-global-assign': ERROR,
'no-invalid-regexp': ERROR,
'no-irregular-whitespace': ERROR,
'no-magic-numbers': [OFF, { ignore: [-1, 0, 1], enforceConst: true }],
'no-mixed-spaces-and-tabs': ERROR,
'no-multi-assign': WARN,
'no-multi-spaces': WARN,
'no-multiple-empty-lines': [WARN, { max: 1 }],
'no-process-env': ERROR,
'no-process-exit': ERROR,
'no-proto': ERROR,
'no-prototype-builtins': ERROR,
'no-redeclare': OFF,
'no-regex-spaces': ERROR,
'no-return-await': ERROR,
'no-return-assign': ERROR,
/**
* This is a workaround as `import/no-relative-parent-imports` is not working properly with Typescript as of 2.20.1
* See https://github.com/benmosher/eslint-plugin-import/issues/1644
* See https://github.com/benmosher/eslint-plugin-import/issues/834
* See https://github.com/benmosher/eslint-plugin-import/issues/669#issuecomment-316438608
*
* NOTE: This is a rule that we would like to turn on by default to avoid ugly relative import paths,
* such as `../../../../something`, but due to problem with Typescript's not resolving these to absolute
* paths while creating type declaration files, we decided to allow relative paths
* See https://github.com/microsoft/TypeScript/issues/30952
* See https://github.com/microsoft/TypeScript/issues/15479
* See https://github.com/microsoft/TypeScript/issues/26722
*/
// 'no-restricted-imports': [WARN, { patterns: ['../*'] }],
'no-trailing-spaces': WARN,
'no-unused-labels': WARN,
'no-unsafe-finally': ERROR,
'no-unsafe-negation': WARN,
'no-unreachable': ERROR,
'no-var': ERROR,
'no-void': ERROR,
'no-whitespace-before-property': ERROR,
'object-curly-spacing': [WARN, 'always'],
'prefer-arrow-callback': [ERROR, { allowNamedFunctions: true }],
'prefer-const': WARN,
'prefer-named-capture-group': WARN,
'prefer-template': WARN,
quotes: [WARN, 'single', { avoidEscape: true, allowTemplateLiterals: true }],
'require-yield': OFF,
semi: [WARN, 'always', { omitLastInOneLineBlock: true }],
'semi-spacing': [WARN, { after: true, before: false }],
'semi-style': WARN,
'space-before-blocks': WARN,
'space-before-function-paren': [
WARN,
{ anonymous: 'always', named: 'never' },
],
'space-in-parens': [WARN, 'never'],
'space-infix-ops': WARN,
'space-unary-ops': WARN,
strict: ERROR,
'switch-colon-spacing': WARN,
'template-curly-spacing': WARN,
'template-tag-spacing': WARN,
};
const IMPORT_RULES = {
// Turn off rules as per recommendation of typescript-eslint
// See https://typescript-eslint.io/linting/troubleshooting/performance-troubleshooting
'import/no-unresolved': OFF,
'import/named': OFF,
'import/namespace': OFF,
'import/default': OFF,
'import/export': OFF,
'import/no-named-as-default': OFF,
'import/no-named-as-default-member': OFF,
'import/no-deprecated': OFF,
'import/no-unused-modules': OFF,
'import/no-cycle': OFF,
'import/extensions': OFF, // we don't need this since TS already covered this check
'import/newline-after-import': [WARN, { count: 1 }],
'import/no-default-export': WARN,
};
const REACT_RULES = {
'react-hooks/rules-of-hooks': ERROR,
'react-hooks/exhaustive-deps': WARN,
'react/jsx-boolean-value': [ERROR, 'always'],
'react/jsx-fragments': [WARN, 'syntax'],
'react/react-in-jsx-scope': OFF, // turn off as we use React@17 new JSX transform
// using index as key often cause bug when we do form view so we have to be careful
// NOTE: to handle this, we will use object UUID (UUID when we create an object) to make sure the key is unique
'react/jsx-key': ERROR,
'react/jsx-no-target-blank': ERROR,
'react/no-array-index-key': WARN,
'react/no-deprecated': ERROR,
'react/no-direct-mutation-state': ERROR,
'react/no-unescaped-entities': ERROR,
// we use Typescript interface instead of `prop-types`
'react/prop-types': OFF,
// here are a few rules we follow to make `vscode` auto format work better with eslint
'react/jsx-tag-spacing': [WARN, { beforeSelfClosing: 'always' }],
'react/jsx-curly-spacing': [WARN, { when: 'never', allowMultiline: true }],
};
const TYPESCRIPT_RULES = {
'@typescript-eslint/no-empty-object-type': WARN,
'@typescript-eslint/no-unsafe-function-type': WARN,
'@typescript-eslint/no-wrapper-object-types': WARN,
'@typescript-eslint/consistent-type-imports': WARN,
'@typescript-eslint/explicit-function-return-type': [
WARN,
{ allowExpressions: true, allowTypedFunctionExpressions: true },
],
'@typescript-eslint/no-inferrable-types': [WARN, { ignoreParameters: true }],
'@typescript-eslint/no-redeclare': [ERROR, { ignoreDeclarationMerge: true }],
'@typescript-eslint/no-var-requires': OFF,
'@typescript-eslint/no-unused-vars': [
WARN,
{ args: 'none', ignoreRestSiblings: true },
],
// NOTE: the following rules are stylistic only
'@typescript-eslint/no-shadow': WARN,
// NOTE: since functions are hoisted in ES6, it is then advisable to enable this rule so that we can have functions that depend on each other and not causing
// circular module dependency. It is also said to be safe to use
// See https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/no-use-before-define.md#options
'@typescript-eslint/no-use-before-define': [ERROR, { functions: false }],
'@typescript-eslint/no-useless-constructor': WARN,
};
module.exports = {
parser: '@typescript-eslint/parser',
plugins: ['prettier', 'react-hooks', '@typescript-eslint'],
parserOptions: {
tsconfigRootDir: __dirname,
project: './tsconfig.json',
},
settings: {
react: {
version: 'detect',
},
},
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/eslint-recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react/recommended',
'plugin:import/errors', // See https://github.com/benmosher/eslint-plugin-import/blob/master/config/errors.js
'plugin:import/typescript', // See https://github.com/benmosher/eslint-plugin-import/blob/master/config/typescript.js
],
rules: {
...ES_RULES,
...TYPESCRIPT_RULES,
...IMPORT_RULES,
...REACT_RULES,
'@typescript-eslint/no-unsafe-argument': OFF,
'@typescript-eslint/no-unsafe-member-access': OFF,
},
root: true,
};