Skip to content

Commit 17e1683

Browse files
committed
build: additional fixes for tsetse rule compliance
Due to bazel rules_nodejs caching, several additional `JSON.parse` usages were not caught in the first set of fixes. These have now been addressed. Also, the `must-use-promises` rule has been patched to match the behavior of the `@typescript-eslint/no-floating-promises` for consistency. The bazel option `suppressTsconfigOverrideWarnings` was also removed from the `tsconfig` as it is a no-op and was previously used for now removed feature. Test files are currently excluded from the `JSON.parse` rule to avoid large changes to test code.
1 parent 7c5b365 commit 17e1683

File tree

18 files changed

+46
-24
lines changed

18 files changed

+46
-24
lines changed

.yarn/patches/@bazel-concatjs-npm-5.8.1-1bf81df846.patch

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,18 @@ index b01c999f5e02b388f51a508b0b608cf69db9b664..847c23fe4829d0c847e9b4bd1ad698e1
5252
}
5353

5454
# "node_modules" still checked for backward compat for ng_module
55+
diff --git a/internal/tsetse/rules/must_use_promises_rule.js b/internal/tsetse/rules/must_use_promises_rule.js
56+
index e404d01cf80ab4da4b9cca89005b14a60b7d8c79..85488d9a339982af4495d2b5f4c30effb98a538b 100755
57+
--- a/internal/tsetse/rules/must_use_promises_rule.js
58+
+++ b/internal/tsetse/rules/must_use_promises_rule.js
59+
@@ -30,6 +30,10 @@ function checkCallExpression(checker, node) {
60+
if (tsutils.isExpressionValueUsed(node) || !inAsyncFunction(node)) {
61+
return;
62+
}
63+
+ // Sync behavior with @typescript-eslint/no-floating-promises
64+
+ if (node.parent && ts.isVoidExpression(node.parent)) {
65+
+ return;
66+
+ }
67+
if (tsutils.isThenableType(checker.typeChecker, node)) {
68+
checker.addFailureAtNode(node, FAILURE_STRING);
69+
}

packages/angular/build/src/utils/index-file/inline-fonts.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class InlineFontsProcessor {
9797
}
9898
});
9999

100-
initCollectorStream().catch(() => {
100+
void initCollectorStream().catch(() => {
101101
// We don't really care about any errors here because it just initializes
102102
// the rewriting stream, as we are waiting for `finish` below.
103103
});

packages/angular_devkit/architect/node/node-modules-architect-host.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ function clone(obj: unknown): unknown {
2828
try {
2929
return deserialize(serialize(obj));
3030
} catch {
31-
return JSON.parse(JSON.stringify(obj));
31+
return JSON.parse(JSON.stringify(obj)) as unknown;
3232
}
3333
}
3434

packages/angular_devkit/architect/src/jobs/simple-scheduler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export class SimpleScheduler<
147147

148148
const description: JobDescription = {
149149
// Make a copy of it to be sure it's proper JSON.
150-
...JSON.parse(JSON.stringify(handler.jobDescription)),
150+
...(JSON.parse(JSON.stringify(handler.jobDescription)) as JobDescription),
151151
name: handler.jobDescription.name || name,
152152
argument: handler.jobDescription.argument || true,
153153
input: handler.jobDescription.input || true,

packages/angular_devkit/build_angular/src/builders/jest/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ async function findCustomJestConfig(dir: string): Promise<string | undefined> {
204204
return undefined; // No package.json, therefore no Jest configuration in it.
205205
}
206206

207-
const json = JSON.parse(packageJson);
207+
const json = JSON.parse(packageJson) as { jest?: unknown };
208208
if ('jest' in json) {
209209
return packageJsonPath;
210210
}

packages/angular_devkit/build_angular/src/tools/webpack/plugins/javascript-optimizer-worker.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import remapping from '@ampproject/remapping';
9+
import remapping, { SourceMapInput } from '@ampproject/remapping';
1010
import type { BuildFailure, TransformResult } from 'esbuild';
1111
import { minify } from 'terser';
1212
import { EsbuildExecutor } from './esbuild-executor';
@@ -79,7 +79,7 @@ interface OptimizeRequest {
7979
* The source map of the JavaScript asset, if available.
8080
* This map is merged with all intermediate source maps during optimization.
8181
*/
82-
map: object;
82+
map: SourceMapInput;
8383
};
8484
}
8585

@@ -118,11 +118,11 @@ export default async function ({ asset, options }: OptimizeRequest) {
118118
const partialSourcemaps = [];
119119

120120
if (esbuildResult.map) {
121-
partialSourcemaps.unshift(JSON.parse(esbuildResult.map));
121+
partialSourcemaps.unshift(JSON.parse(esbuildResult.map) as SourceMapInput);
122122
}
123123

124124
if (terserResult.map) {
125-
partialSourcemaps.unshift(terserResult.map);
125+
partialSourcemaps.unshift(terserResult.map as SourceMapInput);
126126
}
127127

128128
if (asset.map) {

packages/ngtools/webpack/src/ivy/loader.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ export function angularWebpackLoader(this: LoaderContext<unknown>, content: stri
5858
let resultMap;
5959
if (result.map) {
6060
resultContent = resultContent.replace(/^\/\/# sourceMappingURL=[^\r\n]*/gm, '');
61-
resultMap = JSON.parse(result.map);
61+
resultMap = JSON.parse(result.map) as Exclude<
62+
Parameters<typeof callback>[2],
63+
string | undefined
64+
>;
6265
resultMap.sources = resultMap.sources.map((source: string) =>
6366
path.join(path.dirname(this.resourcePath), source),
6467
);

tests/legacy-cli/e2e/tests/basic/command-scope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default async function () {
99
// The version command can be run in and outside of a workspace.
1010
await silentNg('version');
1111

12-
assert.rejects(
12+
await assert.rejects(
1313
silentNg('new', 'proj-name', '--dry-run'),
1414
/This command is not available when running the Angular CLI inside a workspace\./,
1515
);
@@ -18,7 +18,7 @@ export default async function () {
1818
process.chdir(homedir());
1919

2020
// ng generate can only be ran inside.
21-
assert.rejects(
21+
await assert.rejects(
2222
silentNg('generate', 'component', 'foo', '--dry-run'),
2323
/This command is not available when running the Angular CLI outside a workspace\./,
2424
);

tests/legacy-cli/e2e/tests/basic/e2e.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { setTimeout } from 'node:timers/promises';
33
import { silentNg } from '../../utils/process';
44

55
export default async function () {
6-
assert.rejects(silentNg('e2e', 'test-project', '--dev-server-target='));
6+
await assert.rejects(silentNg('e2e', 'test-project', '--dev-server-target='));
77

88
// These should work.
99
await silentNg('e2e', 'test-project');

tests/legacy-cli/e2e/tests/commands/add/version-specifier.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default async function () {
1212
// `ng add` command itself and not the behavior of npm which may otherwise fail depending
1313
// on the npm version in use and the version specifier supplied in each test.
1414
if (getActivePackageManager() === 'npm') {
15-
appendFile('.npmrc', '\nforce=true\n');
15+
await appendFile('.npmrc', '\nforce=true\n');
1616
}
1717

1818
const tag = (await isPrereleaseCli()) ? '@next' : '';

0 commit comments

Comments
 (0)