-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheslint.config.js
More file actions
202 lines (188 loc) · 7.94 KB
/
eslint.config.js
File metadata and controls
202 lines (188 loc) · 7.94 KB
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
// @ts-check
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import angular from 'angular-eslint';
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
import * as importPlugin from 'eslint-plugin-import';
import rxjs from '@smarttools/eslint-plugin-rxjs';
import eslintPluginUnicorn from 'eslint-plugin-unicorn';
import globals from 'globals';
const config = tseslint.config(
{
files: ['**/*.ts'],
processor: angular.processInlineTemplates,
extends: [
eslint.configs.recommended,
tseslint.configs.stylisticTypeChecked,
tseslint.configs.strictTypeChecked,
angular.configs.tsRecommended,
// TODO
// 'plugin:rxjs/recommended', // For some unknown weird reason, this plugin needs to be installed in child project as well.
importPlugin.flatConfigs?.recommended,
importPlugin.flatConfigs?.typescript,
],
plugins: { rxjs },
settings: {
// Reference https://www.npmjs.com/package/eslint-plugin-import
'import/resolver': {
// You will also need to install and configure the TypeScript resolver
// See also https://github.com/import-js/eslint-import-resolver-typescript#configuration
typescript: true,
node: true,
},
},
rules: {
'no-implicit-coercion': 'error',
'no-self-compare': 'error',
'no-unmodified-loop-condition': 'error',
'no-unreachable-loop': 'error',
'default-case': 'warn',
eqeqeq: 'error',
'max-classes-per-file': 'error',
'no-warning-comments': ['error', { terms: ['todo', 'fixme'], location: 'anywhere' }],
'no-console': 'error',
'prefer-template': 'error',
'arrow-body-style': ['error', 'as-needed'],
/**
* Declaration sort is handled by import/order rule.
* This rule handles order within {}-brackets only.
*/
'sort-imports': ['error', { ignoreDeclarationSort: true }],
/**
* Handled by https://typescript-eslint.io/rules/no-unused-vars/
* You must disable the base rule as it can report incorrect errors
*/
'no-unused-vars': 'off',
// Reference https://github.com/cartant/eslint-plugin-rxjs/blob/main/docs/rules/finnish.md
'rxjs/finnish': [
'error',
{
functions: false,
methods: false,
names: {
'^(canActivate|canActivateChild|canDeactivate|canLoad|intercept|resolve|validate)$': false,
},
parameters: true,
properties: true,
strict: false,
types: {
'^EventEmitter$': false,
'^Store$': false,
},
variables: true,
},
],
'rxjs/no-exposed-subjects': ['error', { allowProtected: true }],
'rxjs/no-compat': 'error',
'rxjs/throw-error': 'error',
'@typescript-eslint/no-unused-vars': ['error', { args: 'after-used' }],
'@typescript-eslint/unbound-method': ['error', { ignoreStatic: true }], // Ignore `Validators.required` etc.
'@typescript-eslint/no-confusing-void-expression': 'off', // I just simply disagree with this rule
'@typescript-eslint/explicit-member-accessibility': [
'error',
{ overrides: { constructors: 'no-public' } },
],
'@typescript-eslint/prefer-optional-chain': 'error',
'@typescript-eslint/no-unnecessary-type-parameters': 'off', // Too noisy and faulty
'@angular-eslint/no-input-rename': 'off', // I just simply disagree with this rule. Especially while using "transform" property.
'@angular-eslint/prefer-on-push-component-change-detection': 'error',
'@angular-eslint/use-component-view-encapsulation': 'warn', // For me, it is only a suggestion
'@angular-eslint/prefer-output-readonly': 'error', // TODO: https://github.com/jmeinlschmidt/eslint-config-angular/issues/14
'@angular-eslint/contextual-decorator': 'error',
'@angular-eslint/component-max-inline-declarations': ['error', { template: 20 }],
'@angular-eslint/no-attribute-decorator': 'error',
'@angular-eslint/no-conflicting-lifecycle': 'error',
'@angular-eslint/no-empty-lifecycle-method': 'error',
'@angular-eslint/no-forward-ref': 'warn', // For me, it is only a suggestion
'@angular-eslint/no-input-prefix': 'error',
'@angular-eslint/no-lifecycle-call': 'error',
'@angular-eslint/no-pipe-impure': 'error',
'@angular-eslint/no-queries-metadata-property': 'error',
'@angular-eslint/prefer-standalone': 'error',
'@angular-eslint/prefer-signals': 'error',
'@angular-eslint/relative-url-prefix': 'error',
// '@angular-eslint/require-localize-metadata': 'error', // TODO: https://github.com/jmeinlschmidt/eslint-config-angular/issues/13
'@angular-eslint/use-component-selector': 'error',
'@angular-eslint/component-selector': [
'error',
{
type: 'element',
prefix: 'app',
style: 'kebab-case',
},
],
'@angular-eslint/directive-selector': [
'error',
{
type: 'attribute',
prefix: 'app',
style: 'kebab-case', // I just don't really agree with using camelCase. Material isn't using it either.
},
],
'import/no-absolute-path': 'error',
'import/newline-after-import': ['error', { count: 1 }],
'import/order': [
'error',
{
groups: [['builtin', 'external'], 'internal', 'parent', 'sibling', 'index'],
'newlines-between': 'always',
alphabetize: {
order: 'asc',
caseInsensitive: true,
},
},
],
'import/no-useless-path-segments': ['error', { noUselessIndex: true }],
// 'import/no-deprecated': 'error', // Throws false-positive for RxJS,
'import/no-self-import': 'error',
},
},
{
files: ['**/*.html'],
extends: [...angular.configs.templateRecommended, ...angular.configs.templateAccessibility],
rules: {
'@angular-eslint/template/attributes-order': 'error',
'@angular-eslint/template/no-inline-styles': 'warn', // For me, it is only a suggestion
'@angular-eslint/template/conditional-complexity': [
'error',
{ maxComplexity: 3 }, // Max 3 is enough, create derived variable with proper naming
],
'@angular-eslint/template/i18n': 'error',
'@angular-eslint/template/no-any': 'error',
'@angular-eslint/template/no-duplicate-attributes': 'error',
'@angular-eslint/template/no-interpolation-in-attributes': 'error',
'@angular-eslint/template/prefer-self-closing-tags': 'error',
'@angular-eslint/template/use-track-by-function': 'error',
'@angular-eslint/template/prefer-control-flow': 'error',
},
},
{
languageOptions: {
globals: globals.builtin,
},
extends: [eslintPluginUnicorn.configs.recommended],
rules: {
'unicorn/prevent-abbreviations': 'off', // I disagree with this rule
'unicorn/no-empty-file': 'off', // Fails the lint
'unicorn/prefer-string-raw': 'off', // Fails the lint
'unicorn/no-null': 'off', // Too noisy
'unicorn/no-useless-undefined': 'off', // Tends to be faulty
'unicorn/no-array-sort': 'off', // Tends to be faulty
'unicorn/no-array-reverse': 'off', // Tends to be faulty
'unicorn/no-array-reduce': 'off', // I disagree with this rule
'unicorn/no-array-callback-reference': 'off', // I disagree with this rule
'unicorn/consistent-function-scoping': 'off', // I disagree with this rule
'unicorn/prefer-spread': 'off', // Tends to be faulty
'unicorn/prefer-math-min-max': 'off', // Tends to be faulty
},
},
// Prettier rule must always be the very last!
// This rule might intentionally disable some rules declared above due to conflicts
eslintPluginPrettierRecommended,
);
export default config;
// notes
// these two are not supported anymore
// "eslint-plugin-rxjs": ">=5",
// "eslint-plugin-rxjs-angular": ">=2",
// todo, test if we really need peer deps