Skip to content

Commit 610f3da

Browse files
committed
Address all unchecked indexed access within resources
1 parent aa43fec commit 610f3da

File tree

6 files changed

+30
-11
lines changed

6 files changed

+30
-11
lines changed

resources/benchmark.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,9 @@ function runBenchmark(
270270
benchmark: string,
271271
benchmarkProjects: ReadonlyArray<BenchmarkProject>,
272272
) {
273-
const results = [];
274-
for (let i = 0; i < benchmarkProjects.length; ++i) {
275-
const { revision, projectPath } = benchmarkProjects[i];
273+
const results: Array<BenchmarkComputedStats> = [];
274+
275+
benchmarkProjects.forEach(({ revision, projectPath }, i) => {
276276
const modulePath = path.join(projectPath, benchmark);
277277

278278
if (i === 0) {
@@ -288,7 +288,8 @@ function runBenchmark(
288288
} catch (error) {
289289
console.log(' ' + revision + ': ' + red(error.message));
290290
}
291-
}
291+
});
292+
292293
console.log('\n');
293294

294295
beautifyBenchmark(results);

resources/build-npm.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ function buildPackage(outDir: string, isESMOnly: boolean): void {
6969
const splittedTag = preReleaseTag.split('.');
7070
// Note: `experimental-*` take precedence over `alpha`, `beta` or `rc`.
7171
const versionTag = splittedTag[2] ?? splittedTag[0];
72+
assert(versionTag);
7273
assert(
7374
['alpha', 'beta', 'rc'].includes(versionTag) ||
7475
versionTag.startsWith('experimental-'),

resources/diff-npm-package.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ if (args.length < 2) {
2424
);
2525
}
2626

27+
assert(fromRevision);
28+
assert(toRevision);
29+
2730
console.log(`📦 Building NPM package for ${fromRevision}...`);
2831
const fromPackage = prepareNPMPackage(fromRevision);
2932

resources/gen-changelog.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import assert from 'node:assert';
2+
13
import { git, readPackageJSON } from './utils.js';
24

35
const packageJSON = readPackageJSON();
@@ -88,11 +90,13 @@ async function genChangeLog(): Promise<string> {
8890
}
8991

9092
const label = labels[0];
93+
assert(label);
9194
if (!labelsConfig[label]) {
9295
throw new Error(`Unknown label: ${label}. See ${pr.url}`);
9396
}
94-
byLabel[label] ??= [];
95-
byLabel[label].push(pr);
97+
const prByLabel = byLabel[label] ?? [];
98+
byLabel[label] = prByLabel;
99+
prByLabel.push(pr);
96100
committersByLogin[pr.author.login] = pr.author;
97101
}
98102

@@ -285,7 +289,11 @@ function commitInfoToPR(commit: CommitInfo): number {
285289
);
286290
}
287291

288-
return associatedPRs[0].number;
292+
const pr = associatedPRs[0];
293+
294+
assert(pr);
295+
296+
return pr.number;
289297
}
290298

291299
async function getPRsInfo(

resources/inline-invariant.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import assert from 'node:assert';
2+
13
import ts from 'typescript';
24

35
/**
@@ -29,6 +31,8 @@ export function inlineInvariant(context: ts.TransformationContext) {
2931
if (funcName === 'invariant' || funcName === 'devAssert') {
3032
const [condition, ...otherArgs] = args;
3133

34+
assert(condition);
35+
3236
return factory.createBinaryExpression(
3337
factory.createParenthesizedExpression(condition),
3438
ts.SyntaxKind.BarBarToken,

resources/utils.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,12 @@ export function showDirStats(dirPath: string): void {
149149
const ext = name.split('.').slice(1).join('.');
150150
const filetype = ext ? '*.' + ext : name;
151151

152-
fileTypes[filetype] ??= { filepaths: [], size: 0 };
152+
const dirStats = fileTypes[filetype] ?? { filepaths: [], size: 0 };
153+
fileTypes[filetype] = dirStats;
153154

154155
totalSize += stats.size;
155-
fileTypes[filetype].size += stats.size;
156-
fileTypes[filetype].filepaths.push(filepath);
156+
dirStats.size += stats.size;
157+
dirStats.filepaths.push(filepath);
157158
}
158159

159160
const stats: Array<[string, number]> = [];
@@ -163,13 +164,14 @@ export function showDirStats(dirPath: string): void {
163164
if (numFiles > 1) {
164165
stats.push([filetype + ' x' + numFiles, typeStats.size]);
165166
} else {
167+
assert(typeStats.filepaths[0]);
166168
const relativePath = path.relative(dirPath, typeStats.filepaths[0]);
167169
stats.push([relativePath, typeStats.size]);
168170
}
169171
}
170172
stats.sort((a, b) => b[1] - a[1]);
171173

172-
const prettyStats = stats.map(([type, size]) => [
174+
const prettyStats = stats.map<[string, string]>(([type, size]) => [
173175
type,
174176
(size / 1024).toFixed(2) + ' KB',
175177
]);

0 commit comments

Comments
 (0)