Skip to content

Commit 86b3637

Browse files
authored
chore: review use of as keyword in codebase (#69)
1 parent 5c94b56 commit 86b3637

File tree

9 files changed

+20
-20
lines changed

9 files changed

+20
-20
lines changed

packages/cli/src/bin/countBallotsFromGit.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const { repo: repoURL, branch, path: subPath } = parsedArgs;
2525
const privateKey
2626
= parsedArgs.key === "-"
2727
? await readStdIn(false)
28-
: parsedArgs.key && (await fs.readFile(parsedArgs.key as string));
28+
: parsedArgs.key && (await fs.readFile(parsedArgs.key));
2929

3030
const { result, privateKeyAsArmoredString } = await countFromGit({
3131
...(await getEnv(parsedArgs)),

packages/cli/src/bin/voteOnGitHub.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const query = `query PR($prid: Int!, $owner: String!, $repo: String!) {
8989
console.log("Getting info from GitHub API...");
9090
const { data } = JSON.parse(
9191
await runChildProcessAsync(
92-
parsedArgs["gh-binary"] as string,
92+
parsedArgs["gh-binary"],
9393
[
9494
"api",
9595
"graphql",
@@ -122,7 +122,7 @@ if (merged || closed) {
122122

123123
console.log(`Locating vote.yml on commit ${sha}...`);
124124
const files = await runChildProcessAsync(
125-
parsedArgs["gh-binary"] as string,
125+
parsedArgs["gh-binary"],
126126
[
127127
"api",
128128
`/repos/${owner}/${repo}/commits/${sha}`,

packages/cli/src/utils/countBallotsGitEnv.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const cliArgs = {
3030
};
3131

3232
export async function getEnv(parsedArgs: GitCliArgsType) {
33-
const GIT_BIN = (parsedArgs["git-binary"] ?? env.GIT ?? "git") as string;
33+
const GIT_BIN = (parsedArgs["git-binary"] ?? env.GIT ?? "git");
3434

3535
const cwd = await fs.mkdtemp(path.join(os.tmpdir(), "caritat-"));
3636
return {

packages/cli/src/utils/runChildProcessAsync.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export default (
66
args: any[] | readonly string[],
77
{ captureStdout = false, captureStderr = false, spawnArgs = {} } = {},
88
) =>
9-
new Promise((resolve, reject) => {
9+
new Promise<string>((resolve, reject) => {
1010
const opt = {
1111
stdio: captureStdout
1212
? (["inherit", "pipe", "inherit"] as IOType[])
@@ -37,4 +37,4 @@ export default (
3737
}
3838
return resolve(stdout?.trim());
3939
});
40-
}) as Promise<string>;
40+
});

packages/cli/src/utils/streamChildProcessStdout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ export default async function* streamChildProcessStdout(
1212
stdio: ["inherit", "pipe", "inherit"],
1313
...spawnArgs,
1414
});
15-
const promise = new Promise((resolve, reject) => {
15+
const promise = new Promise<void>((resolve, reject) => {
1616
child.once("error", reject);
1717
child.on("close", (code) => {
1818
if (code !== 0) {
1919
return reject(new Error(`${cmd} ${args} failed: ${code}`));
2020
}
2121
resolve();
2222
});
23-
}) as Promise<void>;
23+
});
2424
yield* createInterface({ input: child.stdout });
2525
return promise;
2626
}

packages/core/src/countBallotsFromGit.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ async function readFileAtRevision(
5454
);
5555
}
5656

57-
interface countFromGitArgs {
57+
interface countFromGitArgs<T extends BufferSource> {
5858
GIT_BIN?: string;
5959
cwd: string;
6060
repoURL: string;
6161
branch: string;
6262
subPath: string;
63-
privateKey?: ArrayBuffer;
63+
privateKey?: T;
6464
keyParts: string[];
6565
firstCommitRef: string;
6666
lastCommitRef?: string;
@@ -71,7 +71,7 @@ interface countFromGitArgs {
7171
doNotCleanTempFiles: boolean;
7272
}
7373

74-
export default async function countFromGit({
74+
export default async function countFromGit<T extends BufferSource = BufferSource>({
7575
GIT_BIN = "git",
7676
cwd,
7777
repoURL,
@@ -86,9 +86,9 @@ export default async function countFromGit({
8686
pushToRemote = true,
8787
gpgSign,
8888
doNotCleanTempFiles,
89-
}: countFromGitArgs): Promise<{
89+
}: countFromGitArgs<T>): Promise<{
9090
result: VoteResult;
91-
privateKey: ArrayBuffer;
91+
privateKey: T;
9292
readonly privateKeyAsArmoredString: string;
9393
}> {
9494
const spawnArgs = { cwd };
@@ -150,7 +150,7 @@ export default async function countFromGit({
150150
keyParts?.map((part: string | BufferSource) =>
151151
typeof part === "string" ? Buffer.from(part, "base64") : part,
152152
),
153-
);
153+
) as T;
154154
}
155155

156156
if (mailmap != null) {
@@ -343,7 +343,7 @@ export default async function countFromGit({
343343
result,
344344
privateKey,
345345
get privateKeyAsArmoredString() {
346-
const base64Key = Buffer.from(privateKey).toString("base64");
346+
const base64Key = Buffer.from(privateKey as ArrayBuffer).toString("base64");
347347
let key = "-----BEGIN PRIVATE KEY-----\n";
348348
for (let i = 0; i < base64Key.length; i += 64) {
349349
key += base64Key.slice(i, i + 60) + "\n";

packages/core/src/utils/runChildProcessAsync.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default (
1111
spawnArgs = {},
1212
} = {},
1313
) =>
14-
new Promise((resolve, reject) => {
14+
new Promise<string>((resolve, reject) => {
1515
const opt = {
1616
stdio: captureStdout
1717
? (["inherit", "pipe", "inherit"] as IOType[])
@@ -42,4 +42,4 @@ export default (
4242
}
4343
return resolve(trimOutput ? stdout?.trim() : stdout);
4444
});
45-
}) as Promise<string>;
45+
});

packages/core/src/utils/streamChildProcessStdout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ export default async function* streamChildProcessStdout(
1212
stdio: ["inherit", "pipe", "inherit"],
1313
...spawnArgs,
1414
});
15-
const promise = new Promise((resolve, reject) => {
15+
const promise = new Promise<void>((resolve, reject) => {
1616
child.once("error", reject);
1717
child.on("close", (code) => {
1818
if (code !== 0) {
1919
return reject(new Error(`${cmd} ${args} failed: ${code}`));
2020
}
2121
resolve();
2222
});
23-
}) as Promise<void>;
23+
});
2424
yield* createInterface({ input: child.stdout });
2525
return promise;
2626
}

packages/crypto/src/decrypt.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export async function symmetricDecrypt(
2020
const { byteLength } = saltedCiphertext;
2121
if (ArrayBuffer.isView(saltedCiphertext)) {
2222
offset = saltedCiphertext.byteOffset;
23-
saltedCiphertext = saltedCiphertext.buffer;
23+
saltedCiphertext = saltedCiphertext.buffer as ArrayBuffer;
2424
}
2525

2626
const magicNumber = new DataView(saltedCiphertext, offset, 8);

0 commit comments

Comments
 (0)