Skip to content

Commit

Permalink
Address all unchecked indexed access within resources
Browse files Browse the repository at this point in the history
  • Loading branch information
louisscruz committed Mar 26, 2023
1 parent aa43fec commit 610f3da
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 11 deletions.
9 changes: 5 additions & 4 deletions resources/benchmark.ts
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,9 @@ function runBenchmark(
benchmark: string,
benchmarkProjects: ReadonlyArray<BenchmarkProject>,
) {
const results = [];
for (let i = 0; i < benchmarkProjects.length; ++i) {
const { revision, projectPath } = benchmarkProjects[i];
const results: Array<BenchmarkComputedStats> = [];

benchmarkProjects.forEach(({ revision, projectPath }, i) => {
const modulePath = path.join(projectPath, benchmark);

if (i === 0) {
Expand All @@ -288,7 +288,8 @@ function runBenchmark(
} catch (error) {
console.log(' ' + revision + ': ' + red(error.message));
}
}
});

console.log('\n');

beautifyBenchmark(results);
Expand Down
1 change: 1 addition & 0 deletions resources/build-npm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ function buildPackage(outDir: string, isESMOnly: boolean): void {
const splittedTag = preReleaseTag.split('.');
// Note: `experimental-*` take precedence over `alpha`, `beta` or `rc`.
const versionTag = splittedTag[2] ?? splittedTag[0];
assert(versionTag);
assert(
['alpha', 'beta', 'rc'].includes(versionTag) ||
versionTag.startsWith('experimental-'),
Expand Down
3 changes: 3 additions & 0 deletions resources/diff-npm-package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ if (args.length < 2) {
);
}

assert(fromRevision);
assert(toRevision);

console.log(`📦 Building NPM package for ${fromRevision}...`);
const fromPackage = prepareNPMPackage(fromRevision);

Expand Down
14 changes: 11 additions & 3 deletions resources/gen-changelog.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import assert from 'node:assert';

import { git, readPackageJSON } from './utils.js';

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

const label = labels[0];
assert(label);
if (!labelsConfig[label]) {
throw new Error(`Unknown label: ${label}. See ${pr.url}`);
}
byLabel[label] ??= [];
byLabel[label].push(pr);
const prByLabel = byLabel[label] ?? [];
byLabel[label] = prByLabel;
prByLabel.push(pr);
committersByLogin[pr.author.login] = pr.author;
}

Expand Down Expand Up @@ -285,7 +289,11 @@ function commitInfoToPR(commit: CommitInfo): number {
);
}

return associatedPRs[0].number;
const pr = associatedPRs[0];

assert(pr);

return pr.number;
}

async function getPRsInfo(
Expand Down
4 changes: 4 additions & 0 deletions resources/inline-invariant.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import assert from 'node:assert';

import ts from 'typescript';

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

assert(condition);

return factory.createBinaryExpression(
factory.createParenthesizedExpression(condition),
ts.SyntaxKind.BarBarToken,
Expand Down
10 changes: 6 additions & 4 deletions resources/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,12 @@ export function showDirStats(dirPath: string): void {
const ext = name.split('.').slice(1).join('.');
const filetype = ext ? '*.' + ext : name;

fileTypes[filetype] ??= { filepaths: [], size: 0 };
const dirStats = fileTypes[filetype] ?? { filepaths: [], size: 0 };
fileTypes[filetype] = dirStats;

totalSize += stats.size;
fileTypes[filetype].size += stats.size;
fileTypes[filetype].filepaths.push(filepath);
dirStats.size += stats.size;
dirStats.filepaths.push(filepath);
}

const stats: Array<[string, number]> = [];
Expand All @@ -163,13 +164,14 @@ export function showDirStats(dirPath: string): void {
if (numFiles > 1) {
stats.push([filetype + ' x' + numFiles, typeStats.size]);
} else {
assert(typeStats.filepaths[0]);
const relativePath = path.relative(dirPath, typeStats.filepaths[0]);
stats.push([relativePath, typeStats.size]);
}
}
stats.sort((a, b) => b[1] - a[1]);

const prettyStats = stats.map(([type, size]) => [
const prettyStats = stats.map<[string, string]>(([type, size]) => [
type,
(size / 1024).toFixed(2) + ' KB',
]);
Expand Down

0 comments on commit 610f3da

Please sign in to comment.