Skip to content

Commit a9f266b

Browse files
authored
Update to Angular 18 (#160)
Addresses #157 In addition to updating the dependency version, I'm fixing the following: - #150 - #153 ## Implementation Updated dependencies: - `@angular/core` to `18.2.13` (latest <19) - `@angular-eslint` packages to `18.4.3` (latest <19) - `@typescript-eslint/eslint-plugin` and `@typescript-eslint/parser` to `7.18.0` (latest <8) - After updating the version of `@typescript-eslint/parser`, I began getting the following test failure: ``` Error: Error while loading rule '@typescript-eslint/prefer-optional-chain': You have used a rule which requires parserServices to be generated. You must therefore provide a value for the "parserOptions.project" property for @typescript-eslint/parser. Parser: C:\dev\javascript-styleguide\node_modules\@typescript-eslint\parser\dist\index.js Occurred while linting C:\dev\javascript-styleguide\tests\typescript\index.ts ``` It turns out that `@typescript-eslint/prefer-optional-chain` now [does require type checking](https://typescript-eslint.io/rules/prefer-optional-chain), so I had to move it to the `requiring-type-checking.js` configuration. - `@typescript-eslint/eslint-plugin` version 6 [introduced significant changes](https://github.com/typescript-eslint/typescript-eslint/blob/9e8828b31fda6e0fa45e0397cd6cc4e1662ba356/packages/website/blog/2023-07-09-announcing-typescript-eslint-v6.md#user-facing-breaking-changes). In `requiring-type-checking.js`, I changed it from extending `@typescript-eslint/recommended-requiring-type-checking` to `@typescript-eslint/recommended-type-checked` and `@typescript-eslint/stylistic-type-checked`. Similarly, in `eslint-config-typescript/index.js`, I added `@typescript-eslint/stylistic` to the extended configs. Subsequently, the output of `npm run print-evaluated-rules:diff` showed over a dozen changes. I added overrides to minimize the scope of changes in this PR, and ultimately ended up with the following diff: - `@typescript-eslint/consistent-generic-constructors` is new ("error") -- Despite adding an override to turn this rule off, it remains on. This may be a bug in `@typescript-eslint`. I don't think we want to let this block us, so clients should either fix reported violations or use in-source suppressions. - `@typescript-eslint/lines-between-class-members` was `["error","always",{"exceptAfterSingleLine":true}]`, now is `["error","always",{"exceptAfterSingleLine":true,"exceptAfterOverload":true}]` -- This seems like a harmless difference. - `no-new-native-nonconstructor` is new ("off") -- Explicitly turning off this new rule that defaulted to "error". - `@typescript-eslint/no-duplicate-enum-values` is new ("off") -- Explicitly turning off this new rule that defaulted to "error". - `@typescript-eslint/no-unsafe-declaration-merging` is new ("off") -- Explicitly turning off this new rule that defaulted to "error". - `@typescript-eslint/no-duplicate-type-constituents` is new ("off") -- Explicitly turning off this new rule that defaulted to "error". - `@typescript-eslint/no-redundant-type-constituents` is new ("off") -- Explicitly turning off this new rule that defaulted to "error". - `@typescript-eslint/no-unsafe-enum-comparison` is new ("off") -- Explicitly turning off this new rule that defaulted to "error". - `@angular-eslint/runtime-localize` is new ("error") -- We specifically want this enabled. ### Testing - Ran `npm run print-evaluated-rules:diff` and handled differences as described above. - Ran `npm run print-available-rules` with these changes: - `@typescript-eslint/no-duplicate-imports` - removed from TS Extensions - `@typescript-eslint/class-methods-use-this` - added to TS Extensions - `@typescript-eslint/max-params` - added to TS Extensions - `@typescript-eslint/prefer-ts-expect-error` - moved from TS Recommended to Remaining TS Rules - `@typescript-eslint/prefer-optional-chain` - moved from TS Recommended to TS Recommended (Requiring Type Checks) - `@typescript-eslint/no-implicit-any-catch` - removed from Remaining TS Rules - `@typescript-eslint/no-parameter-properties` - removed from Remaining TS Rules - `@typescript-eslint/sort-type-union-intersection-members` - removed from Remaining TS Rules - `@typescript-eslint/no-empty-object-type` - added to Remaining TS Rules - `@typescript-eslint/no-unnecessary-parameter-property-assignment` - added to Remaining TS Rules - `@typescript-eslint/no-unsafe-function-type` - added to Remaining TS Rules - `@typescript-eslint/no-wrapper-object-types` - added to Remaining TS Rules - `@typescript-eslint/no-empty-object-type` - added to Remaining TS Rules - `@typescript-eslint/no-empty-object-type` - added to Remaining TS Rules - `@typescript-eslint/consistent-return` - added to TS Extensions (Requiring Type Checks) - `@typescript-eslint/only-throw-error` - added to TS Extensions (Requiring Type Checks) - `@typescript-eslint/prefer-destructuring` - added to TS Extensions (Requiring Type Checks) - `@typescript-eslint/prefer-promise-reject-errors` - added to TS Extensions (Requiring Type Checks) - `@typescript-eslint/no-array-delete` - added to TS Recommended (Requiring Type Checks) - `@typescript-eslint/no-confusing-void-expression` - moved from Remaining TS Rules (Requiring Type Checks) to TS Recommended (Requiring Type Checks) - `@typescript-eslint/no-duplicate-type-constituents` - moved from Remaining TS Rules (Requiring Type Checks) to TS Recommended (Requiring Type Checks) - `@typescript-eslint/no-redundant-type-constituents` - moved from Remaining TS Rules (Requiring Type Checks) to TS Recommended (Requiring Type Checks) - `@typescript-eslint/no-unnecessary-template-expression` - added to TS Recommended Requiring Type Checks - `@typescript-eslint/use-unknown-in-catch-callback-variable` - added to TS Recommended Requiring Type Checks - `@typescript-eslint/no-unnecessary-type-parameters` - added to Remaining TS Rules (Requiring Type Checks) - `@typescript-eslint/no-unsafe-unary-minus` - added to Remaining TS Rules (Requiring Type Checks) - `@typescript-eslint/no-useless-template-literals` - added to Remaining TS Rules (Requiring Type Checks) - `@typescript-eslint/prefer-find` - added to Remaining TS Rules (Requiring Type Checks) - `@angular-eslint/no-host-metadata-property` - moved from Angular Recommended to Remaining Angular - `@angular-eslint/runtime-localize` - added to Remaining Angular
1 parent a9e2959 commit a9f266b

11 files changed

+2224
-5531
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "major",
3+
"comment": "Update to Angular 18",
4+
"packageName": "@ni/eslint-config-angular",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"type": "patch",
3+
"comment": "Update version of @typescript-eslint/parser and @typescript-eslint/eslint-plugin",
4+
"packageName": "@ni/eslint-config-typescript",
5+
"email": "[email protected]",
6+
"dependentChangeType": "patch"
7+
}

package-lock.json

+2,163-5,511
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/eslint-config-angular/index.js

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ module.exports = {
1010
https://github.com/angular-eslint/angular-eslint/blob/main/packages/eslint-plugin/src/configs/recommended.json
1111
*/
1212

13+
'@angular-eslint/no-host-metadata-property': 'error',
14+
1315
/*
1416
'@angular-eslint/no-input-rename' rule notes:
1517
Disallow renaming directive inputs generally. Use an inline comment to disable the rule for exceptions where the
@@ -91,6 +93,8 @@ module.exports = {
9193

9294
'@angular-eslint/relative-url-prefix': 'error',
9395

96+
'@angular-eslint/runtime-localize': 'error',
97+
9498
/*
9599
Generally not expected in practice to sort NgModule metadata arrays. Projects may enable if desired.
96100
*/

packages/eslint-config-angular/package.json

+5-5
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232
"!/tools"
3333
],
3434
"peerDependencies": {
35-
"@angular-eslint/builder": "^17.5.2",
36-
"@angular-eslint/eslint-plugin": "^17.5.2",
37-
"@angular-eslint/eslint-plugin-template": "^17.5.2",
38-
"@angular-eslint/schematics": "^17.5.2",
39-
"@angular-eslint/template-parser": "^17.5.2",
35+
"@angular-eslint/builder": "^18.4.3",
36+
"@angular-eslint/eslint-plugin": "^18.4.3",
37+
"@angular-eslint/eslint-plugin-template": "^18.4.3",
38+
"@angular-eslint/schematics": "^18.4.3",
39+
"@angular-eslint/template-parser": "^18.4.3",
4040
"@ni/eslint-config-typescript": "^4.4.0"
4141
}
4242
}

packages/eslint-config-typescript/index.js

+11-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ module.exports = {
22
extends: [
33
'@ni/eslint-config-javascript',
44
'plugin:@typescript-eslint/recommended',
5+
'plugin:@typescript-eslint/stylistic',
56
'plugin:import/typescript',
67
'./lib/extensions'
78
],
@@ -29,8 +30,6 @@ module.exports = {
2930

3031
'@typescript-eslint/explicit-module-boundary-types': 'error',
3132

32-
'@typescript-eslint/no-explicit-any': 'error',
33-
3433
/*
3534
[strict-null-checks]
3635
With `stickNullChecks` disabled, non-null assertions are discouraged (this rule is configured as 'error')
@@ -40,6 +39,15 @@ module.exports = {
4039
*/
4140
'@typescript-eslint/no-non-null-assertion': 'error',
4241

42+
'valid-typeof': 'off',
43+
44+
/*
45+
Overrides to TypeScript stylistic rules:
46+
https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/stylistic.ts
47+
*/
48+
49+
'@typescript-eslint/consistent-generic-constructors': 'off',
50+
4351
/*
4452
Overrides to Typescript rules outside of the recommended configuration:
4553
*/
@@ -200,8 +208,6 @@ module.exports = {
200208

201209
'@typescript-eslint/prefer-literal-enum-member': 'error',
202210

203-
'@typescript-eslint/prefer-optional-chain': 'error',
204-
205211
'@typescript-eslint/prefer-ts-expect-error': 'error',
206212

207213
/*
@@ -218,6 +224,6 @@ module.exports = {
218224
*/
219225
'@typescript-eslint/typedef': 'off',
220226

221-
'@typescript-eslint/unified-signatures': 'error'
227+
'@typescript-eslint/unified-signatures': 'error',
222228
}
223229
};

packages/eslint-config-typescript/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
],
3434
"peerDependencies": {
3535
"@ni/eslint-config-javascript": "^4.3.0",
36-
"@typescript-eslint/parser": "^5.62.0",
37-
"@typescript-eslint/eslint-plugin": "^5.62.0"
36+
"@typescript-eslint/parser": "^7.18.0",
37+
"@typescript-eslint/eslint-plugin": "^7.18.0"
3838
}
3939
}

packages/eslint-config-typescript/requiring-type-checking.js

+18-6
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
module.exports = {
22
extends: [
3-
'plugin:@typescript-eslint/recommended-requiring-type-checking',
3+
'plugin:@typescript-eslint/recommended-type-checked',
4+
'plugin:@typescript-eslint/stylistic-type-checked',
45
'./lib/extensions-requiring-type-checking'
56
],
67
parser: '@typescript-eslint/parser',
78
rules: {
89
/*
910
Overrides to TypeScript recommended rules:
10-
https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/recommended-requiring-type-checking.ts
11+
https://github.com/typescript-eslint/typescript-eslint/tree/v7.18.0/packages/eslint-plugin/src/configs/recommended-type-checked.ts
1112
*/
1213

13-
/*
14-
Allow usage of String.prototype.match for regular expression matching.
15-
*/
16-
'@typescript-eslint/prefer-regexp-exec': 'off',
14+
'@typescript-eslint/no-duplicate-enum-values': 'off',
15+
'@typescript-eslint/no-duplicate-type-constituents': 'off',
16+
'@typescript-eslint/no-loss-of-precision': 'off',
17+
'@typescript-eslint/no-redundant-type-constituents': 'off',
18+
'@typescript-eslint/no-unsafe-declaration-merging': 'off',
19+
'@typescript-eslint/no-unsafe-enum-comparison': 'off',
1720

1821
/*
1922
This rule can be confusing if you're not familiar with JavaScript's rules for binding `this`,
@@ -48,6 +51,13 @@ module.exports = {
4851
*/
4952
'@typescript-eslint/unbound-method': ['error', { ignoreStatic: true }],
5053

54+
/*
55+
Overrides to TypeScript type-checked stylistic rules:
56+
https://github.com/typescript-eslint/typescript-eslint/blob/main/packages/eslint-plugin/src/configs/stylistic-type-checked.ts
57+
*/
58+
59+
'@typescript-eslint/prefer-regexp-exec': 'off',
60+
5161
/*
5262
Overrides to Typescript rules outside of the recommended configuration:
5363
*/
@@ -124,6 +134,8 @@ module.exports = {
124134
*/
125135
'@typescript-eslint/prefer-nullish-coalescing': 'off',
126136

137+
'@typescript-eslint/prefer-optional-chain': 'error',
138+
127139
'@typescript-eslint/prefer-readonly': 'error',
128140

129141
/*

packages/eslint-config-typescript/tools/print-available-rules.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
// eslint-plugin-import doesn't know how to resolve entry points in commonjs modules that are
2+
// declared using "export" rather than the old "main" syntax in package.json.
3+
// See https://github.com/typescript-eslint/typescript-eslint/issues/7565
4+
// and https://github.com/import-js/eslint-plugin-import/issues/2703
5+
// eslint-disable-next-line import/no-unresolved
16
const plugin = require('@typescript-eslint/eslint-plugin');
27

38
const isTrue = val => val !== undefined && val !== false;

tests/angular/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"@ni/eslint-config-angular": "*"
1111
},
1212
"dependencies": {
13-
"@angular/core": "^17.3.12"
13+
"@angular/core": "^18.2.13"
1414
},
1515
"devDependencies": {
1616
"@types/jasmine": "^5.1.4"

tests/print-evaluated-rules/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"print-evaluated-rules:no-audit": "node index.js --no-audit"
1111
},
1212
"peerDependencies": {
13-
"@angular-eslint/eslint-plugin": "^17.5.2",
13+
"@angular-eslint/eslint-plugin": "^18.4.3",
1414
"@ni/angular-test": "*",
1515
"@ni/eslint-config-angular": "*",
1616
"@ni/javascript-test": "*",

0 commit comments

Comments
 (0)