Skip to content

Commit 17667b8

Browse files
authored
build: allow for some schematics code to be linted (#23006)
The linting setup was excluding all of the code under `schematics/test-cases`, however we only need to do it for the `_input` and `_expected_output` files. These changes allow the files to be linted and fixes some errors that went undetected.
1 parent ebd9a97 commit 17667b8

File tree

7 files changed

+47
-18
lines changed

7 files changed

+47
-18
lines changed

src/cdk/schematics/ng-update/test-cases/misc/module-resolution.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe('ng update typescript program module resolution', () => {
1010
'migration-v6', MIGRATION_PATH, []);
1111

1212
writeFile('/node_modules/some-other-module/package.json', `{}`);
13-
writeFile('/node_modules/some-other-module/styles.css', '')
13+
writeFile('/node_modules/some-other-module/styles.css', '');
1414

1515
// We add an import to a non-existent sub-path of `some-other-module/styles`. The TypeScript
1616
// module resolution logic could try various sub-paths. This previously resulted in an error

src/material/schematics/ng-update/test-cases/misc/class-inheritance.spec.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,12 @@ describe('class inheritance misc checks', () => {
1010

1111
const {logOutput} = await runFixers();
1212

13+
// tslint:disable:max-line-length
1314
expect(logOutput).toMatch(
1415
/Found class "WithoutLabelProp".*extends "MatFormFieldControl.*must define "shouldLabelFloat"/);
1516
expect(logOutput).not.toMatch(
1617
/Found class "WithLabelProp".*extends "MatFormFieldControl".*must define "shouldLabelFloat"/);
18+
// tslint:enable:max-line-length
1719
});
1820
});
1921
});

src/material/schematics/ng-update/test-cases/v12/misc/theming-api-v12.spec.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {UnitTestTree} from '@angular-devkit/schematics/testing';
22
import {createTestCaseSetup} from '@angular/cdk/schematics/testing';
3-
import {migrateFileContent} from '@angular/material/schematics/ng-update/migrations/theming-api-v12/migration';
3+
import {
4+
migrateFileContent
5+
} from '@angular/material/schematics/ng-update/migrations/theming-api-v12/migration';
46
import {join} from 'path';
57
import {MIGRATION_PATH} from '../../../../paths';
68

src/material/schematics/ng-update/test-cases/v9/misc/hammer-migration-v9.spec.ts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ describe('v9 HammerJS removal', () => {
2929
});
3030

3131
function appendContent(filePath: string, text: string) {
32-
writeFile(filePath, text + tree.readContent(filePath))
32+
writeFile(filePath, text + tree.readContent(filePath));
3333
}
3434

3535
function writeHammerTypes() {
@@ -38,6 +38,10 @@ describe('v9 HammerJS removal', () => {
3838
`);
3939
}
4040

41+
function getDependencyVersion(name: string): string | undefined {
42+
return (JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies[name];
43+
}
44+
4145
it('should not throw if project tsconfig does not have explicit root file names', async () => {
4246
// Generates a second project in the workspace. This is necessary to ensure that the
4347
// migration runs logic to determine the correct workspace project.
@@ -60,12 +64,11 @@ describe('v9 HammerJS removal', () => {
6064
it('should remove hammerjs from "package.json" file', async () => {
6165
addPackageToPackageJson(tree, 'hammerjs', '0.0.0');
6266

63-
expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs']).toBe('0.0.0');
67+
expect(getDependencyVersion('hammerjs')).toBe('0.0.0');
6468

6569
await runMigration();
6670

67-
expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs'])
68-
.toBe(undefined);
71+
expect(getDependencyVersion('hammerjs')).toBeUndefined();
6972

7073
// expect that there is a "node-package" install task. The task is
7174
// needed to update the lock file.
@@ -126,7 +129,10 @@ describe('v9 HammerJS removal', () => {
126129
it('should remove references to HammerModule', async () => {
127130
writeFile('/projects/cdk-testing/src/test.module.ts', dedent`
128131
import {NgModule} from '@angular/core';
129-
import {HAMMER_GESTURE_CONFIG, HammerModule} from '@angular/platform-browser'; // some comment
132+
import {
133+
HAMMER_GESTURE_CONFIG,
134+
HammerModule
135+
} from '@angular/platform-browser'; // some comment
130136
import {GestureConfig} from '@angular/material/core';
131137
132138
@NgModule({
@@ -161,7 +167,9 @@ describe('v9 HammerJS removal', () => {
161167
it('should remove references to gesture config if imports are aliased', async () => {
162168
writeFile('/projects/cdk-testing/src/test.module.ts', dedent`
163169
import {NgModule} from '@angular/core';
164-
import {HAMMER_GESTURE_CONFIG as configToken} from '@angular/platform-browser'; // some comment
170+
import {
171+
HAMMER_GESTURE_CONFIG as configToken
172+
} from '@angular/platform-browser'; // some comment
165173
import {GestureConfig as gestureConfig} from '@angular/material/core';
166174
167175
@NgModule({
@@ -279,6 +287,7 @@ describe('v9 HammerJS removal', () => {
279287
});
280288

281289
it('should remove import scripts in project index files if found', async () => {
290+
// tslint:disable:max-line-length
282291
writeFile('/projects/cdk-testing/src/index.html', dedent`
283292
<!doctype html>
284293
<html lang="en">
@@ -312,6 +321,7 @@ describe('v9 HammerJS removal', () => {
312321
</body>
313322
<script src="some-other-script.js"></script>
314323
</html>`);
324+
// tslint:enable:max-line-length
315325
});
316326
});
317327

@@ -661,6 +671,8 @@ describe('v9 HammerJS removal', () => {
661671

662672
expect(tree.readContent('/projects/cdk-testing/src/main.ts')).toContain(`import 'hammerjs';`);
663673
expect(tree.exists('/projects/cdk-testing/src/gesture-config.ts')).toBe(true);
674+
675+
// tslint:disable:max-line-length
664676
expect(tree.readContent('/projects/cdk-testing/src/app/app.module.ts')).toContain(dedent`\
665677
import { NgModule } from '@angular/core';
666678
import { BrowserModule, HAMMER_GESTURE_CONFIG, HammerModule } from '@angular/platform-browser';
@@ -680,6 +692,7 @@ describe('v9 HammerJS removal', () => {
680692
bootstrap: [AppComponent]
681693
})
682694
export class AppModule { }`);
695+
// tslint:enable:max-line-length
683696
});
684697

685698
it('should add gesture config provider to app module if module is referenced through ' +
@@ -710,6 +723,8 @@ describe('v9 HammerJS removal', () => {
710723

711724
expect(tree.readContent('/projects/cdk-testing/src/main.ts')).toContain(`import 'hammerjs';`);
712725
expect(tree.exists('/projects/cdk-testing/src/gesture-config.ts')).toBe(true);
726+
727+
// tslint:disable:max-line-length
713728
expect(tree.readContent('/projects/cdk-testing/src/app/app.module.ts')).toContain(dedent`\
714729
import { NgModule } from '@angular/core';
715730
import { BrowserModule, HAMMER_GESTURE_CONFIG, HammerModule } from '@angular/platform-browser';
@@ -729,6 +744,7 @@ describe('v9 HammerJS removal', () => {
729744
bootstrap: [AppComponent]
730745
})
731746
export class AppModule { }`);
747+
// tslint:enable:max-line-length
732748
});
733749

734750
it('should not add gesture config provider multiple times if already provided', async () => {
@@ -792,6 +808,7 @@ describe('v9 HammerJS removal', () => {
792808

793809
expect(tree.readContent('/projects/cdk-testing/src/main.ts')).toContain(`import 'hammerjs';`);
794810
expect(tree.exists('/projects/cdk-testing/src/gesture-config.ts')).toBe(true);
811+
// tslint:disable:max-line-length
795812
expect(tree.readContent('/projects/cdk-testing/src/app/app.module.ts')).toContain(dedent`
796813
import { HammerModule as myHammerModule, HAMMER_GESTURE_CONFIG } from '@angular/platform-browser';
797814
import {NgModule} from '@angular/core';
@@ -802,13 +819,14 @@ describe('v9 HammerJS removal', () => {
802819
providers: [{ provide: HAMMER_GESTURE_CONFIG, useClass: GestureConfig }],
803820
})
804821
export class AppModule {}`);
822+
// tslint:enable:max-line-length
805823
});
806824
});
807825

808826
it('should not remove hammerjs if test target compilation scope does not contain hammerjs usage',
809827
async () => {
810828
addPackageToPackageJson(tree, 'hammerjs', '0.0.0');
811-
expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs']).toBe('0.0.0');
829+
expect(getDependencyVersion('hammerjs')).toBe('0.0.0');
812830

813831
// we simulate a case where a component does not have any tests for. In that case,
814832
// the test target compilation scope does not include "test.component.ts" and the
@@ -825,14 +843,14 @@ describe('v9 HammerJS removal', () => {
825843

826844
await runMigration();
827845

828-
expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs']).toBe('0.0.0');
846+
expect(getDependencyVersion('hammerjs')).toBe('0.0.0');
829847
});
830848

831849
it('should not remove hammerjs from "package.json" file if used in one project while ' +
832850
'unused in other project', async () => {
833851
addPackageToPackageJson(tree, 'hammerjs', '0.0.0');
834852

835-
expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs']).toBe('0.0.0');
853+
expect(getDependencyVersion('hammerjs')).toBe('0.0.0');
836854

837855
await runner.runExternalSchematicAsync('@schematics/angular', 'application',
838856
{name: 'second-project'}, tree).toPromise();
@@ -845,8 +863,7 @@ describe('v9 HammerJS removal', () => {
845863
await runMigration();
846864

847865
expect(runner.tasks.some(t => t.name === 'node-package')).toBe(false);
848-
expect((JSON.parse(tree.readContent('/package.json')) as PackageJson).dependencies['hammerjs'])
849-
.toBe('0.0.0');
866+
expect(getDependencyVersion('hammerjs')).toBe('0.0.0');
850867
});
851868

852869
describe('with custom gesture config', () => {

src/material/schematics/ng-update/test-cases/v9/misc/material-imports.spec.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
import {createTestCaseSetup, readFileContent, resolveBazelPath} from '@angular/cdk/schematics/testing';
1+
import {
2+
createTestCaseSetup,
3+
readFileContent,
4+
resolveBazelPath,
5+
} from '@angular/cdk/schematics/testing';
26
import {MIGRATION_PATH} from '../../../../paths';
37

48
describe('v9 material imports', () => {

tsconfig.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,9 @@
5959
// Exclude schematic template files and test cases which aren't valid TS files.
6060
"src/material/schematics/ng-generate/*/files/**/*",
6161
"src/cdk/schematics/ng-generate/*/files/**/*",
62-
"src/cdk/schematics/ng-update/test-cases/**/*",
63-
"src/material/schematics/ng-update/test-cases/**/*"
62+
"src/cdk/schematics/ng-update/test-cases/**/*_input.ts",
63+
"src/cdk/schematics/ng-update/test-cases/**/*_expected_output.ts",
64+
"src/material/schematics/ng-update/test-cases/**/*_input.ts",
65+
"src/material/schematics/ng-update/test-cases/**/*_expected_output.ts"
6466
]
6567
}

tslint.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,10 @@
224224
// Exclude schematic template files and test cases that can't be linted.
225225
"src/material/schematics/ng-generate/*/files/**/*",
226226
"src/cdk/schematics/ng-generate/*/files/**/*",
227-
"src/cdk/schematics/ng-update/test-cases/**/*",
228-
"src/material/schematics/ng-update/test-cases/**/*"
227+
"src/cdk/schematics/ng-update/test-cases/**/*_input.ts",
228+
"src/cdk/schematics/ng-update/test-cases/**/*_expected_output.ts",
229+
"src/material/schematics/ng-update/test-cases/**/*_input.ts",
230+
"src/material/schematics/ng-update/test-cases/**/*_expected_output.ts"
229231
]
230232
}
231233
}

0 commit comments

Comments
 (0)