Skip to content

Commit 86f17ac

Browse files
committed
Fix lint errors
1 parent 3cb8743 commit 86f17ac

File tree

3 files changed

+33
-32
lines changed

3 files changed

+33
-32
lines changed

src/commands/list.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { leetCodeManager } from "../leetCodeManager";
77
import { ProblemState, UserStatus } from "../shared";
88
import { DialogType, promptForOpenOutputChannel } from "../utils/uiUtils";
99

10+
// tslint:disable-next-line:typedef
1011
export const IProblemDefault = {
1112
favorite: false,
1213
locked: false,
@@ -16,8 +17,8 @@ export const IProblemDefault = {
1617
difficulty: "",
1718
passRate: "",
1819
companies: [] as string[],
19-
tags: [] as string[]
20-
}
20+
tags: [] as string[],
21+
};
2122

2223
export type IProblem = typeof IProblemDefault;
2324

@@ -36,17 +37,17 @@ export async function listProblems(): Promise<IProblem[]> {
3637
for (const line of lines) {
3738
const match: RegExpMatchArray | null = line.match(reg);
3839
if (match && match.length === 8) {
39-
const id = match[4].trim();
40+
const id: string = match[4].trim();
4041
problems.push({
42+
id,
4143
favorite: match[1].trim().length > 0,
4244
locked: match[2].trim().length > 0,
4345
state: parseProblemState(match[3]),
44-
id: id,
4546
name: match[5].trim(),
4647
difficulty: match[6].trim(),
4748
passRate: match[7].trim(),
4849
companies: companies[id] || ["Unknown"],
49-
tags: tags[id] || ["Unknown"]
50+
tags: tags[id] || ["Unknown"],
5051
});
5152
}
5253
}

src/leetCodeExecutor.ts

+6-5
Original file line numberDiff line numberDiff line change
@@ -112,16 +112,17 @@ class LeetCodeExecutor {
112112

113113
public async getCompaniesAndTags(): Promise<{ companies: { [key: string]: string[] }, tags: { [key: string]: string[] } }> {
114114
// preprocess the plugin source
115-
const componiesTagsPath = path.join(await leetCodeExecutor.getLeetCodeRootPath(), "lib", "plugins", "company.js");
116-
let componiesTagsSrc = await fs.readFileSync(componiesTagsPath, "utf8");
117-
componiesTagsSrc = componiesTagsSrc.replace("module.exports = plugin", "module.exports = { COMPONIES, TAGS }");
115+
const componiesTagsPath: string = path.join(await leetCodeExecutor.getLeetCodeRootPath(), "lib", "plugins", "company.js");
116+
const componiesTagsSrc: string = (await fs.readFileSync(componiesTagsPath, "utf8")).replace(
117+
"module.exports = plugin",
118+
"module.exports = { COMPONIES, TAGS }",
119+
);
118120
// require plugin from modified string
119-
const requireFromString = require("require-from-string");
121+
const requireFromString: (src: string, path: string) => any = require("require-from-string");
120122
const { COMPONIES, TAGS } = requireFromString(componiesTagsSrc, componiesTagsPath);
121123
return { companies: COMPONIES, tags: TAGS };
122124
}
123125

124-
125126
private async executeCommandEx(command: string, args: string[], options: cp.SpawnOptions = { shell: true }): Promise<string> {
126127
if (wsl.useWsl()) {
127128
return await executeCommand("wsl", [command].concat(args), options);

src/leetCodeExplorer.ts

+21-22
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
4343
Difficulty: Map<string, list.IProblem[]>,
4444
Tag: Map<string, list.IProblem[]>,
4545
Company: Map<string, list.IProblem[]>,
46-
Favorite: list.IProblem[]
46+
Favorite: list.IProblem[],
4747
};
4848

4949
private onDidChangeTreeDataEvent: vscode.EventEmitter<any> = new vscode.EventEmitter<any>();
@@ -92,7 +92,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
9292
if (!element) { // Root view
9393
return new Promise(async (resolve: (res: LeetCodeNode[]) => void): Promise<void> => {
9494
await this.getProblemData();
95-
const nodes = [
95+
resolve([
9696
new LeetCodeNode(Object.assign({}, list.IProblemDefault, {
9797
id: "Root",
9898
name: "Difficulty",
@@ -109,8 +109,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
109109
id: "Root",
110110
name: "Favorite",
111111
}), false),
112-
]
113-
resolve(nodes);
112+
]);
114113
});
115114
} else {
116115
switch (element.name) { // First-level
@@ -119,7 +118,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
119118
case "Company":
120119
return this.composeCategoryNodes(element);
121120
case "Favorite":
122-
return this.treeData.Favorite.map(p => new LeetCodeNode(p));
121+
return this.treeData.Favorite.map((p: list.IProblem) => new LeetCodeNode(p));
123122
default: // Second and lower levels
124123
return element.isProblem ? [] : this.composeProblemNodes(element);
125124
}
@@ -131,20 +130,20 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
131130
Difficulty: new Map(),
132131
Tag: new Map(),
133132
Company: new Map(),
134-
Favorite: []
135-
}
133+
Favorite: [],
134+
};
136135
for (const problem of await list.listProblems()) {
137136
// Add problems according to category
138-
const categories = [
137+
const categories: Array<[Category, string[]]> = [
139138
["Difficulty", [problem.difficulty]],
140139
["Tag", problem.tags],
141-
["Company", problem.companies]
142-
] as [Category, string[]][];
140+
["Company", problem.companies],
141+
];
143142
for (const [parent, children] of categories) {
144143
for (let subCategory of children) {
145144
// map 'first-second' to 'First Second'
146-
subCategory = subCategory.split('-').map(c => c[0].toUpperCase() + c.slice(1)).join(' ');
147-
const problems = this.treeData[parent].get(subCategory);
145+
subCategory = subCategory.split("-").map((c: string) => c[0].toUpperCase() + c.slice(1)).join(" ");
146+
const problems: list.IProblem[] | undefined = this.treeData[parent].get(subCategory);
148147
if (problems) {
149148
problems.push(problem);
150149
} else {
@@ -154,7 +153,7 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
154153
}
155154
// Add favorite problems
156155
if (problem.favorite) {
157-
this.treeData.Favorite.push(problem)
156+
this.treeData.Favorite.push(problem);
158157
}
159158
}
160159
}
@@ -173,13 +172,13 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
173172
}
174173

175174
private composeCategoryNodes(node: LeetCodeNode): LeetCodeNode[] {
176-
const parent = node.name as Category;
177-
const categoryNodes = Array.from(this.treeData[parent].keys()).map(subCategory =>
178-
new LeetCodeNode(Object.assign({}, list.IProblemDefault, {
179-
id: parent,
180-
name: subCategory,
181-
}), false)
182-
);
175+
const parent: Category = node.name as Category;
176+
const categoryNodes: LeetCodeNode[] =
177+
Array.from(this.treeData[parent].keys()).map((subCategory: string) =>
178+
new LeetCodeNode(Object.assign({}, list.IProblemDefault, {
179+
id: parent,
180+
name: subCategory,
181+
}), false));
183182
// Sort lists
184183
switch (parent) {
185184
case "Difficulty": {
@@ -202,9 +201,9 @@ export class LeetCodeTreeDataProvider implements vscode.TreeDataProvider<LeetCod
202201
case "Tag":
203202
case "Company": {
204203
categoryNodes.sort((a: LeetCodeNode, b: LeetCodeNode): number => {
205-
if (a.name == "Unknown") {
204+
if (a.name === "Unknown") {
206205
return 1;
207-
} else if (b.name == "Unknown") {
206+
} else if (b.name === "Unknown") {
208207
return -1;
209208
} else {
210209
return Number(a.name > b.name) - Number(a.name < b.name);

0 commit comments

Comments
 (0)