Skip to content

Commit 8a0eff3

Browse files
committed
build: replace custom lint rule with compiler option
We currently have a lint rule that prevents dotted access in `SimpleChanges` objects, because it will break with property minification. These changes replace the rule with the built-in `noPropertyAccessFromIndexSignature` compiler option which has the same effect with the added benefit of aligning us closer with g3 and reducing the amount of code we need to maintain.
1 parent fbc7bdd commit 8a0eff3

28 files changed

+48
-120
lines changed

integration/mdc-migration/verify-golden.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const TEST_DIRECTORY = CURRENT_WORKING_DIRECTORY;
1717
const GOLDEN_DIRECTORY = path.join(CURRENT_WORKING_DIRECTORY, process.argv[3]);
1818
const IGNORED_FILES = new Set(process.argv.slice(5));
1919

20-
if (SHOULD_APPROVE && !process.env.BUILD_WORKSPACE_DIRECTORY) {
20+
if (SHOULD_APPROVE && !process.env['BUILD_WORKSPACE_DIRECTORY']) {
2121
console.error('Approval command must be run with `bazel run`.');
2222
process.exit(1);
2323
}
@@ -197,7 +197,7 @@ async function deleteFiles(file: string, ignoredFiles: Set<string>) {
197197
if (diffs.length) {
198198
if (SHOULD_APPROVE) {
199199
const APPROVED_GOLDEN_DIRECTORY = path.join(
200-
process.env.BUILD_WORKSPACE_DIRECTORY!,
200+
process.env['BUILD_WORKSPACE_DIRECTORY']!,
201201
process.argv[4],
202202
);
203203
await deleteFiles(

integration/size-test/check-size.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ if (deviatedByPercentage) {
7777
/** Prints the command for approving the current test. */
7878
function printApproveCommand() {
7979
console.info(chalk.yellow('You can approve the golden by running the following command:'));
80-
console.info(chalk.yellow(` bazel run ${process.env.BAZEL_TARGET}.approve`));
80+
console.info(chalk.yellow(` bazel run ${process.env['BAZEL_TARGET']}.approve`));
8181
}
8282

8383
/** Gets the lexicographically sorted size-test golden. */

scripts/build-docs-content.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const distDir = join(projectDir, 'dist/');
2121
const outputDir = join(distDir, 'docs-content-pkg');
2222

2323
/** Command that runs Bazel. */
24-
const bazelCmd = process.env.BAZEL || `yarn -s bazel`;
24+
const bazelCmd = process.env['BAZEL'] || `yarn -s bazel`;
2525

2626
/**
2727
* Builds the docs content NPM package in snapshot mode.

scripts/build-packages-dist.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const releaseTargetTag = 'release-package';
2020
const projectDir = join(dirname(fileURLToPath(import.meta.url)), '../');
2121

2222
/** Command that runs Bazel. */
23-
const bazelCmd = process.env.BAZEL || `yarn -s bazel`;
23+
const bazelCmd = process.env['BAZEL'] || `yarn -s bazel`;
2424

2525
/** Command that queries Bazel for all release package targets. */
2626
const queryPackagesCmd =

scripts/caretaking/resync-caretaker-app-prs.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Octokit} from '@octokit/rest';
22
import * as fetch from 'node-fetch';
33

44
const apiBaseUrl = 'https://test-jperrott.firebaseio.com/pulls';
5-
const github = new Octokit({auth: process.env.TOKEN});
5+
const github = new Octokit({auth: process.env['TOKEN']});
66

77
async function resync() {
88
const pulls: any[] = [];

scripts/circleci/notify-slack-job-failure.mts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
import sh from 'shelljs';
99
import {isVersionBranch, getConfig, assertValidGithubConfig} from '@angular/ng-dev';
1010

11-
if (process.env.CIRCLE_PR_NUMBER !== undefined) {
11+
if (process.env['CIRCLE_PR_NUMBER'] !== undefined) {
1212
console.info('Skipping notifications for pull requests.');
1313
process.exit(0);
1414
}
1515

16-
const jobName = process.env.CIRCLE_JOB!;
17-
const branchName = process.env.CIRCLE_BRANCH!;
18-
const jobUrl = process.env.CIRCLE_BUILD_URL!;
19-
const webhookUrl = process.env.SLACK_COMPONENTS_CI_FAILURES_WEBHOOK_URL!;
16+
const jobName = process.env['CIRCLE_JOB']!;
17+
const branchName = process.env['CIRCLE_BRANCH']!;
18+
const jobUrl = process.env['CIRCLE_BUILD_URL']!;
19+
const webhookUrl = process.env['SLACK_COMPONENTS_CI_FAILURES_WEBHOOK_URL']!;
2020

2121
const {github} = await getConfig([assertValidGithubConfig]);
2222
const isPublishBranch = isVersionBranch(branchName) || branchName === github.mainBranchName;

scripts/docs-deploy/deploy-ci-push.mts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,19 @@ import {getReleaseRepoWithApi} from './github-versioning.mjs';
1313
import {updateVersionsFile} from './update-versions-file.mjs';
1414

1515
async function main() {
16-
if (process.env.CIRCLE_PR_NUMBER !== undefined) {
16+
if (process.env['CIRCLE_PR_NUMBER'] !== undefined) {
1717
console.log('Skipping deployment for pull request build.');
1818
return;
1919
}
2020

21-
const branchName = process.env.CIRCLE_BRANCH;
21+
const branchName = process.env['CIRCLE_BRANCH'];
2222
if (branchName === undefined) {
2323
throw new Error('Deployment script is unable to determine CI branch.');
2424
}
2525

2626
const repo = await getReleaseRepoWithApi();
2727
const active = await ActiveReleaseTrains.fetch(repo);
28-
const description = `${branchName} - ${process.env.CIRCLE_SHA1!}`;
28+
const description = `${branchName} - ${process.env['CIRCLE_SHA1']!}`;
2929
const {projectId, serviceKey} = firebaseConfig;
3030

3131
if (branchName === active.next.branchName) {

scripts/docs-deploy/deploy-to-site.mts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export async function deployToSite(
4545
// Setup GCP service key for the docs-app deployment.
4646
// https://firebase.google.com/docs/admin/setup.
4747
await fs.promises.writeFile(gcpServiceKeyTmpFile, firebaseServiceKey);
48-
process.env.GOOGLE_APPLICATION_CREDENTIALS = gcpServiceKeyTmpFile;
48+
process.env['GOOGLE_APPLICATION_CREDENTIALS'] = gcpServiceKeyTmpFile;
4949

5050
await firebase('use', info.projectId);
5151
await firebase('target:clear', 'hosting', 'mat-aio');

scripts/docs-deploy/utils.mts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ export const projectDir = path.join(path.dirname(fileURLToPath(import.meta.url))
1111

1212
/** Interface describing a site target for the docs-app. */
1313
export class SiteTarget {
14-
constructor(public firebaseSiteId: string, public remoteUrl: string) {}
14+
constructor(
15+
public firebaseSiteId: string,
16+
public remoteUrl: string,
17+
) {}
1518
}
1619

1720
/** Object capturing all site targets for the docs-app. */
@@ -25,12 +28,12 @@ export const sites = {
2528
};
2629

2730
/** Optional Github access token. Can be used for querying the active release trains. */
28-
export const githubAccessToken: string | undefined = process.env.DOCS_DEPLOY_GITHUB_TOKEN;
31+
export const githubAccessToken: string | undefined = process.env['DOCS_DEPLOY_GITHUB_TOKEN'];
2932

3033
/** Configuration describing the Firebase project that we deploy to. */
3134
export const firebaseConfig = {
3235
projectId: 'material-angular-io',
33-
serviceKey: process.env.DOCS_SITE_GCP_SERVICE_KEY!,
36+
serviceKey: process.env['DOCS_SITE_GCP_SERVICE_KEY']!,
3437
};
3538

3639
/** Finds and parsed the `package.json` of the specified project directory. */

src/bazel-tsconfig-build.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"noUnusedParameters": false,
1111
"noUnusedLocals": false,
1212
"strictNullChecks": true,
13+
"noPropertyAccessFromIndexSignature": true,
1314
"noImplicitReturns": true,
1415
"strictFunctionTypes": true,
1516
"noImplicitOverride": true,

src/cdk/schematics/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"outDir": "../../../dist/packages/cdk/schematics",
88
"noEmitOnError": false,
99
"strictNullChecks": true,
10+
"noPropertyAccessFromIndexSignature": true,
1011
"useUnknownInCatchVariables": true,
1112
"noImplicitOverride": true,
1213
"noImplicitReturns": true,

src/cdk/schematics/utils/build-component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ import {getDefaultComponentOptions, isStandaloneSchematic} from './schematic-opt
4343
function buildDefaultPath(project: workspaces.ProjectDefinition): string {
4444
const root = project.sourceRoot ? `/${project.sourceRoot}/` : `/${project.root}/src/`;
4545

46-
const projectDirName = project.extensions.projectType === ProjectType.Application ? 'app' : 'lib';
46+
const projectDirName =
47+
project.extensions['projectType'] === ProjectType.Application ? 'app' : 'lib';
4748

4849
return `${root}${projectDirName}`;
4950
}

src/cdk/schematics/utils/html-manipulation.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export function addBodyClass(host: Tree, htmlFilePath: string, className: string
7272
if (!hasClass) {
7373
// We have source code location info enabled, and we pre-checked that the element
7474
// has attributes, specifically the `class` attribute.
75-
const classAttributeLocation = body.sourceCodeLocation!.attrs!.class;
75+
const classAttributeLocation = body.sourceCodeLocation!.attrs!['class'];
7676
const recordedChange = host
7777
.beginUpdate(htmlFilePath)
7878
.insertRight(classAttributeLocation.endOffset - 1, ` ${className}`);

src/cdk/schematics/utils/project-index-file.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import {defaultTargetBuilders, getTargetsByBuilderName} from './project-targets'
1212
/** Gets the path of the index file in the given project. */
1313
export function getProjectIndexFiles(project: workspaces.ProjectDefinition): Path[] {
1414
const paths = getTargetsByBuilderName(project, defaultTargetBuilders.build)
15-
.filter(t => t.options?.index)
16-
.map(t => t.options!.index as Path);
15+
.filter(t => t.options?.['index'])
16+
.map(t => t.options!['index'] as Path);
1717

1818
// Use a set to remove duplicate index files referenced in multiple build targets of a project.
1919
return Array.from(new Set(paths));

src/cdk/schematics/utils/project-main-file.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {getProjectTargetOptions} from './project-targets';
1313
/** Looks for the main TypeScript file in the given project and returns its path. */
1414
export function getProjectMainFile(project: workspaces.ProjectDefinition): Path {
1515
const buildOptions = getProjectTargetOptions(project, 'build');
16-
const mainPath = buildOptions.browser as Path | undefined;
16+
const mainPath = buildOptions['browser'] as Path | undefined;
1717

1818
if (!mainPath) {
1919
throw new SchematicsException(

src/cdk/schematics/utils/project-style-file.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ export function getProjectStyleFile(
2424
extension?: string,
2525
): string | null {
2626
const buildOptions = getProjectTargetOptions(project, 'build');
27-
if (buildOptions.styles && isJsonArray(buildOptions.styles) && buildOptions.styles.length) {
28-
const styles = buildOptions.styles.map(s =>
29-
typeof s === 'string' ? s : (s as {input: string}).input,
30-
);
27+
const buildStyles = buildOptions['styles'];
28+
29+
if (buildStyles && isJsonArray(buildStyles) && buildStyles.length) {
30+
const styles = buildStyles.map(s => (typeof s === 'string' ? s : (s as {input: string}).input));
3131

3232
// Look for the default style file that is generated for new projects by the Angular CLI. This
3333
// default style file is usually called `styles.ext` unless it has been changed explicitly.

src/cdk/schematics/utils/project-tsconfig-paths.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function getTargetTsconfigPath(
1919
project: workspaces.ProjectDefinition,
2020
targetName: string,
2121
): WorkspacePath | null {
22-
const tsconfig = project.targets?.get(targetName)?.options?.tsConfig;
22+
const tsconfig = project.targets?.get(targetName)?.options?.['tsConfig'];
2323
return tsconfig ? normalize(tsconfig as string) : null;
2424
}
2525

src/cdk/schematics/utils/schematic-options.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ function getDefaultComponentOption<T>(
7171
optionNames: string[],
7272
fallbackValue: T,
7373
): T {
74-
const schematicOptions = isJsonObject(project.extensions.schematics || null)
75-
? (project.extensions.schematics as JsonObject)
74+
const schematicOptions = isJsonObject(project.extensions['schematics'] || null)
75+
? (project.extensions['schematics'] as JsonObject)
7676
: null;
7777
const defaultSchematic = schematicOptions
7878
? (schematicOptions['@schematics/angular:component'] as JsonObject | null)

src/cdk/testing/tests/webdriver.e2e.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ describe('WebDriverHarnessEnvironment', () => {
5757

5858
beforeAll(async () => {
5959
wd = await new webdriver.Builder()
60-
.usingServer(process.env.WEB_TEST_WEBDRIVER_SERVER!)
60+
.usingServer(process.env['WEB_TEST_WEBDRIVER_SERVER']!)
6161
.withCapabilities(webTestMetadata.capabilities)
6262
.build();
6363
});

src/material/schematics/ng-add/index.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('ng-add schematic', () => {
4141

4242
/** Expects the given file to be in the styles of the specified workspace project. */
4343
function expectProjectStyleFile(project: workspaces.ProjectDefinition, filePath: string) {
44-
expect(getProjectTargetOptions(project, 'build').styles)
44+
expect(getProjectTargetOptions(project, 'build')['styles'])
4545
.withContext(`Expected "${filePath}" to be added to the project styles in the workspace.`)
4646
.toContain(filePath);
4747
}
@@ -436,7 +436,7 @@ describe('ng-add schematic', () => {
436436
const tree = await runner.runSchematic('ng-add-setup-project', baseOptions, appTree);
437437
const workspace = await getWorkspace(tree);
438438
const project = getProjectFromWorkspace(workspace, baseOptions.project);
439-
const styles = getProjectTargetOptions(project, 'build').styles;
439+
const styles = getProjectTargetOptions(project, 'build')['styles'];
440440

441441
expect(styles)
442442
.not.withContext('Expected the existing prebuilt theme file to be removed.')
@@ -452,7 +452,7 @@ describe('ng-add schematic', () => {
452452
const tree = await runner.runSchematic('ng-add-setup-project', baseOptions, appTree);
453453
const workspace = await getWorkspace(tree);
454454
const project = getProjectFromWorkspace(workspace, baseOptions.project);
455-
const styles = getProjectTargetOptions(project, 'build').styles;
455+
const styles = getProjectTargetOptions(project, 'build')['styles'];
456456

457457
expect(styles)
458458
.not.withContext('Expected the default prebuilt theme to be not configured.')
@@ -467,7 +467,7 @@ describe('ng-add schematic', () => {
467467
const tree = await runner.runSchematic('ng-add-setup-project', baseOptions, appTree);
468468
const workspace = await getWorkspace(tree);
469469
const project = getProjectFromWorkspace(workspace, baseOptions.project);
470-
const styles = getProjectTargetOptions(project, 'build').styles;
470+
const styles = getProjectTargetOptions(project, 'build')['styles'];
471471

472472
expect(styles)
473473
.withContext(

src/material/schematics/ng-add/setup-project.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export default function (options: Schema): Rule {
3838
const workspace = await getWorkspace(host);
3939
const project = getProjectFromWorkspace(workspace, options.project);
4040

41-
if (project.extensions.projectType === ProjectType.Application) {
41+
if (project.extensions['projectType'] === ProjectType.Application) {
4242
return chain([
4343
addAnimationsModule(options),
4444
addThemeToAppStyles(options),

src/material/schematics/ng-add/theming/theming.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,10 +132,10 @@ function addThemeStyleToTarget(
132132
}
133133

134134
const targetOptions = getProjectTargetOptions(project, targetName);
135-
const styles = targetOptions.styles as (string | {input: string})[];
135+
const styles = targetOptions['styles'] as (string | {input: string})[];
136136

137137
if (!styles) {
138-
targetOptions.styles = [assetPath];
138+
targetOptions['styles'] = [assetPath];
139139
} else {
140140
const existingStyles = styles.map(s => (typeof s === 'string' ? s : s.input));
141141

src/material/schematics/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"outDir": "../../../dist/packages/material/schematics",
77
"noEmitOnError": false,
88
"strictNullChecks": true,
9+
"noPropertyAccessFromIndexSignature": true,
910
"useUnknownInCatchVariables": true,
1011
"noImplicitOverride": true,
1112
"noImplicitAny": true,

src/universal-app/prerender.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ const themeCssPath = runfiles.resolvePackageRelative('./theme.css');
1818
const result = renderModule(KitchenSinkRootServerModule, {
1919
document: readFileSync(indexHtmlPath, 'utf-8'),
2020
});
21-
const outDir = process.env.TEST_UNDECLARED_OUTPUTS_DIR as string;
21+
const outDir = process.env['TEST_UNDECLARED_OUTPUTS_DIR'] as string;
2222

2323
result
2424
.then(content => {

tools/dgeni/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"moduleResolution": "node",
77
"esModuleInterop": true,
88
"strictNullChecks": true,
9+
"noPropertyAccessFromIndexSignature": true,
910
"useUnknownInCatchVariables": true,
1011
"noImplicitReturns": true,
1112
"strictFunctionTypes": true,

tools/tslint-rules/ngOnChangesPropertyAccessRule.ts

Lines changed: 0 additions & 80 deletions
This file was deleted.

0 commit comments

Comments
 (0)