Skip to content

Commit 055f662

Browse files
devversionandrewseguin
authored andcommitted
build: properly lint tooling source code (#6055)
* build: properly lint tooling source code * Fixes a glob that is responsible for IDE's TypeScript service and also for TSLint * Fixes strict null check errors in the screenshot app. Currently the app can't be compiled properly since strict null checks had been introduced there as well. * Address feedback
1 parent e79dc29 commit 055f662

File tree

11 files changed

+39
-35
lines changed

11 files changed

+39
-35
lines changed

tools/gulp/tasks/validate-release.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ task('validate-release:check-bundles', () => {
3939
function checkReleasePackage(packageName: string): string[] {
4040
const bundlePath = join(releasesDir, packageName, '@angular', `${packageName}.js`);
4141
const bundleContent = readFileSync(bundlePath, 'utf8');
42-
let failures = [];
42+
let failures: string[] = [];
4343

4444
if (inlineStylesSourcemapRegex.exec(bundleContent) !== null) {
4545
failures.push('Bundles contain sourcemap references in component styles.');
@@ -61,7 +61,7 @@ function checkMaterialPackage(): string[] {
6161
const packagePath = join(releasesDir, 'material');
6262
const prebuiltThemesPath = join(packagePath, 'prebuilt-themes');
6363
const themingFilePath = join(packagePath, '_theming.scss');
64-
const failures = [];
64+
const failures: string[] = [];
6565

6666
if (glob('*.css', {cwd: prebuiltThemesPath}).length === 0) {
6767
failures.push('Prebuilt themes are not present in the Material release output.');

tools/package-tools/build-bundles.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {join} from 'path';
2-
import {readdirSync, lstatSync} from 'fs';
32
import {ScriptTarget, ModuleKind, NewLineKind} from 'typescript';
43
import {uglifyJsFile} from './minify-sources';
54
import {createRollupBundle} from './rollup-helpers';

tools/package-tools/build-release.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ export function composeRelease(packageName: string, options: ComposeReleaseOptio
4848
}
4949

5050
/** Creates files necessary for a secondary entry-point. */
51-
function createFilesForSecondaryEntryPoint(packageName: string, packagePath: string, releasePath: string) {
51+
function createFilesForSecondaryEntryPoint(packageName: string, packagePath: string,
52+
releasePath: string) {
5253
getSecondaryEntryPointsForPackage(packageName).forEach(entryPointName => {
5354
// Create a directory in the root of the package for this entry point that contains
5455
// * A package.json that lists the different bundle locations

tools/package-tools/entry-point-package-json.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import {join} from 'path';
2-
import {lstatSync, readdirSync, writeFileSync} from 'fs';
2+
import {writeFileSync} from 'fs';
33

44
/** Creates a package.json for a secondary entry-point with the different bundle locations. */
5-
export function createEntryPointPackageJson(destDir: string, packageName: string, entryPointName: string) {
5+
export function createEntryPointPackageJson(destDir: string, packageName: string,
6+
entryPointName: string) {
67
const content = {
78
name: `@angular/${packageName}/${entryPointName}`,
89
typings: `../${entryPointName}.d.ts`,

tools/package-tools/gulp/build-tasks-gulp.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import {dest, src, task} from 'gulp';
22
import {join} from 'path';
3-
import {readFileSync, unlink, writeFileSync} from 'fs';
43
import {main as tsc} from '@angular/tsc-wrapped';
54
import {buildConfig} from '../build-config';
65
import {composeRelease} from '../build-release';
@@ -27,8 +26,11 @@ const htmlMinifierOptions = {
2726
* Creates a set of gulp tasks that can build the specified package.
2827
* @param packageName Name of the package. Needs to be similar to the directory name in `src/`.
2928
* @param dependencies Required packages that will be built before building the current package.
29+
* @param options Options that can be passed to adjust the gulp package tasks.
3030
*/
31-
export function createPackageBuildTasks(packageName: string, dependencies: string[] = [], options: PackageTaskOptions = {}) {
31+
export function createPackageBuildTasks(packageName: string, dependencies: string[] = [],
32+
options: PackageTaskOptions = {}) {
33+
3234
// To avoid refactoring of the project the package material will map to the source path `lib/`.
3335
const packageRoot = join(packagesDir, packageName === 'material' ? 'lib' : packageName);
3436
const packageOut = join(outputDir, 'packages', packageName);

tools/package-tools/secondary-entry-points.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
import {join} from 'path';
2-
import {readdirSync, lstatSync} from 'fs';
3-
import {buildConfig} from './build-config';
4-
5-
61
/**
72
* List of cdk entry-points in the order that they must be built. This is necessary because
83
* some of the entry-points depend on each other. This is temporary until we switch to bazel.

tools/screenshot-test/functions/github.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ const authDomain = firebaseFunctions.config().firebase.authDomain;
1414
const toolName = firebaseFunctions.config().tool.name;
1515

1616
export function updateGithubStatus(event: firebaseFunctions.Event<any>) {
17-
if (!event.data.exists() || typeof event.data.val() != 'boolean') {
17+
if (!event.data.exists() || typeof event.data.val() != 'boolean' && event.params) {
1818
return;
1919
}
20-
let result = event.data.val() == true;
21-
let {prNumber, sha} = event.params;
20+
21+
const result = event.data.val() == true;
22+
const {prNumber, sha} = event.params!;
23+
2224
return setGithubStatus(sha, {
2325
result: result,
2426
name: toolName,

tools/screenshot-test/functions/jwt-util.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ const secret = firebaseFunctions.config().secret.key;
1313
* Replace '/' with '.' to get the token.
1414
*/
1515
function getSecureToken(event: firebaseFunctions.Event<any>) {
16-
let {jwtHeader, jwtPayload, jwtSignature} = event.params;
16+
const {jwtHeader, jwtPayload, jwtSignature} = event.params!;
1717
return `${jwtHeader}.${jwtPayload}.${jwtSignature}`;
1818
}
1919

20+
2021
/**
2122
* Verify that the event has a valid JsonWebToken. If the token is *not* valid,
2223
* the data tied to the event will be deleted and the function will return a rejected promise.
2324
*/
2425
export function verifySecureToken(event: firebaseFunctions.Event<any>) {
2526
return new Promise((resolve, reject) => {
26-
const prNumber = event.params['prNumber'];
27+
const prNumber = event.params!['prNumber'];
2728
const secureToken = getSecureToken(event);
2829

2930
return verifyJWT(secureToken, prNumber, secret, repoSlug).then(() => {

tools/screenshot-test/functions/test-goldens.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,18 @@ const bucket = gcs.bucket(firebaseFunctions.config().firebase.storageBucket);
1515
export function copyTestImagesToGoldens(prNumber: string) {
1616
return firebaseAdmin.database().ref(`screenshot/reports/${prNumber}/results`).once('value')
1717
.then((snapshot: firebaseAdmin.database.DataSnapshot) => {
18-
let failedFilenames: string[] = [];
18+
const failedFilenames: string[] = [];
1919
let counter = 0;
20-
snapshot.forEach((childSnapshot: firebaseAdmin.database.DataSnapshot) => {
21-
if (childSnapshot.val() === false) {
20+
21+
snapshot.forEach(childSnapshot => {
22+
if (childSnapshot.key && childSnapshot.val() === false) {
2223
failedFilenames.push(childSnapshot.key);
2324
}
25+
2426
counter++;
25-
if (counter == snapshot.numChildren()) {
26-
return true;
27-
}
27+
return counter === snapshot.numChildren();
2828
});
29+
2930
return failedFilenames;
3031
}).then((failedFilenames: string[]) => {
3132
return bucket.getFiles({prefix: `screenshots/${prNumber}/test`}).then((data: any) => {

tools/screenshot-test/src/app/firebase.service.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,9 @@ export class FirebaseService {
7171
this._readResults(childSnapshot);
7272
break;
7373
}
74+
7475
counter++;
75-
if (counter === snapshot.numChildren()) {
76-
return true;
77-
}
76+
return counter === snapshot.numChildren();
7877
});
7978
});
8079
}
@@ -123,11 +122,11 @@ export class FirebaseService {
123122
this.screenshotResultSummary.testNames = [];
124123
this.screenshotResultSummary.testResultsByName.clear();
125124
childSnapshot.forEach((resultSnapshot: firebase.database.DataSnapshot) => {
126-
this._addTestResults(resultSnapshot.key, resultSnapshot.val());
127-
childCounter++;
128-
if (childCounter === childSnapshot.numChildren()) {
129-
return true;
125+
if (resultSnapshot.key) {
126+
this._addTestResults(resultSnapshot.key, resultSnapshot.val());
130127
}
128+
childCounter++;
129+
return childCounter === childSnapshot.numChildren();
131130
});
132131
}
133132

tsconfig.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
"baseUrl": ".",
1717
"paths": {
1818
"@angular/material": ["./src/lib/public_api.ts"],
19-
"@angular/cdk*": ["./src/cdk/*"],
20-
"@angular/material-examples": ["./src/material-examples"]
19+
"@angular/cdk/*": ["./src/cdk/*"],
20+
"@angular/material-examples": ["./src/material-examples"],
21+
"material2-build-tools": ["./tools/package-tools"]
2122
}
2223
},
2324
"include": [
2425
"src/**/*.ts",
25-
"tools/**.ts"
26+
"tools/**/*.ts"
2627
],
2728
"exclude": [
2829
// Exclude files that depend on Node APIs because those depend on the Node types and therefore
@@ -31,6 +32,8 @@
3132

3233
// IDEs should not type-check the different node_modules directories of the different packages.
3334
// This would cause the IDEs to be slower and also linters would check the node_modules.
34-
"**/node_modules"
35+
"node_modules/",
36+
"tools/dashboard/node_modules/",
37+
"tools/screenshot-test/node_modules/"
3538
]
3639
}

0 commit comments

Comments
 (0)