-
-
Notifications
You must be signed in to change notification settings - Fork 68
/
eslint.config.js
177 lines (176 loc) · 5.93 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
// @ts-check
const eslint = require("@eslint/js");
const tseslint = require("typescript-eslint");
const angulareslint = require("angular-eslint");
module.exports = tseslint.config(
{
files: ["**/*.ts"],
languageOptions: {
parserOptions: {
projectService: true,
tsconfigRootDir: __dirname,
},
},
extends: [
eslint.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
...angulareslint.configs.tsRecommended,
],
processor: angulareslint.processInlineTemplates,
"rules": {
// Good practice to differentiate component types
"@angular-eslint/component-class-suffix": [
"error",
{
"suffixes": [
"Component",
"Page"
]
}
],
// Prefixes
"@angular-eslint/component-selector": [
"error",
{
"type": "element",
"prefix": "app",
"style": "kebab-case"
}
],
"@angular-eslint/directive-selector": [
"error",
{
"type": "attribute",
"prefix": "app",
"style": "camelCase"
}
],
// Enforce modern JavaScript
"prefer-template": "error",
"prefer-arrow-callback": "error",
// Stricter JavaScript
"no-new-native-nonconstructor": "error",
"no-constant-binary-expression": "error",
"prefer-object-has-own": "error", // ES2022+
// Strict types
"eqeqeq": "error",
"@typescript-eslint/no-explicit-any": "error",
"@typescript-eslint/prefer-nullish-coalescing": "error",
"@typescript-eslint/use-unknown-in-catch-callback-variable": "error",
"@typescript-eslint/no-non-null-assertion": "error",
"@typescript-eslint/restrict-plus-operands": ["error", {
allowAny: false,
allowBoolean: false,
allowNullish: false,
allowNumberAndString: false,
allowRegExp: false,
}],
"@typescript-eslint/explicit-function-return-type": "error",
"@typescript-eslint/strict-boolean-expressions": ["error", {
allowNumber: false,
allowString: false,
}],
"@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/prefer-for-of": "error",
"@typescript-eslint/prefer-optional-chain": "error",
"@typescript-eslint/restrict-template-expressions": "error",
"no-shadow": "off",
"@typescript-eslint/no-shadow": "error",
"@typescript-eslint/prefer-readonly": "error",
"@typescript-eslint/no-useless-empty-export": "error",
// Stricter Angular ESLint rules
"@angular-eslint/prefer-standalone": "error",
"@angular-eslint/consistent-component-styles": "error",
"@angular-eslint/sort-lifecycle-methods": "error",
"@angular-eslint/contextual-decorator": "error",
"@angular-eslint/no-attribute-decorator": "error",
"@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/use-component-view-encapsulation": "error",
"@angular-eslint/use-injectable-provided-in": "error",
"@angular-eslint/no-async-lifecycle-method": "error",
// Stricter RxJS (disabled until package is updated)
// "rxjs/no-exposed-subjects": "warn", // should be error in a real project
// "rxjs/no-subclass": "error",
// "rxjs/no-subject-value": "error",
// "rxjs/no-topromise": "error",
// "rxjs/no-unsafe-catch": "error",
// "rxjs/no-unsafe-first": "error",
// "rxjs/no-unsafe-switchmap": "error",
// "rxjs/throw-error": "error",
// Annoying as Angular CLI generates empty classes and constructors
"@typescript-eslint/no-extraneous-class": [
"warn",
{
"allowWithDecorator": true
}
],
// Allow Angular forms validators like `Validator.required`
"@typescript-eslint/unbound-method": [
"error",
{
"ignoreStatic": true
}
],
// Disallow some imports
"no-restricted-imports": [
"error",
{
"paths": [
// Disallow imports from entry points inside a module (`.` = `./index`)
".",
"..",
"../..",
"../../.."
],
"patterns": [
// Disallow imports forbidden folders
"dist/*",
// Disallow imports from another application
"testing-apps/*"
]
}
]
},
},
{
files: ["**/*.html"],
extends: [
...angulareslint.configs.templateRecommended,
...angulareslint.configs.templateAccessibility,
],
rules: {
// Strict types
"@angular-eslint/template/no-any": "error",
// Stricter Anguler ESLint rules
"@angular-eslint/template/prefer-control-flow": "error",
"@angular-eslint/template/prefer-self-closing-tags": "warn",
"@angular-eslint/template/attributes-order": "warn",
"@angular-eslint/template/conditional-complexity": "error",
"@angular-eslint/template/cyclomatic-complexity": "error",
"@angular-eslint/template/no-duplicate-attributes": "error",
"@angular-eslint/template/no-interpolation-in-attributes": "error",
"@angular-eslint/template/no-inline-styles": [
"error",
{
"allowNgStyle": true,
"allowBindToStyle": true
}
],
"@angular-eslint/template/button-has-type": "error",
// More accessibility
"@angular-eslint/template/no-positive-tabindex": "error"
}
},
{
files: ['**/*.js'],
...tseslint.configs.disableTypeChecked,
},
);