From efc4eb67e8f40eedbd1d5a03ec9950757d7f5f98 Mon Sep 17 00:00:00 2001 From: Aaron Powell Date: Tue, 2 Jul 2019 10:52:51 +1000 Subject: [PATCH] all eslint rules tackled --- .eslintrc | 4 ++++ src/commands.ts | 4 ++-- src/extension.ts | 8 ++++---- src/services/config.ts | 18 ++++++++++++------ src/settingsHelper.ts | 5 +++-- src/test/extension.test.ts | 36 ++++++++++++++++++++---------------- 6 files changed, 45 insertions(+), 30 deletions(-) diff --git a/.eslintrc b/.eslintrc index 652e762..8843e14 100755 --- a/.eslintrc +++ b/.eslintrc @@ -8,5 +8,9 @@ ], "parserOptions": { "project": "./tsconfig.json" + }, + "rules": { + "@typescript-eslint/explicit-function-return-type": "off", + "@typescript-eslint/no-parameter-properties": "off" } } diff --git a/src/commands.ts b/src/commands.ts index 30e3aaa..fe18f11 100755 --- a/src/commands.ts +++ b/src/commands.ts @@ -1,7 +1,7 @@ -enum Commands { +enum ContributedCommands { SelectProfile = "extension.selectProfile", SaveProfile = "extension.saveProfile", DeleteProfile = "extension.deleteProfile" } -export default Commands; +export default ContributedCommands; diff --git a/src/extension.ts b/src/extension.ts index d0099b4..860861a 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,6 +1,6 @@ import * as vscode from "vscode"; import SettingsHelper from "./settingsHelper"; -import Commands from "./commands"; +import ContributedCommands from "./commands"; import Config from "./services/config"; export async function activate(context: vscode.ExtensionContext) { @@ -8,7 +8,7 @@ export async function activate(context: vscode.ExtensionContext) { let config = new Config(); context.subscriptions.push( - vscode.commands.registerCommand(Commands.SelectProfile, async () => { + vscode.commands.registerCommand(ContributedCommands.SelectProfile, async () => { let profiles = config.getProfiles(); if (!profiles.length) { @@ -33,7 +33,7 @@ export async function activate(context: vscode.ExtensionContext) { ); context.subscriptions.push( - vscode.commands.registerCommand(Commands.SaveProfile, async () => { + vscode.commands.registerCommand(ContributedCommands.SaveProfile, async () => { let profiles = config.getProfiles(); let profile = await vscode.window.showQuickPick( @@ -65,7 +65,7 @@ export async function activate(context: vscode.ExtensionContext) { ); context.subscriptions.push( - vscode.commands.registerCommand(Commands.DeleteProfile, async () => { + vscode.commands.registerCommand(ContributedCommands.DeleteProfile, async () => { let profiles = config.getProfiles(); if (!profiles.length) { diff --git a/src/services/config.ts b/src/services/config.ts index b6ef996..1e5c772 100755 --- a/src/services/config.ts +++ b/src/services/config.ts @@ -1,7 +1,13 @@ import * as vscode from "vscode"; import { ConfigKey, ConfigProfilesKey, ConfigStorageKey } from "../constants"; -interface Storage { [key: string]: any } +export interface Settings { + [key: string]: number | string | boolean | object; +} + +export interface Storage { + [key: string]: Settings; +} class Config { private getConfig() { @@ -51,14 +57,14 @@ class Config { ); } - public addProfileSettings(profile: string, settings: any) { + public addProfileSettings(profile: string, settings: Settings) { // We don't want to save profile info in the profile storage - if (settings["profileSwitcher.profiles"]) { - delete settings["profileSwitcher.profiles"]; + if (settings[`${ConfigKey}:${ConfigProfilesKey}`]) { + delete settings[`${ConfigKey}:${ConfigProfilesKey}`]; } - if (settings["profileSwitcher.storage"]) { - delete settings["profileSwitcher.storage"]; + if (settings[`${ConfigKey}:${ConfigStorageKey}`]) { + delete settings[`${ConfigKey}:${ConfigStorageKey}`]; } let storage = this.getStorage(); diff --git a/src/settingsHelper.ts b/src/settingsHelper.ts index d68d624..a931bdc 100755 --- a/src/settingsHelper.ts +++ b/src/settingsHelper.ts @@ -2,6 +2,7 @@ import * as fs from "fs-extra"; import * as vscode from "vscode"; import * as os from "os"; import * as path from "path"; +import { Settings } from "./services/config"; export enum OsType { Windows = 1, @@ -19,7 +20,7 @@ export default class SettingsHelper { public PATH: string = ""; public OsType: OsType = OsType.Windows; - constructor(private context: vscode.ExtensionContext) { + public constructor(private context: vscode.ExtensionContext) { this.isInsiders = /insiders/.test(this.context.asAbsolutePath("")); this.isPortable = process.env.VSCODE_PORTABLE ? true : false; this.isOss = /\boss\b/.test(this.context.asAbsolutePath("")); @@ -104,7 +105,7 @@ export default class SettingsHelper { return await fs.readJSON(settingsPath, { encoding: "utf8" }); } - public async updateUserSettings(update: any) { + public async updateUserSettings(update: Settings) { let existingSettings = await this.getUserSettings(); let newSettings = Object.assign({}, existingSettings, update); diff --git a/src/test/extension.test.ts b/src/test/extension.test.ts index 33369f6..d934a9a 100644 --- a/src/test/extension.test.ts +++ b/src/test/extension.test.ts @@ -1,3 +1,4 @@ +/* eslint @typescript-eslint/no-explicit-any: "off" */ import { assert } from "chai"; import * as vscode from "vscode"; import { @@ -16,9 +17,9 @@ suite("basic extension tests", () => { }); test("extension can activate", done => { - const extension = >( - vscode.extensions.getExtension(ExtensionId) - ); + const extension = vscode.extensions.getExtension( + ExtensionId + ) as vscode.Extension; setTimeout(() => { assert.isTrue(extension.isActive); @@ -188,29 +189,32 @@ suite("end to end testing", () => { }; class MockMemento implements vscode.Memento { - get(key: string): T | undefined; - get(key: string, defaultValue: T): T; - get(key: any, defaultValue?: any) { + public get(key: string): T | undefined; + public get(key: string, defaultValue: T): T; + public get(key: any, defaultValue?: any) { + console.log(`${key}:${defaultValue}`); throw new Error("Method not implemented."); } - update(key: string, value: any): Thenable { + public update(key: string, value: any): Thenable { + console.log(`${key}:${value}`); throw new Error("Method not implemented."); } } class MockContext implements vscode.ExtensionContext { - subscriptions: { dispose(): any }[]; - workspaceState: vscode.Memento; - globalState: vscode.Memento; - extensionPath: string; - asAbsolutePath(relativePath: string): string { + public subscriptions: { dispose(): any }[]; + public workspaceState: vscode.Memento; + public globalState: vscode.Memento; + public extensionPath: string; + public asAbsolutePath(relativePath: string): string { + console.log(relativePath); return process.execPath; } - storagePath: string | undefined; - globalStoragePath: string; - logPath: string; + public storagePath: string | undefined; + public globalStoragePath: string; + public logPath: string; - constructor() { + public constructor() { this.subscriptions = []; this.extensionPath = ""; this.globalStoragePath = "";