Skip to content

Commit e88ebe3

Browse files
committed
Enable a few more ESLint rules
1 parent e1b980a commit e88ebe3

File tree

8 files changed

+82
-19
lines changed

8 files changed

+82
-19
lines changed

tools/adventure-pack/goodies/typescript/Number.isIntegerOrIntegerObject/index.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ describe("Number.isIntegerOrIntegerObject", () => {
4040
expect(Number.isIntegerOrIntegerObject(true)).toBe(false);
4141
expect(Number.isIntegerOrIntegerObject(false)).toBe(false);
4242
expect(Number.isIntegerOrIntegerObject(Symbol("12"))).toBe(false);
43-
expect(Number.isIntegerOrIntegerObject(Symbol())).toBe(false);
43+
expect(Number.isIntegerOrIntegerObject(Symbol(undefined))).toBe(false);
4444
expect(Number.isIntegerOrIntegerObject({})).toBe(false);
4545
expect(Number.isIntegerOrIntegerObject([])).toBe(false);
4646
expect(Number.isIntegerOrIntegerObject([12])).toBe(false);

tools/adventure-pack/src/app/useMergedCode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export function useMergedCode({
1515

1616
useEffect(() => {
1717
if (goodies == null) {
18-
return;
18+
return undefined;
1919
}
2020

2121
let isActive = true;

tools/adventure-pack/src/scripts/package-goodies/typescript/readGoodies.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ import type { JavaScriptGoody } from "../../../app/parsers/javaScriptGoodyParser
1010
import type { TypeScriptGoody } from "../../../app/parsers/typeScriptGoodyParser";
1111
import { fillOutImportedByAndSortImports } from "../fillOutImportedByAndSortImports";
1212
import {
13+
GOODIES_DIRECTORY,
1314
type TypeScriptGoodyBase,
1415
readBaseGoody,
15-
GOODIES_DIRECTORY,
1616
} from "./readBaseGoody";
1717
import { transpile } from "./transpile";
1818

tools/adventure-pack/src/scripts/package-goodies/typescript/transpile.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import invariant from "invariant";
22
import {
3-
createScanner,
4-
transpile as originalTranspile,
53
LanguageVariant,
6-
SyntaxKind,
74
ScriptTarget,
5+
SyntaxKind,
6+
createScanner,
7+
transpile as originalTranspile,
88
} from "typescript";
99

1010
import { getRandomBytes } from "@code-chronicles/util";

tools/download-submissions/src/getFilenameForSubmission.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,9 @@ import type { TransformedSubmission } from "./transformSubmission";
99
export function getFilenameForSubmission({
1010
id,
1111
lang,
12-
timestamp,
12+
// eslint-disable-next-line camelcase
1313
status_display,
14+
timestamp,
1415
}: TransformedSubmission): string {
1516
const extension =
1617
LANGUAGE_TO_FILE_EXTENSION[
@@ -19,6 +20,7 @@ export function getFilenameForSubmission({
1920
const date = timestampToYearMonthDay(timestamp, "");
2021
const resultAbbreviation = nullthrows(
2122
SUBMISSION_STATUS_TO_ABBREVIATION[
23+
// eslint-disable-next-line camelcase
2224
status_display as keyof typeof SUBMISSION_STATUS_TO_ABBREVIATION
2325
],
2426
).toLowerCase();

tools/download-submissions/src/transformSubmission.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export type TransformedSubmission = Omit<
2828

2929
export function transformSubmission({
3030
code,
31+
// eslint-disable-next-line camelcase
3132
compare_result,
3233
time: _,
3334
...rest
@@ -40,6 +41,7 @@ export function transformSubmission({
4041
submission: {
4142
...rest,
4243
sha512: sha512(code),
44+
// eslint-disable-next-line camelcase
4345
compare_result: compare_result?.map(Number).join("") ?? null,
4446
},
4547
};

tools/eslint-config/eslint.config.js

Lines changed: 42 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,46 @@ const vanilla = {
2727
ignoreStringLiterals: true,
2828
},
2929
],
30+
31+
"accessor-pairs": [
32+
"error",
33+
{
34+
getWithoutSet: false,
35+
setWithoutGet: true,
36+
enforceForClassMembers: true,
37+
},
38+
],
3039
"array-callback-return": [
3140
"error",
3241
{ allowImplicit: false, checkForEach: true, allowVoid: false },
3342
],
43+
"arrow-body-style": [
44+
"warn",
45+
"as-needed",
46+
{ requireReturnForObjectLiteral: false },
47+
],
48+
"block-scoped-var": "error",
49+
camelcase: [
50+
"warn",
51+
{
52+
properties: "always",
53+
ignoreDestructuring: false,
54+
ignoreImports: false,
55+
ignoreGlobals: false,
56+
allow: [],
57+
},
58+
],
59+
"class-methods-use-this": [
60+
"warn",
61+
{ exceptMethods: [], enforceForClassFields: true },
62+
],
63+
complexity: ["warn", { max: 20 }],
64+
"consistent-return": ["error", { treatUndefinedAsUnspecified: false }],
65+
"consistent-this": ["warn", "self"],
3466
"constructor-super": "error",
3567
curly: ["warn", "all"],
68+
"default-case-last": "error",
69+
eqeqeq: ["error", "always", { null: "never" }],
3670
"for-direction": "error",
3771
"getter-return": "error",
3872
"no-async-promise-executor": "error",
@@ -125,6 +159,9 @@ const vanilla = {
125159
"no-useless-assignment": "error",
126160
"no-useless-backreference": "error",
127161
"require-atomic-updates": "error",
162+
"require-await": "error",
163+
"require-yield": "error",
164+
"symbol-description": "warn",
128165
"use-isnan": [
129166
"error",
130167
{ enforceForSwitchCase: true, enforceForIndexOf: true },
@@ -138,12 +175,16 @@ const typescript = {
138175
files: ["**/*.ts", "**/*.tsx"],
139176
plugins: {
140177
...vanilla.plugins,
141-
"@typescript-eslint": typescriptEslintPlugin,
142178
"@stylistic/ts": stylisticPluginTs,
179+
"@typescript-eslint": typescriptEslintPlugin,
143180
},
144181
rules: {
145182
...vanilla.rules,
146183

184+
// In TypeScript files, use the TypeScript version of the rule.
185+
"@stylistic/js/quotes": "off",
186+
"@stylistic/ts/quotes": vanilla.rules["@stylistic/js/quotes"],
187+
147188
// In TypeScript files, TypeScript itself should take care of this.
148189
"no-undef": "off",
149190

@@ -156,10 +197,6 @@ const typescript = {
156197
// TODO: configure the additional options
157198
"@typescript-eslint/no-use-before-define":
158199
vanilla.rules["no-use-before-define"],
159-
160-
// In TypeScript files, use the TypeScript version of the rule.
161-
"@stylistic/js/quotes": "off",
162-
"@stylistic/ts/quotes": vanilla.rules["@stylistic/js/quotes"],
163200
},
164201
};
165202

tools/leetcode-api/src/getSubmissionList.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ const submissionParser = (() => {
3232
return z
3333
.object({
3434
id: positiveInt.transform(String),
35+
// eslint-disable-next-line camelcase
3536
question_id: positiveInt,
3637
lang: trimmedNonEmptyString,
38+
// eslint-disable-next-line camelcase
3739
lang_name: trimmedNonEmptyString,
3840
time: trimmedNonEmptyString.transform((s) => s.replace(/\u00a0/g, " ")),
3941
timestamp: int.nonnegative(),
4042
status: int,
43+
// eslint-disable-next-line camelcase
4144
status_display: trimmedNonEmptyString,
4245
runtime: trimmedNonEmptyString,
4346
url: z
@@ -46,37 +49,56 @@ const submissionParser = (() => {
4649
.transform((value) =>
4750
new URL(value, "https://leetcode.com/").toString(),
4851
),
52+
// eslint-disable-next-line camelcase
4953
is_pending: trimmedNonEmptyString,
5054
title: trimmedNonEmptyString,
5155
memory: trimmedNonEmptyString,
5256
code: untrimmedNonEmptyString,
57+
// eslint-disable-next-line camelcase
5358
compare_result: z
5459
.string()
5560
.regex(/^[01]*$/)
5661
.transform((value) => Array.from(value).map((c) => c === "1"))
5762
.nullable(),
63+
// eslint-disable-next-line camelcase
5864
title_slug: z
5965
.string()
6066
.trim()
6167
.regex(/^[a-z0-9\-]+$/),
68+
// eslint-disable-next-line camelcase
6269
has_notes: z.boolean(),
70+
// eslint-disable-next-line camelcase
6371
flag_type: int,
6472
})
65-
.transform(({ question_id, title, title_slug, ...rest }) => ({
66-
...rest,
67-
question: {
68-
questionFrontendId: question_id,
73+
.transform(
74+
({
75+
// eslint-disable-next-line camelcase
76+
question_id,
6977
title,
70-
titleSlug: title_slug,
71-
},
72-
}));
78+
// eslint-disable-next-line camelcase
79+
title_slug,
80+
...rest
81+
}) => ({
82+
...rest,
83+
question: {
84+
// eslint-disable-next-line camelcase
85+
questionFrontendId: question_id,
86+
title,
87+
// eslint-disable-next-line camelcase
88+
titleSlug: title_slug,
89+
},
90+
}),
91+
);
7392
})();
7493

7594
export type Submission = z.infer<typeof submissionParser>;
7695

7796
const submissionListParser = z.object({
97+
// eslint-disable-next-line camelcase
7898
submissions_dump: z.array(submissionParser),
99+
// eslint-disable-next-line camelcase
79100
has_next: z.boolean(),
101+
// eslint-disable-next-line camelcase
80102
last_key: z.string(),
81103
});
82104

0 commit comments

Comments
 (0)