-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheslint.config.mjs
280 lines (276 loc) · 9.62 KB
/
eslint.config.mjs
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
// @ts-check
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import angular from 'angular-eslint';
const basicAllowedAttributes = [
'autocomplete',
'charset',
'class',
'color',
'colspan',
'dir',
'fill',
'for',
'formArrayName',
'formControlName',
'formGroupName',
'height',
'href',
'id',
'lang',
'list',
'name',
'ngClass',
'ngProjectAs',
'role',
'routerLink',
'routerLinkActive',
'src',
'stroke',
'stroke-width',
'style',
'svgIcon',
'tabindex',
'target',
'type',
'value',
'viewBox',
'width',
'xmlns',
];
function tsFiles(files, extraRules = {}) {
return {
files: [files],
extends: [
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
...angular.configs.tsAll,
],
processor: angular.processInlineTemplates,
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: import.meta.dirname,
},
},
rules: {
'@angular-eslint/component-max-inline-declarations': 'off', // We use that mostly for testing, so it's fine
'@angular-eslint/no-forward-ref': 'off', // We sometimes need it
'@angular-eslint/prefer-on-push-component-change-detection': 'off',
'@angular-eslint/use-component-selector': 'off', // Some components are not template-able and thus do not need selector
'@typescript-eslint/consistent-type-definitions': ['error', 'type'],
'@typescript-eslint/explicit-member-accessibility': 'error',
'@typescript-eslint/no-confusing-void-expression': 'off', // Don't create unncessary closure and we prefer code tersity anyway
'@typescript-eslint/no-dynamic-delete': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/no-extraneous-class': 'off', // We have component without any logic in TS
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
'@typescript-eslint/no-unnecessary-condition': 'off', // This is very unfortunate, but there are too many dangerous false-positive, see https://github.com/typescript-eslint/typescript-eslint/issues/1798
'@typescript-eslint/no-unsafe-argument': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/prefer-nullish-coalescing': 'off', // Usually a good idea, but sometimes dangerous false-positive
'@typescript-eslint/unbound-method': 'off',
'@typescript-eslint/no-unnecessary-type-parameters': 'off', // The doc is scary, let's revisit this when we have time
'@angular-eslint/prefer-signals': [
'error',
{
preferInputSignals: false, // Only when our code will be entirely migrated to `input()`
},
],
'@angular-eslint/runtime-localize': 'off', // Because we never use runtime translations loading
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'app',
style: 'camelCase',
},
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'app',
style: 'kebab-case',
},
],
'@typescript-eslint/explicit-function-return-type': [
'error',
{
allowExpressions: true,
},
],
'@typescript-eslint/explicit-module-boundary-types': [
'error',
{
allowArgumentsExplicitlyTypedAsAny: true,
},
],
'@typescript-eslint/no-misused-promises': [
'error',
{
checksVoidReturn: {
// We want to use promise in Rxjs subscribes without caring about the promise result
arguments: false,
properties: false,
},
},
],
'@typescript-eslint/restrict-plus-operands': [
'error',
{
// Allow some flexibility
allowAny: true,
allowBoolean: true,
allowNullish: true,
allowNumberAndString: true,
},
],
'@typescript-eslint/restrict-template-expressions': [
'error',
{
// Allow some flexibility
allowAny: true,
allowBoolean: true,
allowNullish: true,
allowNumber: true,
},
],
'@typescript-eslint/no-unused-expressions': [
'error',
{
allowTernary: true,
},
],
'@typescript-eslint/no-unused-vars': [
'error',
{
caughtErrors: 'none',
},
],
'no-restricted-globals': [
'error',
'atob',
'bota',
'document',
'event',
'history',
'length',
'localStorage',
'location',
'name',
'navigator',
'sessionStorage',
'window',
],
...extraRules,
},
};
}
function htmlFiles(files, extraRules = {}) {
return {
files: [files],
extends: [...angular.configs.templateAll],
rules: {
'@angular-eslint/template/alt-text': 'off', // We don't care as much as we should about a11y
'@angular-eslint/template/button-has-type': 'off',
'@angular-eslint/template/click-events-have-key-events': 'off', // We don't care as much as we should about a11y
'@angular-eslint/template/i18n': 'off',
'@angular-eslint/template/interactive-supports-focus': 'off', // We don't care as much as we should about a11y
'@angular-eslint/template/label-has-associated-control': 'off', // We don't care as much as we should about a11y
'@angular-eslint/template/no-any': 'off', // Unfortunately, some libs force us to use this
'@angular-eslint/template/no-autofocus': 'off',
'@angular-eslint/template/no-call-expression': 'off',
'@angular-eslint/template/no-inline-styles': 'off', // We sometimes use short inline styles
'@angular-eslint/template/prefer-ngsrc': 'off', // TODO: experiment with ngsrc and see if we need to use it or not
'@angular-eslint/template/eqeqeq': [
'error',
{
allowNullOrUndefined: true,
},
],
...extraRules,
},
};
}
export default tseslint.config(
tsFiles('**/*.ts'),
tsFiles('projects/natural/src/**/*.ts', {
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'natural',
style: 'camelCase',
},
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'natural',
style: 'kebab-case',
},
],
}),
tsFiles('projects/natural-editor/src/**/*.ts', {
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'natural',
style: 'camelCase',
},
],
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'natural',
style: 'kebab-case',
},
],
}),
htmlFiles('**/*.html'),
htmlFiles('projects/natural/src/**/*.html', {
'@angular-eslint/template/i18n': [
'error',
{
checkId: false,
ignoreAttributes: [
...basicAllowedAttributes,
'align',
'aria-orientation',
'enumName',
'fontIcon',
'icon',
'loading',
'matColumnDef',
'matTooltipPosition',
'mode',
'naturalBackgroundDensity',
'naturalCustomCss',
'naturalIcon',
'naturalSrcDensity',
'panelWidth',
'srcset',
'togglePosition',
],
},
],
}),
htmlFiles('projects/natural-editor/src/**/*.html', {
'@angular-eslint/template/i18n': [
'error',
{
checkId: false,
ignoreAttributes: [...basicAllowedAttributes, 'align', 'fontIcon', 'naturalCustomCss', 'naturalIcon'],
},
],
}),
);