-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy patheslint.config.js
226 lines (225 loc) · 7.89 KB
/
eslint.config.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
import eslint from '@eslint/js';
import * as regexpPlugin from 'eslint-plugin-regexp';
import sonarjs from 'eslint-plugin-sonarjs';
import globals from 'globals';
import tseslint from 'typescript-eslint';
// TODO: different configs for JS vs TS
export default tseslint.config(
{ name: 'eslint/recommended', ...eslint.configs.recommended },
...tseslint.configs.recommendedTypeChecked,
{
name: 'typescript-eslint/parser-options',
languageOptions: {
parserOptions: {
project: './api/tsconfig.eslint.json',
tsconfigRootDir: import.meta.dirname,
},
},
},
...tseslint.configs.stylisticTypeChecked,
regexpPlugin.configs['flat/recommended'],
{ name: 'sonarjs/recommended', ...sonarjs.configs.recommended },
{
name: 'global ignores',
ignores: ['*.test.ts', 'api/migrations/*', 'api/stately/generated/*.js'],
},
{
name: 'dim-api-custom',
languageOptions: {
ecmaVersion: 'latest',
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
},
sourceType: 'module',
globals: {
...globals.node,
},
},
linterOptions: {
reportUnusedDisableDirectives: true,
},
rules: {
'no-console': 'off',
'no-empty': 'off',
'require-atomic-updates': 'off',
'@typescript-eslint/no-unused-vars': [
'error',
{
varsIgnorePattern: '(^_|[iI]gnored)',
argsIgnorePattern: '(^_|[iI]gnored)',
ignoreRestSiblings: true,
},
],
'no-restricted-properties': [
1,
{
object: '_',
property: 'forEach',
message: 'Please use a for in loop.',
},
{
object: '_',
property: 'filter',
message: 'Please use the native js filter.',
},
{
object: '_',
property: 'map',
message: 'Please use the native js map.',
},
{
object: '_',
property: 'uniq',
message: 'Please use Array.from(new Set(foo)) or [...new Set(foo)] instead.',
},
{
object: '_',
property: 'forIn',
message: 'Please use Object.values or Object.entries instead',
},
{
object: '_',
property: 'noop',
message:
'Import noop directly instead of using it through _.noop, to satisfy the unbound-method lint',
},
{
object: '_',
property: 'groupBy',
message: 'Use Object.groupBy or Map.groupBy instead.',
},
{
object: '_',
property: 'cloneDeep',
message: 'Use structuredClone instead.',
},
],
'no-restricted-syntax': [
'error',
{
selector: 'TSEnumDeclaration:not([const=true])',
message: 'Please only use `const enum`s.',
},
],
// TODO: Switch to @stylistic/eslint-plugin-js for this one rule
'spaced-comment': [
'error',
'always',
{ exceptions: ['@__INLINE__'], block: { balanced: true } },
],
'arrow-body-style': ['error', 'as-needed'],
curly: ['error', 'all'],
eqeqeq: ['error', 'always'],
'@typescript-eslint/return-await': ['error', 'in-try-catch'],
'prefer-regex-literals': 'error',
'prefer-promise-reject-errors': 'error',
'prefer-spread': 'error',
radix: 'error',
yoda: 'error',
'prefer-template': 'error',
'class-methods-use-this': ['error', { exceptMethods: ['render'] }],
'no-unmodified-loop-condition': 'error',
'no-unreachable-loop': 'error',
'no-unused-private-class-members': 'error',
'func-name-matching': 'error',
'logical-assignment-operators': 'error',
'no-lonely-if': 'error',
'no-unneeded-ternary': 'error',
'no-useless-call': 'error',
'no-useless-concat': 'error',
'no-useless-rename': 'error',
'@typescript-eslint/await-thenable': 'error',
'@typescript-eslint/no-misused-promises': [
'error',
{
checksVoidReturn: false,
},
],
'@typescript-eslint/ban-types': 'off',
'@typescript-eslint/explicit-member-accessibility': 'off',
'@typescript-eslint/explicit-function-return-type': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/method-signature-style': 'error',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-use-before-define': ['error', { functions: false }],
'@typescript-eslint/no-parameter-properties': 'off',
'@typescript-eslint/no-extraneous-class': 'error',
'@typescript-eslint/no-this-alias': 'error',
'@typescript-eslint/no-unnecessary-type-constraint': 'error',
'@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error',
'@typescript-eslint/no-unnecessary-qualifier': 'error',
'@typescript-eslint/no-unnecessary-type-assertion': 'error',
'@typescript-eslint/no-unnecessary-type-arguments': 'error',
'@typescript-eslint/prefer-function-type': 'error',
'@typescript-eslint/prefer-for-of': 'error',
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/prefer-as-const': 'error',
'@typescript-eslint/prefer-reduce-type-parameter': 'error',
'@typescript-eslint/prefer-includes': 'error',
'@typescript-eslint/prefer-string-starts-ends-with': 'error',
'@typescript-eslint/prefer-regexp-exec': 'off',
'@typescript-eslint/array-type': 'error',
'@typescript-eslint/no-non-null-asserted-optional-chain': 'error',
'@typescript-eslint/unified-signatures': 'error',
'@typescript-eslint/no-base-to-string': 'error',
'@typescript-eslint/non-nullable-type-assertion-style': 'error',
'@typescript-eslint/switch-exhaustiveness-check': 'off',
'@typescript-eslint/consistent-type-definitions': 'error',
'@typescript-eslint/consistent-generic-constructors': 'error',
'@typescript-eslint/no-duplicate-enum-values': 'error',
'@typescript-eslint/only-throw-error': 'error',
'@typescript-eslint/no-unused-expressions': [
'error',
{ allowShortCircuit: true, allowTernary: true },
],
'@typescript-eslint/no-for-in-array': 'error',
'@typescript-eslint/consistent-indexed-object-style': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/require-await': 'off',
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
'@typescript-eslint/prefer-nullish-coalescing': [
'off',
{
ignoreConditionalTests: true,
ignoreTernaryTests: false,
ignoreMixedLogicalExpressions: true,
ignorePrimitives: {
boolean: true,
number: false,
string: true,
},
},
],
'@typescript-eslint/no-unsafe-argument': 'error',
'@typescript-eslint/no-unsafe-assignment': 'error',
'@typescript-eslint/no-unsafe-call': 'error',
'@typescript-eslint/no-unsafe-member-access': 'error',
'@typescript-eslint/no-unsafe-return': 'error',
'@typescript-eslint/no-redundant-type-constituents': 'off',
'no-implied-eval': 'off',
'@typescript-eslint/no-implied-eval': 'error',
'sonarjs/cognitive-complexity': 'off',
'sonarjs/no-small-switch': 'off',
'sonarjs/no-duplicate-string': 'off',
'sonarjs/prefer-immediate-return': 'off',
'sonarjs/no-nested-switch': 'off',
'sonarjs/no-nested-template-literals': 'off',
},
},
{
files: ['src/**/*.cjs'],
rules: {
'@typescript-eslint/no-require-imports': 'off',
},
},
{
name: 'tests',
files: ['**/*.test.ts'],
rules: {
// We don't want to allow importing test modules in app modules, but of course you can do it in other test modules.
'no-restricted-imports': 'off',
},
},
);