Skip to content

Commit a27876d

Browse files
committed
Update eslint rules #10134
It's been a while since we updated our rules. This time we opt in into all rules and explicitly disable the ones that don't fit our code. This way we will automatically receive new rules in the future, and we can decide whether we accept or reject them, instead of needing to re-check which one is new at every update.
1 parent 754404d commit a27876d

File tree

4 files changed

+70
-34
lines changed

4 files changed

+70
-34
lines changed

.eslintrc.json

Lines changed: 55 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,37 @@
44
{
55
"files": ["*.ts"],
66
"parserOptions": {
7-
"project": ["tsconfig.json"],
7+
"project": true,
88
"createDefaultProgram": true
99
},
1010
"extends": [
1111
"eslint:recommended",
12-
"plugin:@typescript-eslint/recommended",
13-
"plugin:@angular-eslint/recommended",
12+
"plugin:@typescript-eslint/strict-type-checked",
13+
"plugin:@typescript-eslint/stylistic-type-checked",
14+
"plugin:@angular-eslint/all",
1415
"plugin:@angular-eslint/template/process-inline-templates"
1516
],
1617
"rules": {
18+
"@angular-eslint/component-max-inline-declarations": "off", // We use that mostly for testing, so it's fine
19+
"@angular-eslint/no-forward-ref": "off", // We sometimes need it
20+
"@angular-eslint/prefer-on-push-component-change-detection": "off",
21+
"@angular-eslint/use-component-selector": "off", // Some components are not template-able and thus do not need selector
22+
"@typescript-eslint/consistent-type-definitions": ["error", "type"],
23+
"@typescript-eslint/explicit-member-accessibility": "error",
24+
"@typescript-eslint/no-confusing-void-expression": "off", // We prefer code tersity
25+
"@typescript-eslint/no-dynamic-delete": "off",
26+
"@typescript-eslint/no-explicit-any": "off",
27+
"@typescript-eslint/no-extraneous-class": "off", // We have component without any logic in TS
28+
"@typescript-eslint/no-floating-promises": "off",
29+
"@typescript-eslint/no-non-null-assertion": "off",
30+
"@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
31+
"@typescript-eslint/no-unsafe-argument": "off",
32+
"@typescript-eslint/no-unsafe-assignment": "off",
33+
"@typescript-eslint/no-unsafe-call": "off",
34+
"@typescript-eslint/no-unsafe-member-access": "off",
35+
"@typescript-eslint/no-unsafe-return": "off",
36+
"@typescript-eslint/prefer-nullish-coalescing": "off", // Usually a good idea, but sometimes dangerous false-positive
37+
"@typescript-eslint/unbound-method": "off",
1738
"@angular-eslint/directive-selector": [
1839
"error",
1940
{
@@ -30,21 +51,28 @@
3051
"style": "kebab-case"
3152
}
3253
],
33-
"@typescript-eslint/ban-types": "error",
3454
"@typescript-eslint/explicit-function-return-type": [
3555
"error",
3656
{
3757
"allowExpressions": true
3858
}
3959
],
40-
"@typescript-eslint/explicit-member-accessibility": "error",
4160
"@typescript-eslint/explicit-module-boundary-types": [
4261
"error",
4362
{
4463
"allowArgumentsExplicitlyTypedAsAny": true
4564
}
4665
],
47-
"@typescript-eslint/prefer-for-of": "error",
66+
"@typescript-eslint/no-misused-promises": [
67+
"error",
68+
{
69+
"checksVoidReturn": {
70+
// We want to use promise in Rxjs subscribes without caring about the promise result
71+
"arguments": false,
72+
"properties": false
73+
}
74+
}
75+
],
4876
"no-restricted-globals": [
4977
"error",
5078
"atob",
@@ -64,8 +92,27 @@
6492
},
6593
{
6694
"files": ["*.html"],
67-
"extends": ["plugin:@angular-eslint/template/recommended"],
68-
"rules": {}
95+
"extends": ["plugin:@angular-eslint/template/all"],
96+
"rules": {
97+
"@angular-eslint/template/alt-text": "off", // We don't care as much as we should about a11y
98+
"@angular-eslint/template/attributes-order": "off", // TODO: We want to enable this, but autofix mess up our code, and it's too much manual changes
99+
"@angular-eslint/template/button-has-type": "off",
100+
"@angular-eslint/template/click-events-have-key-events": "off", // We don't care as much as we should about a11y
101+
"@angular-eslint/template/i18n": "off",
102+
"@angular-eslint/template/interactive-supports-focus": "off", // We don't care as much as we should about a11y
103+
"@angular-eslint/template/label-has-associated-control": "off", // We don't care as much as we should about a11y
104+
"@angular-eslint/template/no-any": "off", // Unfortunately, some libs force us to use this
105+
"@angular-eslint/template/no-autofocus": "off",
106+
"@angular-eslint/template/no-call-expression": "off",
107+
"@angular-eslint/template/no-inline-styles": "off", // We sometimes use short inlie styles
108+
"@angular-eslint/template/prefer-ngsrc": "off", // TODO: experiment with ngsrc and see if we need to use it or not
109+
"@angular-eslint/template/eqeqeq": [
110+
"error",
111+
{
112+
"allowNullOrUndefined": true
113+
}
114+
]
115+
}
69116
}
70117
]
71118
}

projects/fab-speed-dial/src/lib/fab-speed-dial.ts

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function getHostElement(button: MatMiniFabButton): any {
3434
@Component({
3535
selector: 'eco-fab-speed-dial-actions',
3636
template: `@if (miniFabVisible) {
37-
<ng-content select="[mat-mini-fab]"></ng-content>
37+
<ng-content select="[mat-mini-fab]" />
3838
}`,
3939
standalone: true,
4040
})
@@ -82,10 +82,6 @@ export class EcoFabSpeedDialActionsComponent implements AfterContentInit {
8282
}
8383

8484
public show(): void {
85-
if (!this._buttons) {
86-
return;
87-
}
88-
8985
this.resetAnimationState();
9086
this.miniFabVisible = true;
9187

@@ -118,10 +114,6 @@ export class EcoFabSpeedDialActionsComponent implements AfterContentInit {
118114
}
119115

120116
public hide(): void {
121-
if (!this._buttons) {
122-
return;
123-
}
124-
125117
this.resetAnimationState();
126118

127119
const obs = this._buttons.map((button, i) => {
@@ -170,11 +162,12 @@ export class EcoFabSpeedDialActionsComponent implements AfterContentInit {
170162
selector: 'eco-fab-speed-dial',
171163
template: `
172164
<div class="eco-fab-speed-dial-container">
173-
<ng-content select="eco-fab-speed-dial-trigger"></ng-content>
174-
<ng-content select="eco-fab-speed-dial-actions"></ng-content>
165+
<ng-content select="eco-fab-speed-dial-trigger" />
166+
<ng-content select="eco-fab-speed-dial-actions" />
175167
</div>
176168
`,
177-
styleUrls: ['fab-speed-dial.scss'],
169+
styleUrls: ['./fab-speed-dial.scss'],
170+
// eslint-disable-next-line @angular-eslint/use-component-view-encapsulation
178171
encapsulation: ViewEncapsulation.None,
179172
standalone: true,
180173
})
@@ -298,10 +291,6 @@ export class EcoFabSpeedDialComponent implements OnDestroy, AfterContentInit {
298291
}
299292

300293
public setActionsVisibility(): void {
301-
if (!this._childActions) {
302-
return;
303-
}
304-
305294
if (this.open) {
306295
this._childActions.show();
307296
} else {
@@ -345,7 +334,7 @@ export class EcoFabSpeedDialComponent implements OnDestroy, AfterContentInit {
345334

346335
@Component({
347336
selector: 'eco-fab-speed-dial-trigger',
348-
template: ` <ng-content select="[mat-fab]"></ng-content>`,
337+
template: ` <ng-content select="[mat-fab]" />`,
349338
standalone: true,
350339
})
351340
export class EcoFabSpeedDialTriggerComponent {

src/app/app.component.html

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,19 +50,19 @@
5050
<eco-fab-speed-dial [(open)]="open" [direction]="direction" [animationMode]="animationMode" [fixed]="fixed">
5151
<eco-fab-speed-dial-trigger [spin]="spin">
5252
<button mat-fab (click)="doAction('trigger')">
53-
<mat-icon class="spin180" fontIcon="add"></mat-icon>
53+
<mat-icon class="spin180" fontIcon="add" />
5454
</button>
5555
</eco-fab-speed-dial-trigger>
5656

5757
<eco-fab-speed-dial-actions>
5858
<button mat-mini-fab (click)="doAction('action1')">
59-
<mat-icon fontIcon="search"></mat-icon>
59+
<mat-icon fontIcon="search" />
6060
</button>
6161
<button mat-mini-fab (click)="doAction('action2')">
62-
<mat-icon fontIcon="edit"></mat-icon>
62+
<mat-icon fontIcon="edit" />
6363
</button>
6464
<button mat-mini-fab (click)="doAction('action3')">
65-
<mat-icon fontIcon="home"></mat-icon>
65+
<mat-icon fontIcon="home" />
6666
</button>
6767
</eco-fab-speed-dial-actions>
6868
</eco-fab-speed-dial>
@@ -85,19 +85,19 @@
8585
>
8686
<eco-fab-speed-dial-trigger [spin]="spin">
8787
<button mat-fab (click)="doAction('trigger')">
88-
<mat-icon class="spin360" fontIcon="check"></mat-icon>
88+
<mat-icon class="spin360" fontIcon="check" />
8989
</button>
9090
</eco-fab-speed-dial-trigger>
9191

9292
<eco-fab-speed-dial-actions>
9393
<button mat-mini-fab (click)="doAction('action1')">
94-
<mat-icon fontIcon="add"></mat-icon>
94+
<mat-icon fontIcon="add" />
9595
</button>
9696
<button mat-mini-fab (click)="doAction('action2')">
97-
<mat-icon fontIcon="edit"></mat-icon>
97+
<mat-icon fontIcon="edit" />
9898
</button>
9999
<button mat-mini-fab (click)="doAction('action3')">
100-
<mat-icon fontIcon="menu"></mat-icon>
100+
<mat-icon fontIcon="menu" />
101101
</button>
102102
</eco-fab-speed-dial-actions>
103103
</eco-fab-speed-dial>

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,6 @@
1010
<link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet" />
1111
</head>
1212
<body>
13-
<app-root></app-root>
13+
<app-root />
1414
</body>
1515
</html>

0 commit comments

Comments
 (0)