fix(core): migrate relative link resolution with single quotes (#39102)
This is a roll forward of #39082, using `ts.createIdentifier(`'legacy'`)` as a cross-version compatible way of making a single quoted string literal. Migrated code now uses single quotes, which is in line with the default linting options, so there is no lint error after migration. PR Close #39102
This commit is contained in:
parent
dace4aacb6
commit
049b453149
|
@ -45,7 +45,7 @@ export class RelativeLinkResolutionTransform {
|
||||||
return literal;
|
return literal;
|
||||||
}
|
}
|
||||||
const legacyExpression =
|
const legacyExpression =
|
||||||
ts.createPropertyAssignment(RELATIVE_LINK_RESOLUTION, ts.createStringLiteral('legacy'));
|
ts.createPropertyAssignment(RELATIVE_LINK_RESOLUTION, ts.createIdentifier(`'legacy'`));
|
||||||
return ts.updateObjectLiteral(literal, [...literal.properties, legacyExpression]);
|
return ts.updateObjectLiteral(literal, [...literal.properties, legacyExpression]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -85,7 +85,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {
|
||||||
|
|
||||||
runTSLint(true);
|
runTSLint(true);
|
||||||
expect(getFile('/index.ts'))
|
expect(getFile('/index.ts'))
|
||||||
.toContain(`RouterModule.forRoot([], { relativeLinkResolution: "legacy" })`);
|
.toContain(`RouterModule.forRoot([], { relativeLinkResolution: 'legacy' })`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should migrate options without relativeLinkResolution', () => {
|
it('should migrate options without relativeLinkResolution', () => {
|
||||||
|
@ -103,7 +103,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {
|
||||||
|
|
||||||
runTSLint(true);
|
runTSLint(true);
|
||||||
expect(getFile('/index.ts'))
|
expect(getFile('/index.ts'))
|
||||||
.toContain(`RouterModule.forRoot([], { useHash: true, relativeLinkResolution: "legacy" })`);
|
.toContain(`RouterModule.forRoot([], { useHash: true, relativeLinkResolution: 'legacy' })`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not migrate options containing relativeLinkResolution', () => {
|
it('should not migrate options containing relativeLinkResolution', () => {
|
||||||
|
@ -133,7 +133,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {
|
||||||
runTSLint(true);
|
runTSLint(true);
|
||||||
expect(getFile('/index.ts'))
|
expect(getFile('/index.ts'))
|
||||||
.toContain(
|
.toContain(
|
||||||
`const options = { useHash: true, relativeLinkResolution: "legacy" } as ExtraOptions;`);
|
`const options = { useHash: true, relativeLinkResolution: 'legacy' } as ExtraOptions;`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should migrate when options is a variable', () => {
|
it('should migrate when options is a variable', () => {
|
||||||
|
@ -145,7 +145,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {
|
||||||
runTSLint(true);
|
runTSLint(true);
|
||||||
expect(getFile('/index.ts'))
|
expect(getFile('/index.ts'))
|
||||||
.toContain(
|
.toContain(
|
||||||
`const options: ExtraOptions = { useHash: true, relativeLinkResolution: "legacy" };`);
|
`const options: ExtraOptions = { useHash: true, relativeLinkResolution: 'legacy' };`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should migrate when options is a variable with no type', () => {
|
it('should migrate when options is a variable with no type', () => {
|
||||||
|
@ -166,7 +166,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {
|
||||||
|
|
||||||
runTSLint(true);
|
runTSLint(true);
|
||||||
expect(getFile('/index.ts'))
|
expect(getFile('/index.ts'))
|
||||||
.toContain(`const options = { useHash: true, relativeLinkResolution: "legacy" };`);
|
.toContain(`const options = { useHash: true, relativeLinkResolution: 'legacy' };`);
|
||||||
expect(getFile('/index.ts')).toContain(`RouterModule.forRoot([], options)`);
|
expect(getFile('/index.ts')).toContain(`RouterModule.forRoot([], options)`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -179,7 +179,7 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {
|
||||||
runTSLint(true);
|
runTSLint(true);
|
||||||
expect(getFile('/index.ts'))
|
expect(getFile('/index.ts'))
|
||||||
.toContain(
|
.toContain(
|
||||||
`const options: RouterExtraOptions = { useHash: true, relativeLinkResolution: "legacy" };`);
|
`const options: RouterExtraOptions = { useHash: true, relativeLinkResolution: 'legacy' };`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should migrate aliased RouterModule.forRoot', () => {
|
it('should migrate aliased RouterModule.forRoot', () => {
|
||||||
|
@ -197,6 +197,6 @@ describe('Google3 relativeLinkResolution TSLint rule', () => {
|
||||||
|
|
||||||
runTSLint(true);
|
runTSLint(true);
|
||||||
expect(getFile('/index.ts'))
|
expect(getFile('/index.ts'))
|
||||||
.toContain(`AngularRouterModule.forRoot([], { relativeLinkResolution: "legacy" }),`);
|
.toContain(`AngularRouterModule.forRoot([], { relativeLinkResolution: 'legacy' }),`);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -61,7 +61,7 @@ describe('initial navigation migration', () => {
|
||||||
|
|
||||||
await runMigration();
|
await runMigration();
|
||||||
expect(tree.readContent('/index.ts'))
|
expect(tree.readContent('/index.ts'))
|
||||||
.toContain(`RouterModule.forRoot([], { relativeLinkResolution: "legacy" })`);
|
.toContain(`RouterModule.forRoot([], { relativeLinkResolution: 'legacy' })`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should migrate options without relativeLinkResolution', async () => {
|
it('should migrate options without relativeLinkResolution', async () => {
|
||||||
|
@ -79,7 +79,7 @@ describe('initial navigation migration', () => {
|
||||||
|
|
||||||
await runMigration();
|
await runMigration();
|
||||||
expect(tree.readContent('/index.ts'))
|
expect(tree.readContent('/index.ts'))
|
||||||
.toContain(`RouterModule.forRoot([], { useHash: true, relativeLinkResolution: "legacy" })`);
|
.toContain(`RouterModule.forRoot([], { useHash: true, relativeLinkResolution: 'legacy' })`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not migrate options containing relativeLinkResolution', async () => {
|
it('should not migrate options containing relativeLinkResolution', async () => {
|
||||||
|
@ -109,7 +109,7 @@ describe('initial navigation migration', () => {
|
||||||
await runMigration();
|
await runMigration();
|
||||||
expect(tree.readContent('/index.ts'))
|
expect(tree.readContent('/index.ts'))
|
||||||
.toContain(
|
.toContain(
|
||||||
`const options = { useHash: true, relativeLinkResolution: "legacy" } as ExtraOptions;`);
|
`const options = { useHash: true, relativeLinkResolution: 'legacy' } as ExtraOptions;`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should migrate when options is a variable', async () => {
|
it('should migrate when options is a variable', async () => {
|
||||||
|
@ -121,7 +121,7 @@ describe('initial navigation migration', () => {
|
||||||
await runMigration();
|
await runMigration();
|
||||||
expect(tree.readContent('/index.ts'))
|
expect(tree.readContent('/index.ts'))
|
||||||
.toContain(
|
.toContain(
|
||||||
`const options: ExtraOptions = { useHash: true, relativeLinkResolution: "legacy" };`);
|
`const options: ExtraOptions = { useHash: true, relativeLinkResolution: 'legacy' };`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should migrate when options is a variable with no type', async () => {
|
it('should migrate when options is a variable with no type', async () => {
|
||||||
|
@ -142,7 +142,7 @@ describe('initial navigation migration', () => {
|
||||||
|
|
||||||
await runMigration();
|
await runMigration();
|
||||||
expect(tree.readContent('/index.ts'))
|
expect(tree.readContent('/index.ts'))
|
||||||
.toContain(`const options = { useHash: true, relativeLinkResolution: "legacy" };`);
|
.toContain(`const options = { useHash: true, relativeLinkResolution: 'legacy' };`);
|
||||||
expect(tree.readContent('/index.ts')).toContain(`RouterModule.forRoot([], options)`);
|
expect(tree.readContent('/index.ts')).toContain(`RouterModule.forRoot([], options)`);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -155,7 +155,7 @@ describe('initial navigation migration', () => {
|
||||||
await runMigration();
|
await runMigration();
|
||||||
expect(tree.readContent('/index.ts'))
|
expect(tree.readContent('/index.ts'))
|
||||||
.toContain(
|
.toContain(
|
||||||
`const options: RouterExtraOptions = { useHash: true, relativeLinkResolution: "legacy" };`);
|
`const options: RouterExtraOptions = { useHash: true, relativeLinkResolution: 'legacy' };`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should migrate aliased RouterModule.forRoot', async () => {
|
it('should migrate aliased RouterModule.forRoot', async () => {
|
||||||
|
@ -173,7 +173,7 @@ describe('initial navigation migration', () => {
|
||||||
|
|
||||||
await runMigration();
|
await runMigration();
|
||||||
expect(tree.readContent('/index.ts'))
|
expect(tree.readContent('/index.ts'))
|
||||||
.toContain(`AngularRouterModule.forRoot([], { relativeLinkResolution: "legacy" }),`);
|
.toContain(`AngularRouterModule.forRoot([], { relativeLinkResolution: 'legacy' }),`);
|
||||||
});
|
});
|
||||||
|
|
||||||
function writeFile(filePath: string, contents: string) {
|
function writeFile(filePath: string, contents: string) {
|
||||||
|
|
Loading…
Reference in New Issue