Skip to content

Commit

Permalink
fix(angular): fix @angular-eslint/* package updates to consider angul…
Browse files Browse the repository at this point in the history
…ar installed version (#17526)
  • Loading branch information
leosvelperez authored Jun 12, 2023
1 parent 0e88b12 commit e39ee11
Show file tree
Hide file tree
Showing 3 changed files with 172 additions and 3 deletions.
22 changes: 19 additions & 3 deletions packages/angular/migrations.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
Original file line number Diff line number Diff line change
@@ -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",
],
},
}
`);
});
});
Original file line number Diff line number Diff line change
@@ -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<void> {
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<string, unknown> }) {
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];
}
}
}

1 comment on commit e39ee11

@vercel
Copy link

@vercel vercel bot commented on e39ee11 Jun 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

nx-dev – ./

nx-dev-nrwl.vercel.app
nx-dev-git-master-nrwl.vercel.app
nx-five.vercel.app
nx.dev

Please sign in to comment.