Skip to content

Commit 2be70ec

Browse files
committed
build: enable --strict for tools typescript code
1 parent db8320a commit 2be70ec

16 files changed

+60
-43
lines changed

tools/dgeni/processors/entry-point-grouper.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,22 @@ export class EntryPointDoc {
2424
docType = 'entry-point';
2525

2626
/** Name of the component group. */
27-
name: string;
27+
name: string = '';
2828

2929
/** Display name of the entry-point. */
30-
displayName: string;
30+
displayName: string = '';
3131

3232
/** Module import path for the entry-point. */
33-
moduleImportPath: string;
33+
moduleImportPath: string = '';
3434

3535
/** Name of the package, either material or cdk */
36-
packageName: string;
36+
packageName: string = '';
3737

3838
/** Display name of the package. */
39-
packageDisplayName: string;
39+
packageDisplayName: string = '';
4040

4141
/** Unique id for the entry-point. */
42-
id: string;
42+
id: string = '';
4343

4444
/** Known aliases for the entry-point. This is only needed for the `computeIdsProcessor`. */
4545
aliases: string[] = [];

tools/example-module/generate-example-module.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ function analyzeExamples(sourceFiles: string[], baseDir: string): AnalyzedExampl
116116
title: primaryComponent.title.trim(),
117117
additionalComponents: [],
118118
files: [],
119-
module: null,
119+
// The `module` field will be set in a separate step below. We need to set
120+
// it here as we are setting it later in a side-effect iteration.
121+
module: null!,
120122
};
121123

122124
// For consistency, we expect the example component selector to match

tools/example-module/parse-example-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ interface ParsedMetadata {
1010
}
1111

1212
interface ParsedMetadataResults {
13-
primaryComponent: ParsedMetadata;
13+
primaryComponent: ParsedMetadata | undefined;
1414
secondaryComponents: ParsedMetadata[];
1515
}
1616

tools/sass/compiler-main.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
import * as worker from '@bazel/worker';
22
import * as fs from 'fs';
3-
import * as sass from 'sass';
43
import * as path from 'path';
54
import yargs from 'yargs';
65

76
import {createLocalAngularPackageImporter} from './local-sass-importer';
87

8+
// TODO: Switch to normal import when https://github.com/sass/dart-sass/issues/1714 is fixed.
9+
// Also re-add the `as XX` type narrowing below.
10+
const sass = require('sass') as any;
11+
912
const workerArgs = process.argv.slice(2);
1013

1114
// Note: This path is relative to the current working directory as build actions
@@ -61,7 +64,7 @@ async function processBuildAction(args: string[]) {
6164
.parseAsync();
6265

6366
const result = sass.compile(inputExecpath, {
64-
style: style as sass.OutputStyle,
67+
style: style, // TODO: Re-add: as sass.OutputStyle,
6568
sourceMap,
6669
sourceMapIncludeSources: embedSources,
6770
loadPaths: loadPath,

tools/sass/local-sass-importer.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import {pathToFileURL} from 'url';
22
import {join} from 'path';
3-
import * as sass from 'sass';
3+
4+
// TODO: Add explicit type for `Sass.FileImporter` once
5+
// https://github.com/sass/dart-sass/issues/1714 is fixed.
46

57
/** Prefix indicating Angular-owned Sass imports. */
68
const angularPrefix = '@angular/';
@@ -9,7 +11,7 @@ const angularPrefix = '@angular/';
911
* Creates a Sass `FileImporter` that resolves `@angular/<..>` packages to the
1012
* specified local packages directory.
1113
*/
12-
export function createLocalAngularPackageImporter(packageDirAbsPath: string): sass.FileImporter {
14+
export function createLocalAngularPackageImporter(packageDirAbsPath: string) {
1315
return {
1416
findFileUrl: (url: string) => {
1517
if (url.startsWith(angularPrefix)) {

tools/stylelint/cross-package-import-validation.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@ import {dirname, relative, join} from 'path';
33

44
const ruleName = 'material/cross-package-import-validation';
55
const messages = utils.ruleMessages(ruleName, {
6-
forbidden: (targetPackage: string, importPath: string) =>
6+
forbidden: (targetPackage, importPath) =>
77
`Relative reference to separate NPM package "${targetPackage}" is not allowed. ` +
88
`Use a module specifier instead of "${importPath}".`,
9-
noDeepCrossPackageModuleImport: (importSpecifier: string) =>
9+
noDeepCrossPackageModuleImport: importSpecifier =>
1010
`Deep cross-package module imports are not allowed ("${importSpecifier}").`,
1111
});
1212

@@ -21,7 +21,7 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean) => {
2121
return;
2222
}
2323

24-
const filePath = root.source.input.file;
24+
const filePath = root.source!.input.file!;
2525

2626
// We skip non-theme files and legacy theming Sass files (like `.import.scss`).
2727
if (
@@ -34,7 +34,7 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean) => {
3434

3535
root.walkAtRules(rule => {
3636
if (rule.name === 'use' || rule.name === 'import' || rule.name === 'forward') {
37-
const [_, specifier] = rule.params.match(specifierRegex);
37+
const [_, specifier] = rule.params.match(specifierRegex)!;
3838

3939
// Ensure no deep imports for cross-package `@angular/` imports.
4040
if (/@angular\/[^/]+\//.test(specifier)) {
@@ -52,13 +52,13 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean) => {
5252
return;
5353
}
5454

55-
const currentPath = convertToProjectRelativePosixPath(root.source.input.file);
55+
const currentPath = convertToProjectRelativePosixPath(root.source!.input.file!);
5656
const targetPath = convertToProjectRelativePosixPath(
57-
join(dirname(root.source.input.file), specifier),
57+
join(dirname(root.source!.input.file!), specifier),
5858
);
5959

60-
const owningFilePackage = currentPath.match(packageNameRegex)[1];
61-
const targetFilePackage = targetPath.match(packageNameRegex)[1];
60+
const owningFilePackage = currentPath.match(packageNameRegex)![1];
61+
const targetFilePackage = targetPath.match(packageNameRegex)![1];
6262

6363
if (owningFilePackage !== targetFilePackage) {
6464
utils.report({

tools/stylelint/no-ampersand-beyond-selector-start.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const messages = utils.ruleMessages(ruleName, {
1111

1212
/** Config options for the rule. */
1313
interface RuleOptions {
14-
filePattern: string;
14+
filePattern?: string;
1515
}
1616

1717
/**
@@ -27,16 +27,16 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, options: RuleOptions)
2727
return;
2828
}
2929

30-
const filePattern = new RegExp(options.filePattern);
31-
const fileName = basename(root.source.input.file);
30+
const filePattern = options.filePattern ? new RegExp(options.filePattern) : null;
31+
const fileName = basename(root.source!.input.file!);
3232

33-
if (!filePattern.test(fileName)) {
33+
if (filePattern !== null && !filePattern.test(fileName)) {
3434
return;
3535
}
3636

3737
root.walkRules(rule => {
3838
if (
39-
rule.parent.type === 'rule' &&
39+
rule.parent?.type === 'rule' &&
4040
isStandardSyntaxRule(rule) &&
4141
isStandardSyntaxSelector(rule.selector) &&
4242
hasInvalidAmpersandUsage(rule.selector)

tools/stylelint/no-concrete-rules.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import {basename} from 'path';
33

44
const ruleName = 'material/no-concrete-rules';
55
const messages = utils.ruleMessages(ruleName, {
6-
expected: pattern => `CSS rules must be placed inside a mixin for files matching '${pattern}'.`,
6+
expectedWithPattern: pattern =>
7+
`CSS rules must be placed inside a mixin for files matching '${pattern}'.`,
8+
expectedAllFiles: () => `CSS rules must be placed inside a mixin for all files.`,
79
});
810

911
/** Config options for the rule. */
1012
interface RuleOptions {
11-
filePattern: string;
13+
filePattern?: string;
1214
}
1315

1416
/**
@@ -21,10 +23,10 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, options: RuleOptions)
2123
return;
2224
}
2325

24-
const filePattern = new RegExp(options.filePattern);
25-
const fileName = basename(root.source.input.file);
26+
const filePattern = options.filePattern ? new RegExp(options.filePattern) : null;
27+
const fileName = basename(root.source!.input.file!);
2628

27-
if (!filePattern.test(fileName) || !root.nodes) {
29+
if ((filePattern !== null && !filePattern.test(fileName)) || !root.nodes) {
2830
return;
2931
}
3032

@@ -37,7 +39,10 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, options: RuleOptions)
3739
result,
3840
ruleName,
3941
node,
40-
message: messages.expected(filePattern),
42+
message:
43+
filePattern !== null
44+
? messages.expectedWithPattern(filePattern)
45+
: messages.expectedAllFiles(),
4146
});
4247
}
4348
});

tools/stylelint/no-import.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, options?: {exclude?:
1515

1616
const excludePattern = options?.exclude ? new RegExp(options.exclude) : null;
1717

18-
if (excludePattern?.test(basename(root.source.input.file))) {
18+
if (excludePattern?.test(basename(root.source!.input.file!))) {
1919
return;
2020
}
2121

tools/stylelint/no-prefixes/index.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {NeedsPrefix} from './needs-prefix';
55
const parseSelector = require('stylelint/lib/utils/parseSelector');
66
const ruleName = 'material/no-prefixes';
77
const messages = utils.ruleMessages(ruleName, {
8-
property: (property: string, browsers: string) => {
8+
property: (property, browsers) => {
99
return `Unprefixed property "${property}" needs a prefix for browsers ${browsers}.`;
1010
},
1111
value: (property, value) => `Unprefixed value in "${property}: ${value}".`,
@@ -16,16 +16,20 @@ const messages = utils.ruleMessages(ruleName, {
1616

1717
/** Config options for the rule. */
1818
interface Options {
19-
browsers: string[];
20-
filePattern: string;
19+
browsers?: string[];
20+
filePattern?: string;
2121
}
2222

2323
/**
2424
* Stylelint plugin that warns for unprefixed CSS.
2525
*/
2626
const plugin = createPlugin(ruleName, (isEnabled: boolean, {filePattern, browsers}: Options) => {
2727
return (root, result) => {
28-
if (!isEnabled || (filePattern && !minimatch(root.source.input.file, filePattern))) {
28+
if (
29+
!isEnabled ||
30+
!browsers ||
31+
(filePattern && !minimatch(root.source!.input.file!, filePattern))
32+
) {
2933
return;
3034
}
3135

tools/stylelint/no-top-level-ampersand-in-mixin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, _options?) => {
2424

2525
const options = _options as RuleOptions;
2626
const filePattern = new RegExp(options.filePattern);
27-
const fileName = basename(root.source.input.file);
27+
const fileName = basename(root.source!.input.file!);
2828

2929
if (!filePattern.test(fileName)) {
3030
return;

tools/stylelint/no-unused-import.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@ import {basename, join} from 'path';
33

44
const ruleName = 'material/no-unused-import';
55
const messages = utils.ruleMessages(ruleName, {
6-
expected: (namespace: string) => `Namespace ${namespace} is not being used.`,
7-
invalid: (rule: string) =>
6+
expected: namespace => `Namespace ${namespace} is not being used.`,
7+
invalid: rule =>
88
`Failed to extract namespace from ${rule}. material/no-unused-` +
99
`imports Stylelint rule likely needs to be updated.`,
1010
});

tools/stylelint/selector-no-deep.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean) => {
1919

2020
root.walkRules(rule => {
2121
if (
22-
rule.parent.type === 'rule' &&
22+
rule.parent?.type === 'rule' &&
2323
isStandardSyntaxRule(rule) &&
2424
isStandardSyntaxSelector(rule.selector) &&
2525
rule.selector.includes('/deep/')

tools/stylelint/single-line-comment-only.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const plugin = createPlugin(ruleName, (isEnabled: boolean, options?: {filePatter
1919

2020
const filePattern = options?.filePattern ? new RegExp(options.filePattern) : null;
2121

22-
if (filePattern && !filePattern?.test(basename(root.source.input.file))) {
22+
if (filePattern && !filePattern?.test(basename(root.source!.input.file!))) {
2323
return;
2424
}
2525

tools/stylelint/theme-mixin-api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const themeMixinRegex = /^(density|color|typography|theme)\((.*)\)$/;
2323
*/
2424
const plugin = createPlugin(ruleName, (isEnabled: boolean, _options, context) => {
2525
return (root, result) => {
26-
const componentName = getComponentNameFromPath(root.source.input.file);
26+
const componentName = getComponentNameFromPath(root.source!.input.file!);
2727

2828
if (!componentName || !isEnabled) {
2929
return;
@@ -234,7 +234,7 @@ function stripNewlinesAndIndentation(value: string): string {
234234
* The `<..>` character sequency is a placeholder that will allow for arbitrary
235235
* content.
236236
*/
237-
function anyPattern(pattern): RegExp {
237+
function anyPattern(pattern: string): RegExp {
238238
const regex = new RegExp(
239239
`^${sanitizeForRegularExpression(pattern).replace(/<\\.\\.>/g, '.*?')}$`,
240240
);

tools/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"outDir": "../dist/tools",
99
"target": "es2020",
1010
"module": "Node16",
11+
"strict": true,
1112
"esModuleInterop": true,
1213
"lib": ["es2020"],
1314
"skipLibCheck": true,

0 commit comments

Comments
 (0)