Skip to content
This repository has been archived by the owner on Jul 18, 2022. It is now read-only.

Commit

Permalink
all eslint rules tackled
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronpowell committed Jul 2, 2019
1 parent 1398af0 commit efc4eb6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 30 deletions.
4 changes: 4 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,9 @@
],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/no-parameter-properties": "off"
}
}
4 changes: 2 additions & 2 deletions src/commands.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
enum Commands {
enum ContributedCommands {
SelectProfile = "extension.selectProfile",
SaveProfile = "extension.saveProfile",
DeleteProfile = "extension.deleteProfile"
}

export default Commands;
export default ContributedCommands;
8 changes: 4 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
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) {
let settingsHelper = new SettingsHelper(context);
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) {
Expand All @@ -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(
Expand Down Expand Up @@ -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) {
Expand Down
18 changes: 12 additions & 6 deletions src/services/config.ts
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 3 additions & 2 deletions src/settingsHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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(""));
Expand Down Expand Up @@ -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);
Expand Down
36 changes: 20 additions & 16 deletions src/test/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint @typescript-eslint/no-explicit-any: "off" */
import { assert } from "chai";
import * as vscode from "vscode";
import {
Expand All @@ -16,9 +17,9 @@ suite("basic extension tests", () => {
});

test("extension can activate", done => {
const extension = <vscode.Extension<any>>(
vscode.extensions.getExtension(ExtensionId)
);
const extension = vscode.extensions.getExtension(
ExtensionId
) as vscode.Extension<any>;

setTimeout(() => {
assert.isTrue(extension.isActive);
Expand Down Expand Up @@ -188,29 +189,32 @@ suite("end to end testing", () => {
};

class MockMemento implements vscode.Memento {
get<T>(key: string): T | undefined;
get<T>(key: string, defaultValue: T): T;
get(key: any, defaultValue?: any) {
public get<T>(key: string): T | undefined;
public get<T>(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<void> {
public update(key: string, value: any): Thenable<void> {
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 = "";
Expand Down

0 comments on commit efc4eb6

Please # to comment.