Skip to content

Commit 2adf629

Browse files
devversionandrewseguin
authored andcommitted
fix(ng-update): do not report form-field breaking change from v6 (#16161)
The misc rules currently run for every migration, but the one for the `shouldLabelFloat` was apparently using a wrong check that has been added back in the days when we pulled out the standalone migration tool into the material2 repository. While being at it, we are fixing that invalid check and limit the misc migration to the V6 upgrade target version. Fixes #16143
1 parent b261afa commit 2adf629

File tree

4 files changed

+36
-2
lines changed

4 files changed

+36
-2
lines changed

src/material/schematics/ng-update/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,17 @@ import {materialUpgradeData} from './upgrade-data';
1515
/** List of additional upgrade rules for Angular Material. */
1616
const upgradeRules = [
1717
// Misc check rules
18-
'check-class-inheritance-misc',
1918
'check-class-names-misc',
2019
'check-imports-misc',
2120
'check-property-names-misc',
2221
'check-template-misc',
2322
'update-angular-material-imports',
2423

24+
// Class inheritance misc V6. NOTE: when adding new
25+
// data to this rule, consider adding it to the generic
26+
// property-names upgrade data.
27+
['check-class-inheritance-misc', TargetVersion.V6],
28+
2529
// Ripple misc V7
2630
['ripple-speed-factor-assignment', TargetVersion.V7],
2731
['ripple-speed-factor-template', TargetVersion.V7],
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import {createTestCaseSetup} from '@angular/cdk/schematics/testing';
2+
import {migrationCollection} from '../index.spec';
3+
4+
describe('class inheritance misc checks', () => {
5+
6+
describe('v6 class which extends MatFormFieldControl', () => {
7+
8+
it('should report if class does not declare "shouldLabelFloat"', async () => {
9+
const {removeTempDir, runFixers} = await createTestCaseSetup('migration-v6',
10+
migrationCollection, [require.resolve('./class-inheritance_input.ts')]);
11+
12+
const {logOutput} = await runFixers();
13+
14+
expect(logOutput).toMatch(/Found class "WithoutLabelProp".*extends "MatFormFieldControl.*must define "shouldLabelFloat"/);
15+
expect(logOutput).not.toMatch(/Found class "WithLabelProp".*extends "MatFormFieldControl".*must define "shouldLabelFloat"/);
16+
17+
removeTempDir();
18+
});
19+
});
20+
});
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import {HostBinding} from '@angular/core';
2+
import {MatFormFieldControl} from '@angular/material/form-field';
3+
4+
class WithoutLabelProp extends MatFormFieldControl<any> {
5+
}
6+
7+
class WithLabelProp extends MatFormFieldControl<any> {
8+
@HostBinding('class.floating')
9+
get shouldLabelFloat() {return true;}
10+
}

src/material/schematics/ng-update/upgrade-rules/misc-checks/checkClassInheritanceMiscRule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export class Walker extends ProgramAwareRuleWalker {
3434
if (baseTypes.includes('MatFormFieldControl')) {
3535
const hasFloatLabelMember = node.members
3636
.filter(member => member.name)
37-
.find(member => member.name!.getText() === 'shouldFloatLabel');
37+
.find(member => member.name!.getText() === 'shouldLabelFloat');
3838

3939
if (!hasFloatLabelMember) {
4040
this.addFailureAtNode(node, `Found class "${bold(className)}" which extends ` +

0 commit comments

Comments
 (0)