diff --git a/packages/angular/migrations.json b/packages/angular/migrations.json index 352326ef2573c..e883f096f1391 100644 --- a/packages/angular/migrations.json +++ b/packages/angular/migrations.json @@ -245,6 +245,15 @@ }, "description": "Switch the data persistence operator imports to '@ngrx/router-store/data-persistence'.", "factory": "./src/migrations/update-16-2-0/switch-data-persistence-operators-imports-to-ngrx-router-store" + }, + "rename-angular-eslint-accesibility-rules": { + "cli": "nx", + "version": "16.4.0-beta.6", + "requires": { + "@angular-eslint/eslint-plugin-template": ">=16.0.0" + }, + "description": "Remove the 'accessibility-' prefix from '@angular-eslint/eslint-plugin-template' rules.", + "factory": "./src/migrations/update-16-4-0/rename-angular-eslint-accesibility-rules" } }, "packageJsonUpdates": { @@ -464,7 +473,8 @@ "14.4.0": { "version": "14.4.0-beta.1", "requires": { - "eslint": "^7.0.0 || ^8.0.0" + "eslint": "^7.0.0 || ^8.0.0", + "@angular/core": ">=14.0.0 <15.0.0" }, "packages": { "@angular-eslint/eslint-plugin": { @@ -674,6 +684,10 @@ }, "14.8.0-angular-eslint": { "version": "14.8.0-beta.0", + "requires": { + "eslint": "^7.0.0 || ^8.0.0", + "@angular/core": ">=14.0.0 <15.0.0" + }, "packages": { "@angular-eslint/eslint-plugin": { "version": "~14.0.4", @@ -769,7 +783,8 @@ "15.2.2-angular-eslint": { "version": "15.2.2-beta.0", "requires": { - "eslint": "^7.20.0 || ^8.0.0" + "eslint": "^7.20.0 || ^8.0.0", + "@angular/core": ">=15.0.0 <16.0.0" }, "packages": { "@angular-eslint/eslint-plugin": { @@ -1099,7 +1114,8 @@ "16.1.0-angular-eslint": { "version": "16.1.0-beta.1", "requires": { - "eslint": "^7.20.0 || ^8.0.0" + "eslint": "^7.20.0 || ^8.0.0", + "@angular/core": ">=16.0.0 <17.0.0" }, "packages": { "@angular-eslint/eslint-plugin": { diff --git a/packages/angular/src/migrations/update-16-4-0/rename-angular-eslint-accesibility-rules.spec.ts b/packages/angular/src/migrations/update-16-4-0/rename-angular-eslint-accesibility-rules.spec.ts new file mode 100644 index 0000000000000..b21e8c076b9ee --- /dev/null +++ b/packages/angular/src/migrations/update-16-4-0/rename-angular-eslint-accesibility-rules.spec.ts @@ -0,0 +1,110 @@ +import { Tree, readJson } from '@nx/devkit'; +import { writeJson } from '@nx/devkit'; +import { createTreeWithEmptyWorkspace } from '@nx/devkit/testing'; +import migration from './rename-angular-eslint-accesibility-rules'; + +describe('rename-angular-eslint-accesibility-rules migration', () => { + let tree: Tree; + + beforeEach(() => { + tree = createTreeWithEmptyWorkspace(); + }); + + it('should rename relevant rules keeping their config and handling overrides', async () => { + writeJson(tree, '.eslintrc.json', { + rules: { + '@angular-eslint/component-class-suffix': [ + 'error', + { suffixes: ['Page', 'View'] }, + ], + '@angular-eslint/template/accessibility-alt-text': ['error'], + '@angular-eslint/template/no-call-expression': ['error'], + '@angular-eslint/template/accessibility-role-has-required-aria': [ + 'error', + ], + }, + overrides: [ + { + files: ['*.ts'], + rules: { + '@angular-eslint/component-class-suffix': [ + 'warn', + { suffixes: ['Page', 'View'] }, + ], + }, + }, + { + files: ['*.html'], + rules: { + '@angular-eslint/template/accessibility-alt-text': ['warn'], + '@angular-eslint/template/no-call-expression': ['warn'], + '@angular-eslint/template/accessibility-role-has-required-aria': [ + 'warn', + ], + }, + }, + ], + }); + + await migration(tree); + + expect(readJson(tree, '.eslintrc.json')).toMatchInlineSnapshot(` + { + "overrides": [ + { + "files": [ + "*.ts", + ], + "rules": { + "@angular-eslint/component-class-suffix": [ + "warn", + { + "suffixes": [ + "Page", + "View", + ], + }, + ], + }, + }, + { + "files": [ + "*.html", + ], + "rules": { + "@angular-eslint/template/alt-text": [ + "warn", + ], + "@angular-eslint/template/no-call-expression": [ + "warn", + ], + "@angular-eslint/template/role-has-required-aria": [ + "warn", + ], + }, + }, + ], + "rules": { + "@angular-eslint/component-class-suffix": [ + "error", + { + "suffixes": [ + "Page", + "View", + ], + }, + ], + "@angular-eslint/template/alt-text": [ + "error", + ], + "@angular-eslint/template/no-call-expression": [ + "error", + ], + "@angular-eslint/template/role-has-required-aria": [ + "error", + ], + }, + } + `); + }); +}); diff --git a/packages/angular/src/migrations/update-16-4-0/rename-angular-eslint-accesibility-rules.ts b/packages/angular/src/migrations/update-16-4-0/rename-angular-eslint-accesibility-rules.ts new file mode 100644 index 0000000000000..6d90083a1592f --- /dev/null +++ b/packages/angular/src/migrations/update-16-4-0/rename-angular-eslint-accesibility-rules.ts @@ -0,0 +1,43 @@ +import type { Tree } from '@nx/devkit'; +import { formatFiles, updateJson, visitNotIgnoredFiles } from '@nx/devkit'; + +// https://github.com/angular-eslint/angular-eslint/blob/24a4de54a8991c93924abf1dfb78b132a6269aef/packages/schematics/src/migrations/update-16-0-0/update-16-0-0.ts +export default async function (tree: Tree): Promise { + visitNotIgnoredFiles(tree, '.', (filePath) => { + if (!filePath.endsWith('.eslintrc.json')) { + return; + } + + updateJson(tree, filePath, (json) => { + if (json.overrides) { + for (const override of json.overrides) { + modifyRules(override); + } + } + + modifyRules(json); + return json; + }); + }); + + await formatFiles(tree); +} + +function modifyRules(parent: { rules?: Record }) { + if (!parent.rules) { + return; + } + + for (const rule of Object.keys(parent.rules)) { + if (rule.startsWith('@angular-eslint/template/accessibility-')) { + const ruleConfig = parent.rules[rule]; + parent.rules[ + rule.replace( + '@angular-eslint/template/accessibility-', + '@angular-eslint/template/' + ) + ] = ruleConfig; + delete parent.rules[rule]; + } + } +}