-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(angular): fix @angular-eslint/* package updates to consider angul…
…ar installed version (#17526)
- Loading branch information
1 parent
0e88b12
commit e39ee11
Showing
3 changed files
with
172 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
110 changes: 110 additions & 0 deletions
110
...ges/angular/src/migrations/update-16-4-0/rename-angular-eslint-accesibility-rules.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
], | ||
}, | ||
} | ||
`); | ||
}); | ||
}); |
43 changes: 43 additions & 0 deletions
43
packages/angular/src/migrations/update-16-4-0/rename-angular-eslint-accesibility-rules.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]; | ||
} | ||
} | ||
} |
e39ee11
There was a problem hiding this comment.
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