Skip to content

Commit 0eb5329

Browse files
authored
chore: add @stylistic/eslint-plugin (#66)
Our current linter is IMO way too loose, causing us to have inconsistent JS styles across the repo. Let's make it tighter.
1 parent 915d788 commit 0eb5329

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+501
-472
lines changed

eslint.config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,16 @@
11
import js from "@eslint/js";
22
import tsPlugin from "typescript-eslint";
3+
import stylistic from "@stylistic/eslint-plugin";
34

45
export default [
56
js.configs.recommended,
67
...tsPlugin.configs.recommended,
8+
stylistic.configs.customize({
9+
braceStyle: "1tbs",
10+
quotes: "double",
11+
quoteProps: "as-needed",
12+
semi: true,
13+
}),
714
{
815
files: ["**/*.ts"],
916
languageOptions: {
@@ -15,6 +22,7 @@ export default [
1522
},
1623
plugins: {
1724
"@typescript-eslint": tsPlugin.plugin,
25+
"@stylistic": stylistic,
1826
},
1927
},
2028
{ ignores: ["node_modules/", "**/dist/"] },

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"url": "https://github.com/nodejs/caritat.git"
1010
},
1111
"devDependencies": {
12+
"@stylistic/eslint-plugin": "^4.4.1",
1213
"@types/eslint": "^9",
1314
"@types/js-yaml": "^4.0.5",
1415
"@types/node": "^20.0.0",

packages/cli/src/bin/countBallotsFromGit.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ const parsedArgs = await parseArgs().options({
2222

2323
const { repo: repoURL, branch, path: subPath } = parsedArgs;
2424

25-
const privateKey =
26-
parsedArgs.key === "-"
25+
const privateKey
26+
= parsedArgs.key === "-"
2727
? await readStdIn(false)
2828
: parsedArgs.key && (await fs.readFile(parsedArgs.key as string));
2929

packages/cli/src/bin/countBallotsFromGitHub.ts

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ const parsedArgs = await parseArgs()
1919

2020
protocol: {
2121
describe:
22-
"the protocol to use to pull the remote repository, either SSH or " +
23-
"HTTP (defaults to SSH if a public SSH key is found for the current " +
24-
"user, otherwise default to HTTP)",
22+
"the protocol to use to pull the remote repository, either SSH or "
23+
+ "HTTP (defaults to SSH if a public SSH key is found for the current "
24+
+ "user, otherwise default to HTTP)",
2525
string: true,
2626
},
2727
login: {
@@ -50,8 +50,8 @@ const parsedArgs = await parseArgs()
5050
["key-part"]: {
5151
...cliArgs["key-part"],
5252
describe:
53-
cliArgs["key-part"].describe +
54-
" If not provided, it will be extracted from the PR comments.",
53+
cliArgs["key-part"].describe
54+
+ " If not provided, it will be extracted from the PR comments.",
5555
},
5656
})
5757
.command(
@@ -63,16 +63,16 @@ const parsedArgs = await parseArgs()
6363
type: "string",
6464
describe: "URL to the GitHub pull request",
6565
});
66-
}
66+
},
6767
).argv;
6868

69-
const privateKey =
70-
parsedArgs.key === "-"
69+
const privateKey
70+
= parsedArgs.key === "-"
7171
? await readStdIn(false)
7272
: parsedArgs.key && (await fs.readFile(parsedArgs.key));
7373

7474
const prUrlInfo = /^https:\/\/github\.com\/([^/]+)\/([^/]+)\/pull\/(\d+)$/.exec(
75-
parsedArgs["pr-url"] as string
75+
parsedArgs["pr-url"] as string,
7676
);
7777

7878
if (prUrlInfo == null) {
@@ -81,7 +81,7 @@ if (prUrlInfo == null) {
8181

8282
const [, owner, repo, prNumber] = prUrlInfo;
8383
console.warn(
84-
`Looking into GitHub pull request ${owner}/${repo}#${prNumber}...`
84+
`Looking into GitHub pull request ${owner}/${repo}#${prNumber}...`,
8585
);
8686

8787
const query = `query PR($prid: Int!, $owner: String!, $repo: String!) {
@@ -126,8 +126,8 @@ const { data } = JSON.parse(
126126
"-f",
127127
`query=${query}`,
128128
],
129-
{ captureStdout: true }
130-
)
129+
{ captureStdout: true },
130+
),
131131
);
132132

133133
const { pullRequest } = data.repository;
@@ -154,31 +154,31 @@ const files = await runChildProcessAsync(
154154
"--jq",
155155
".files.[] | .filename",
156156
],
157-
{ captureStdout: true }
157+
{ captureStdout: true },
158158
);
159159

160160
const voteFileCanonicalName = "vote.yml";
161161
const subPath = files
162162
.split("\n")
163163
.find(
164-
(path) =>
165-
path === voteFileCanonicalName ||
166-
path.endsWith(`/${voteFileCanonicalName}`)
164+
path =>
165+
path === voteFileCanonicalName
166+
|| path.endsWith(`/${voteFileCanonicalName}`),
167167
)
168168
?.slice(0, -voteFileCanonicalName.length);
169169

170170
const handle = parsedArgs.login || data.viewer.login;
171171

172-
const protocol =
173-
parsedArgs.protocol ?? (data.viewer.publicKeys.totalCount ? "ssh" : "http");
172+
const protocol
173+
= parsedArgs.protocol ?? (data.viewer.publicKeys.totalCount ? "ssh" : "http");
174174

175175
function getHTTPRepoURL(repoURL: string, login: string) {
176176
const url = new URL(repoURL + ".git");
177177
url.username = login;
178178
return url.toString();
179179
}
180-
const repoURL =
181-
protocol === "ssh"
180+
const repoURL
181+
= protocol === "ssh"
182182
? data.repository.sshUrl
183183
: getHTTPRepoURL(data.repository.url, handle);
184184

@@ -191,14 +191,14 @@ console.warn("All relevant information has been retrieved:", {
191191
});
192192

193193
async function getKeyPartsFromComments() {
194-
const shamirKeyPartComment =
195-
/\n-----BEGIN SHAMIR KEY PART-----\n([a-zA-Z0-9+/\s]+={0,2})\n-----END SHAMIR KEY PART-----\n/;
194+
const shamirKeyPartComment
195+
= /\n-----BEGIN SHAMIR KEY PART-----\n([a-zA-Z0-9+/\s]+={0,2})\n-----END SHAMIR KEY PART-----\n/;
196196
const { comments } = JSON.parse(
197197
await runChildProcessAsync(
198198
parsedArgs["gh-binary"] as string,
199199
["pr", "view", parsedArgs["pr-url"], "--json", "comments"],
200-
{ captureStdout: true }
201-
)
200+
{ captureStdout: true },
201+
),
202202
);
203203

204204
const results = [];
@@ -237,12 +237,12 @@ if (parsedArgs["post-comment"]) {
237237
]);
238238
} else {
239239
console.log(
240-
"To publish the results, you should use `--post-comment --commit-json-summary` CLI flags."
240+
"To publish the results, you should use `--post-comment --commit-json-summary` CLI flags.",
241241
);
242242
console.log(
243243
"Participation:",
244244
Math.round(summary.participation * 100_00) / 1_00,
245-
"%"
245+
"%",
246246
);
247247
console.log("Raw results:", summary.result);
248248
}

packages/cli/src/bin/decryptBallot.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env node
22

33
import fs from "fs";
4-
4+
55
import parseArgs from "../utils/parseArgs.js";
66
import decryptData from "@node-core/caritat-crypto/decrypt";
77

@@ -25,7 +25,7 @@ const parsedArgs = await parseArgs().options({
2525
const { data: filePath, key: privateKeyPath } = parsedArgs;
2626

2727
const { encryptedSecret, data } = JSON.parse(
28-
fs.readFileSync(filePath, "utf8").replace(/^\uFEFF/, "")
28+
fs.readFileSync(filePath, "utf8").replace(/^\uFEFF/, ""),
2929
);
3030

3131
console.log(
@@ -34,8 +34,8 @@ console.log(
3434
await decryptData(
3535
Buffer.from(data, "base64"),
3636
Buffer.from(encryptedSecret, "base64"),
37-
fs.readFileSync(privateKeyPath)
38-
)
39-
)
40-
).toString("utf8")
37+
fs.readFileSync(privateKeyPath),
38+
),
39+
),
40+
).toString("utf8"),
4141
);

packages/cli/src/bin/decryptKeyPart.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@ if (argv[2] === "-h" || argv[2] === "--help") {
1919
console.log("decryptKeyPath < path/to/vote.yml");
2020
console.log("curl -L http://example.com/vote.yml | decryptKeyPath | base64");
2121
console.log(
22-
"decryptKeyPath https://github.com/owner/repo/pull/1 # requires gh CLI tool"
22+
"decryptKeyPath https://github.com/owner/repo/pull/1 # requires gh CLI tool",
2323
);
2424
console.log(
25-
"decryptKeyPath https://github.com/owner/repo/pull/1 --post-comment # requires gh CLI tool"
25+
"decryptKeyPath https://github.com/owner/repo/pull/1 --post-comment # requires gh CLI tool",
2626
);
2727
console.log(
28-
"Upon success, this tool will output to stdout a base64 representation of the decrypted key part."
28+
"Upon success, this tool will output to stdout a base64 representation of the decrypted key part.",
2929
);
3030
exit(0);
3131
} else if (argv[2]) {
32-
//github.com/stduhpf/pleaseignore/raw/15f8e6ae5d2c417d7bc68ec1ea6db35d00cc263c/voteTest/nodejstest/vote.yml
33-
const gh_PR_URL =
34-
/^https?:\/\/github.com\/([^/]+)\/([^/]+)\/pull\/(\d+)/.exec(argv[2]);
32+
// github.com/stduhpf/pleaseignore/raw/15f8e6ae5d2c417d7bc68ec1ea6db35d00cc263c/voteTest/nodejstest/vote.yml
33+
const gh_PR_URL
34+
= /^https?:\/\/github.com\/([^/]+)\/([^/]+)\/pull\/(\d+)/.exec(argv[2]);
3535
if (gh_PR_URL == null) throw new Error("Invalid PR URL format");
3636
const [, owner, repo, prId] = gh_PR_URL;
3737
const filesData = JSON.parse(
@@ -43,16 +43,16 @@ if (argv[2] === "-h" || argv[2] === "--help") {
4343
"Accept: application/vnd.github+json",
4444
`/repos/${owner}/${repo}/pulls/${prId}/files`,
4545
],
46-
{ captureStdout: true }
47-
)
46+
{ captureStdout: true },
47+
),
4848
);
4949
const { contents_url } = filesData.find(({ filename }) =>
50-
/(^|\/)vote.yml$/.test(filename)
50+
/(^|\/)vote.yml$/.test(filename),
5151
);
5252
yamlString = await runChildProcessAsync(
5353
env.GH_BIN || "gh",
5454
["api", "-H", "Accept: application/vnd.github.raw", contents_url],
55-
{ captureStdout: true }
55+
{ captureStdout: true },
5656
);
5757
} else {
5858
yamlString = (await stdin.toArray()).join();
@@ -72,11 +72,11 @@ const out = await Promise.any(
7272
cp.stdin.end(share);
7373
const [code] = await Promise.race([
7474
once(cp, "exit"),
75-
once(cp, "error").then((er) => Promise.reject(er)),
75+
once(cp, "error").then(er => Promise.reject(er)),
7676
]);
7777
if (code !== 0) throw new Error("failed", { cause: code });
7878
return Buffer.concat(await stdout);
79-
})
79+
}),
8080
);
8181
ac.abort();
8282

@@ -86,10 +86,10 @@ if (argv[3] === "--post-comment") {
8686
"comment",
8787
argv[2],
8888
"-b",
89-
`I would like to close this vote, and for this effect, I'm revealing my ` +
90-
`key part:\n\n${"```"}\n-----BEGIN SHAMIR KEY PART-----\n${out.toString(
91-
"base64"
92-
)}\n-----END SHAMIR KEY PART-----\n${"```"}\n`,
89+
`I would like to close this vote, and for this effect, I'm revealing my `
90+
+ `key part:\n\n${"```"}\n-----BEGIN SHAMIR KEY PART-----\n${out.toString(
91+
"base64",
92+
)}\n-----END SHAMIR KEY PART-----\n${"```"}\n`,
9393
]);
9494
} else {
9595
stdout.write(out);

packages/cli/src/bin/encryptBallot.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ const { file: filePath, key: publicKeyPath } = parsedArgs;
2424

2525
const { encryptedSecret, saltedCiphertext } = await encryptData(
2626
fs.readFileSync(filePath),
27-
fs.readFileSync(publicKeyPath)
27+
fs.readFileSync(publicKeyPath),
2828
);
2929

3030
console.log(
3131
JSON.stringify({
3232
encryptedSecret: Buffer.from(encryptedSecret).toString("base64"),
3333
data: Buffer.from(saltedCiphertext).toString("base64"),
34-
})
34+
}),
3535
);

packages/cli/src/bin/extractEncryptedPrivateKey.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (yamlFile === "--help" || yamlFile === "-h") {
1818
console.log("Usage: extractEncryptedPrivateKey <path-to-YAML-file>");
1919
console.log("or");
2020
console.log(
21-
"Usage: echo 'encryptedPrivateKey: …' | extractEncryptedPrivateKey"
21+
"Usage: echo 'encryptedPrivateKey: …' | extractEncryptedPrivateKey",
2222
);
2323
process.exit();
2424
} else if (yamlFile == null) {

packages/cli/src/bin/generateNewVoteFolder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ const parsedArgs = await parseArgs().options({
104104

105105
async function getCommitAuthor() {
106106
if (
107-
(parsedArgs.username && !parsedArgs.email) ||
108-
(!parsedArgs.username && parsedArgs.email)
107+
(parsedArgs.username && !parsedArgs.email)
108+
|| (!parsedArgs.username && parsedArgs.email)
109109
) {
110110
const { emailAddress, username } = await getEnv(parsedArgs);
111111
return `${username} <${emailAddress}>`;
@@ -125,8 +125,8 @@ await generateNewVoteFolder({
125125
const chars = await once(stdin, "data");
126126
stdin.pause();
127127
if (
128-
chars[0][0] === 0x6e || // n
129-
chars[0][0] === 0x4e // N
128+
chars[0][0] === 0x6e // n
129+
|| chars[0][0] === 0x4e // N
130130
) {
131131
console.log("Vote template file is ready for edit.");
132132
return true;

0 commit comments

Comments
 (0)