Skip to content

Commit bb2bd81

Browse files
authored
Update to Angular 20 (#189)
Only rule changes are as follows: - `@angular-eslint/component-class-suffix` removed (was `error`) - `@angular-eslint/directive-class-suffix` removed (was `error`) We also have a new recommended rule that we are disabling: - `@angular-eslint/prefer-inject` Apparently, using the `inject()` function is recommended over injection as constructor arguments. Angular even provides an automatic migration (`ng generate @angular/core:inject`), but it's not smart. It just puts new fields immediately before the constructor, but they need to be declared/initialized before any other field initializers that depend on them. For automation purposes (and probably as general convention), that means we want them declared at the top of the class. `@typescript-eslint/member-ordering` doesn't have an automated fix-up, nor the ability to take initializers into acount. The [Perfectionist](https://perfectionist.dev/) [`sort-classes`](https://perfectionist.dev/rules/sort-classes#accessors) rule has both of those, so I optimistically tried using that instead. We can configure their rule to enforce (and automate the sorting of) fields initialized with `inject(...` coming before all other fields. But I wasn't able to prevent it from auto-sorting getter/setter pairs with different access modifiers apart from each other (which is also a violation). Aside from this it's unclear how painful it would be to update unit test code that might be constructing these objects directly. Based on all this, I'm disabling the rule.
1 parent e9c9420 commit bb2bd81

9 files changed

Lines changed: 8808 additions & 13506 deletions

File tree

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "Update to Angular 20",
4+
"packageName": "@ni/eslint-config-angular",
5+
"email": "7282195+m-akinc@users.noreply.github.com",
6+
"dependentChangeType": "patch"
7+
}

package-lock.json

Lines changed: 8768 additions & 13482 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/eslint-config-angular/index.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,15 @@ export const angularTypescriptConfig = defineConfig([
1616
https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/src/configs/recommended.json
1717
*/
1818

19+
'@angular-eslint/component-class-suffix': 'error',
20+
/*
21+
Enabling this would require replacing DI constuctor parameters with fields initialized with `inject()`.
22+
The new fields would have to be declared early/first in the class (other initializers may be relying on them),
23+
and doing so may violate @typescript-eslint/member-ordering. Additionally, it likely requires effort to
24+
update existing unit tests.
25+
See: https://github.com/ni/javascript-styleguide/issues/190
26+
*/
27+
'@angular-eslint/prefer-inject': 'off',
1928
'@angular-eslint/prefer-standalone': 'off',
2029

2130
/*

packages/eslint-config-angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
"!/eslint.config.js"
3838
],
3939
"peerDependencies": {
40-
"angular-eslint": "^19.8.1",
40+
"angular-eslint": "^20.7.0",
4141
"@ni/eslint-config-typescript": "^5.0.5",
4242
"@ni/eslint-config-javascript": "^5.1.4"
4343
}

tests/angular/angular.json

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
2+
"$schema": "../../node_modules/@angular/cli/lib/config/schema.json",
33
"version": 1,
44
"newProjectRoot": "projects",
55
"projects": {
@@ -10,7 +10,7 @@
1010
"prefix": "app",
1111
"architect": {
1212
"build": {
13-
"builder": "@angular-devkit/build-angular:application",
13+
"builder": "@angular/build:application",
1414
"options": {
1515
"outputPath": "dist/angular-test",
1616
"index": "src/index.html",
@@ -34,7 +34,7 @@
3434
"defaultConfiguration": "production"
3535
},
3636
"serve": {
37-
"builder": "@angular-devkit/build-angular:dev-server",
37+
"builder": "@angular/build:dev-server",
3838
"configurations": {
3939
"production": {
4040
"buildTarget": "angular-test:build:production"
@@ -46,10 +46,10 @@
4646
"defaultConfiguration": "development"
4747
},
4848
"extract-i18n": {
49-
"builder": "@angular-devkit/build-angular:extract-i18n"
49+
"builder": "@angular/build:extract-i18n"
5050
},
5151
"test": {
52-
"builder": "@angular-devkit/build-angular:karma",
52+
"builder": "@angular/build:karma",
5353
"options": {
5454
"browsers": "ChromeHeadlessNoSandbox",
5555
"polyfills": [
@@ -81,7 +81,7 @@
8181
"prefix": "angular-lib",
8282
"architect": {
8383
"build": {
84-
"builder": "@angular-devkit/build-angular:ng-packagr",
84+
"builder": "@angular/build:ng-packagr",
8585
"options": {
8686
"project": "projects/angular-library/ng-package.json"
8787
},
@@ -96,7 +96,7 @@
9696
"defaultConfiguration": "production"
9797
},
9898
"test": {
99-
"builder": "@angular-devkit/build-angular:karma",
99+
"builder": "@angular/build:karma",
100100
"options": {
101101
"browsers": "ChromeHeadlessNoSandbox",
102102
"polyfills": [

tests/angular/package.json

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,30 +11,30 @@
1111
},
1212
"private": true,
1313
"dependencies": {
14-
"@angular/animations": "^19.2.17",
15-
"@angular/common": "^19.2.17",
16-
"@angular/compiler": "^19.2.17",
17-
"@angular/core": "^19.2.17",
18-
"@angular/forms": "^19.2.17",
19-
"@angular/platform-browser": "^19.2.17",
20-
"@angular/platform-browser-dynamic": "^19.2.17",
14+
"@angular/animations": "^20.3.15",
15+
"@angular/common": "^20.3.15",
16+
"@angular/compiler": "^20.3.15",
17+
"@angular/core": "^20.3.15",
18+
"@angular/forms": "^20.3.15",
19+
"@angular/platform-browser": "^20.3.15",
20+
"@angular/platform-browser-dynamic": "^20.3.15",
2121
"rxjs": "~7.8.0",
2222
"tslib": "^2.3.0",
2323
"zone.js": "~0.15.1"
2424
},
2525
"devDependencies": {
26-
"@angular-devkit/build-angular": "^19.2.17",
27-
"@angular/cli": "^19.2.17",
28-
"@angular/compiler-cli": "^19.2.17",
29-
"@angular/localize": "^19.2.17",
26+
"@angular/build": "^20.3.15",
27+
"@angular/cli": "^20.3.15",
28+
"@angular/compiler-cli": "^20.3.15",
29+
"@angular/localize": "^20.3.15",
3030
"@types/jasmine": "~5.1.4",
3131
"jasmine-core": "~5.2.0",
3232
"karma": "~6.4.0",
3333
"karma-chrome-launcher": "~3.2.0",
3434
"karma-coverage": "~2.2.0",
3535
"karma-jasmine": "~5.1.0",
3636
"karma-jasmine-html-reporter": "~2.1.0",
37-
"ng-packagr": "^19.2.2",
37+
"ng-packagr": "^20.3.2",
3838
"typescript": "~5.8.3"
3939
},
4040
"peerDependencies": {

tests/angular/projects/angular-library/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"version": "0.0.0",
44
"private": true,
55
"peerDependencies": {
6-
"@angular/common": "^18.2.0",
7-
"@angular/core": "^18.2.0"
6+
"@angular/common": "^20.3.15",
7+
"@angular/core": "^20.3.15"
88
},
99
"dependencies": {
1010
"tslib": "^2.3.0"

tests/angular/projects/angular-library/src/lib/angular-library.component.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { Component, Input } from '@angular/core';
22

33
@Component({
4-
selector: 'angular-lib',
4+
selector: 'angular-lib-component',
55
standalone: true,
66
/* Angular In-line Template Smoke Test */
77
template: '<span i18n [(id)]="name" theme="non-localized-theme-id" title="This title should be localized." i18n-title>Hello {{name}}</span>!'

tests/print-evaluated-rules/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"print-evaluated-rules:no-audit": "node index.js --no-audit"
1212
},
1313
"peerDependencies": {
14-
"angular-eslint": "19.8.1",
14+
"angular-eslint": "^20.7.0",
1515
"@ni/angular-test": "*",
1616
"@ni/eslint-config-angular": "*",
1717
"@ni/eslint-config-javascript": "*",

0 commit comments

Comments
 (0)