10000 strict typedef · buerlee/vscode-leetcode@6e920d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6e920d5

Browse files
committed
strict typedef
1 parent b2deee8 commit 6e920d5

File tree

11 files changed

+35
-19
lines changed
  • 11 files changed

    +35
    -19
    lines changed

    src/commands/session.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -7,7 +7,7 @@ import { executeCommand } from "../utils/cpUtils";
    77
    import { DialogType, promptForOpenOutputChannel, promptForSignIn } from "../utils/uiUtils";
    88

    99
    export async function getSessionList(channel: vscode.OutputChannel): Promise<ISession[]> {
    10-
    const signInStatus = leetCodeManager.getUser();
    10+
    const signInStatus: string | undefined = leetCodeManager.getUser();
    1111
    if (!signInStatus) {
    1212
    promptForSignIn();
    1313
    return [];
    @@ -75,7 +75,7 @@ async function parseSessionsToPicks(channel: vscode.OutputChannel): Promise<Arra
    7575
    export async function createSession(channel: vscode.OutputChannel): Promise<void> {
    7676
    const session: string | undefined = await vscode.window.showInputBox({
    7777
    prompt: "Enter the new session name.",
    78-
    validateInput: (s: string) => s && s.trim() ? undefined : "Session name must not be empty",
    78+
    validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "Session name must not be empty",
    7979
    });
    8080
    if (!session) {
    8181
    return;

    src/commands/show.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -39,7 +39,7 @@ export async function searchProblem(channel: vscode.OutputChannel): Promise<void
    3939
    async function showProblemInternal(channel: vscode.OutputChannel, id: string): Promise<void> {
    4040
    try {
    4141
    const leetCodeConfig: vscode.WorkspaceConfiguration = vscode.workspace.getConfiguration("leetcode");
    42-
    let defaultLanguage = leetCodeConfig.get<string>("defaultLanguage");
    42+
    let defaultLanguage: string | undefined = leetCodeConfig.get<string>("defaultLanguage");
    4343
    if (defaultLanguage && languages.indexOf(defaultLanguage) < 0) {
    4444
    defaultLanguage = undefined;
    4545
    }
    @@ -54,7 +54,7 @@ async function showProblemInternal(channel: vscode.OutputChannel, id: string): P
    5454
    const reg: RegExp = /\* Source Code:\s*(.*)/;
    5555
    const match: RegExpMatchArray | null = result.match(reg);
    5656
    if (match && match.length >= 2) {
    57-
    const filePath = wsl.useWsl() ? wsl.toWinPath(match[1].trim()) : match[1].trim();
    57+
    const filePath: string = wsl.useWsl() ? wsl.toWinPath(match[1].trim()) : match[1].trim();
    5858

    5959
    await vscode.window.showTextDocument(vscode.Uri.file(filePath), { preview: false });
    6060
    } else {

    src/commands/test.ts

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -52,7 +52,7 @@ export async function testSolution(channel: vscode.OutputChannel, uri?: vscode.U
    5252
    case ":direct":
    5353
    const testString: string | undefined = await vscode.window.showInputBox({
    5454
    prompt: "Enter the test cases.",
    55-
    validateInput: (s: string) => s && s.trim() ? undefined : "Test case must not be empty.",
    55+
    validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "Test case must not be empty.",
    5656
    placeHolder: "Example: [1,2,3]\\n4",
    5757
    ignoreFocusOut: true,
    5858
    });

    src/extension.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -10,7 +10,7 @@ import { leetCodeManager } from "./leetCodeManager";
    1010
    import { leetCodeStatusBarItem } from "./leetCodeStatusBarItem";
    1111
    import { isNodeInstalled } from "./utils/nodeUtils";
    1212

    13-
    export async function activate(context: vscode.ExtensionContext) {
    13+
    export async function activate(context: vscode.ExtensionContext): Promise<void> {
    1414
    const channel: vscode.OutputChannel = vscode.window.createOutputChannel("LeetCode");
    1515
    if (!await isNodeInstalled(channel)) {
    1616
    return;
    @@ -37,6 +37,6 @@ export async function activate(context: vscode.ExtensionContext) {
    3737
    });
    3838
    }
    3939

    40-
    export function deactivate() {
    40+
    export function deactivate(): void {
    4141
    leetCodeStatusBarItem.dispose();
    4242
    }

    src/leetCodeExplorer.ts

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -8,7 +8,7 @@ import { ProblemState } from "./shared";
    88

    99
    // tslint:disable:max-classes-per-file
    1010
    export class LeetCodeNode {
    11-
    constructor(private data: list.IProblem, private isProblemNode = true) { }
    11+
    constructor(private data: list.IProblem, private isProblemNode: boolean = true) { }
    1212

    1313
    public get locked(): boolean {
    1414
    return this.data.locked;

    src/leetCodeManager.ts

    Lines changed: 3 additions & 3 deletions
    Original file line numberDiff line numberDiff line change
    @@ -29,7 +29,7 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager {
    2929

    3030
    public async getLoginStatus(channel: vscode.OutputChannel): Promise<void> {
    3131
    try {
    32-
    const result = await executeCommand(channel, "node", [leetCodeBinaryPath, "user"]);
    32+
    const result: string = await executeCommand(channel, "node", [leetCodeBinaryPath, "user"]);
    3333
    this.currentUser = result.slice("You are now login as".length).trim();
    3434
    this.userStatus = UserStatus.SignedIn;
    3535
    } catch (error) {
    @@ -60,7 +60,7 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager {
    6060
    childProc.on("error", reject);
    6161
    const name: string | undefined = await vscode.window.showInputBox({
    6262
    prompt: "Enter user name.",
    63-
    validateInput: (s: string) => s && s.trim() ? undefined : "User name must not be empty",
    63+
    validateInput: (s: string): string | undefined => s && s.trim() ? undefined : "User name must not be empty",
    6464
    });
    6565
    if (!name) {
    6666
    childProc.kill();
    @@ -70,7 +70,7 @@ class LeetCodeManager extends EventEmitter implements ILeetCodeManager {
    7070
    const pwd: string | undefined =< 10000 /span> await vscode.window.showInputBox({
    7171
    prompt: "Enter password.",
    7272
    password: true,
    73-
    validateInput: (s: string) => s ? undefined : "Password must not be empty",
    73+
    validateInput: (s: string): string | undefined => s ? undefined : "Password must not be empty",
    7474
    });
    7575
    if (!pwd) {
    7676
    childProc.kill();

    src/shared.ts

    Lines changed: 2 additions & 2 deletions
    Original file line numberDiff line numberDiff line change
    @@ -4,7 +4,7 @@ import * as path from "path";
    44
    import * as vscode from "vscode";
    55
    import * as wsl from "./utils/wslUtils";
    66

    7-
    let binPath = path.join(__dirname, "..", "..", "node_modules", "leetcode-cli", "bin", "leetcode");
    7+
    let binPath: string = path.join(__dirname, "..", "..", "node_modules", "leetcode-cli", "bin", "leetcode");
    88

    99
    if (wsl.useWsl()) {
    1010
    binPath = wsl.toWslPath(binPath);
    @@ -21,7 +21,7 @@ export enum UserStatus {
    2121
    SignedOut = 2,
    2222
    }
    2323

    24-
    export const languages = [
    24+
    export const languages: string[] = [
    2525
    "bash",
    2626
    "c",
    2727
    "cpp",

    src/utils/nodeUtils.ts

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -10,7 +10,7 @@ export async function isNodeInstalled(channel: vscode.OutputChannel): Promise<bo
    1010
    await executeCommand(channel, "node", ["-v"]);
    1111
    return true;
    1212
    } catch (error) {
    13-
    const choice = await vscode.window.showErrorMessage(
    13+
    const choice: vscode.MessageItem | undefined = await vscode.window.showErrorMessage(
    1414
    "LeetCode extension need Node.js installed in environment path",
    1515
    DialogOptions.open,
    1616
    );

    src/utils/uiUtils.ts

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -36,7 +36,7 @@ export async function promptForOpenOutputChannel(message: string, type: DialogTy
    3636
    }
    3737

    3838
    export async function promptForSignIn(): Promise<void> {
    39-
    const choice = await vscode.window.showInformationMessage(
    39+
    const choice: vscode.MessageItem | undefined = await vscode.window.showInformationMessage(
    4040
    "Please sign in to LeetCode.",
    4141
    DialogOptions.yes,
    4242
    DialogOptions.no,

    src/utils/workspaceUtils.ts

    Lines changed: 1 addition & 1 deletion
    Original file line numberDiff line numberDiff line change
    @@ -17,7 +17,7 @@ export async function selectWorkspaceFolder(): Promise<string> {
    1717
    }
    1818
    }
    1919

    20-
    const workFolder = folder ? folder.uri.fsPath : path.join(os.homedir(), ".leetcode");
    20+
    const workFolder: string = folder ? folder.uri.fsPath : path.join(os.homedir(), ".leetcode");
    2121

    2222
    return wsl.useWsl() ? wsl.toWslPath(workFolder) : workFolder;
    2323
    }

    0 commit comments

    Comments
     (0)
    0