Skip to content

Commit

Permalink
prettier, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tinahollygb committed Oct 6, 2022
1 parent 2248846 commit 1ad341c
Show file tree
Hide file tree
Showing 12 changed files with 802 additions and 163 deletions.
61 changes: 38 additions & 23 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,39 @@
{
"root": true,
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
"@typescript-eslint/naming-convention": "warn",
"@typescript-eslint/semi": "warn",
"curly": "warn",
"eqeqeq": "warn",
"no-throw-literal": "warn",
"semi": "off"
},
"ignorePatterns": [
"out",
"dist",
"**/*.d.ts"
]
}
"env": {
"node": true,
"es6": true,
"browser": true,
"es2021": true
},
"settings": {
"import/core-modules": ["vscode"]
},
"extends": [
"plugin:import/recommended",
"plugin:import/typescript",
"eslint:recommended",
"plugin:prettier/recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"overrides": [
{
"files": [
"**/*.ts"
],
"rules": {
"@typescript-eslint/no-empty-function": "off"
}
}
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": [
"@typescript-eslint"
],
"rules": {
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ dist
node_modules
.vscode-test/
*.vsix
.eslintcache
4 changes: 4 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
.vscode
out
resources
16 changes: 10 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"onCommand:growthbook.helloWorld"
],
"main": "./out/extension.js",

"contributes": {
"views": {
"explorer": [
Expand All @@ -36,22 +35,27 @@
"compile": "tsc -p ./",
"watch": "tsc -watch -p ./",
"pretest": "yarn run compile && yarn run lint",
"lint": "eslint src --ext ts",
"lint": "eslint src --ext ts --fix --cache --cache-strategy content",
"lint:ci": "yarn lint -- --max-warnings 0",
"test": "node ./out/test/runTest.js"
},
"devDependencies": {
"@types/glob": "^8.0.0",
"@types/mocha": "^10.0.0",
"@types/node": "16.x",
"@types/vscode": "^1.71.0",
"@typescript-eslint/eslint-plugin": "^5.38.1",
"@typescript-eslint/parser": "^5.38.1",
"@typescript-eslint/eslint-plugin": "^5.39.0",
"@typescript-eslint/parser": "^5.39.0",
"@vscode/test-electron": "^2.1.5",
"eslint": "^8.24.0",
"eslint-config-prettier": "^8.5.0",
"eslint-import-resolver-typescript": "^3.5.1",
"eslint-plugin-import": "^2.26.0",
"eslint-plugin-prettier": "^4.2.1",
"glob": "^8.0.3",
"mocha": "^10.0.0",
"prettier": "^2.7.1",
"typescript": "^4.8.4"
},
"dependencies": {
}
"dependencies": {}
}
104 changes: 53 additions & 51 deletions src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,60 +1,62 @@
// The module 'vscode' contains the VS Code extensibility API
// Import the module and reference it with the alias vscode in your code below
import * as vscode from 'vscode';
import { FeatureListTreeDataProvider } from './features/FeatureListTreeDataProvider';
import { FeatureDefinition } from './features/types';
import * as vscode from "vscode";
import { FeatureListTreeDataProvider } from "./features/FeatureListTreeDataProvider";
import { FeatureDefinition } from "./features/types";

// This method is called when your extension is activated
// Your extension is activated the very first time the command is executed
export function activate(context: vscode.ExtensionContext) {

// Register the tree view
const rootPath = vscode.workspace.workspaceFolders && vscode.workspace.workspaceFolders.length > 0
? vscode.workspace.workspaceFolders[0].uri.fsPath
: undefined;

console.log('rootPath', rootPath);

// TODO: Remove mock features
const features: FeatureDefinition[] = [];
for (let i = 1; i <= 10; i++) {
features.push({
id: `feature_number_${i}`,
description: `This is a description of the feature at index ${i}`,
valueType: 'boolean'
});
}


if (rootPath) {
vscode.window.registerTreeDataProvider(
'featuresList',
new FeatureListTreeDataProvider(context, features)
);

const treeView = vscode.window.createTreeView('featuresList', {
treeDataProvider: new FeatureListTreeDataProvider(context, features)
});

context.subscriptions.push(treeView);
}


// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log('Congratulations, your extension "growthbook" is now active!');

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
let disposable = vscode.commands.registerCommand('growthbook.helloWorld', () => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage('Hello World from growthbook!');
});

context.subscriptions.push(disposable);
// Register the tree view
const rootPath =
vscode.workspace.workspaceFolders &&
vscode.workspace.workspaceFolders.length > 0
? vscode.workspace.workspaceFolders[0].uri.fsPath
: undefined;

console.log("rootPath", rootPath);

// TODO: Remove mock features
const features: FeatureDefinition[] = [];
for (let i = 1; i <= 10; i++) {
features.push({
id: `feature_number_${i}`,
description: `This is a description of the feature at index ${i}`,
valueType: "boolean",
});
}

if (rootPath) {
vscode.window.registerTreeDataProvider(
"featuresList",
new FeatureListTreeDataProvider(context, features)
);

const treeView = vscode.window.createTreeView("featuresList", {
treeDataProvider: new FeatureListTreeDataProvider(context, features),
});

context.subscriptions.push(treeView);
}

// Use the console to output diagnostic information (console.log) and errors (console.error)
// This line of code will only be executed once when your extension is activated
console.log("Congratulations, your extension 'growthbook' is now active!");

// The command has been defined in the package.json file
// Now provide the implementation of the command with registerCommand
// The commandId parameter must match the command field in package.json
const disposable = vscode.commands.registerCommand(
"growthbook.helloWorld",
() => {
// The code you place here will be executed every time your command is executed
// Display a message box to the user
vscode.window.showInformationMessage("Hello World from growthbook!");
}
);

context.subscriptions.push(disposable);
}

// This method is called when your extension is deactivated
export function deactivate() { }
export function deactivate() {}
54 changes: 37 additions & 17 deletions src/features/FeatureListTreeDataProvider.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,49 @@
import * as Path from 'path';
import * as Fs from 'fs';
import { CancellationToken, Event, ExtensionContext, ProviderResult, TreeDataProvider, TreeItem, TreeItemCollapsibleState } from "vscode";
import * as Fs from "fs";
import * as Path from "path";
import {
Event,
ExtensionContext,
ProviderResult,
TreeDataProvider,
TreeItem,
TreeItemCollapsibleState,
} from "vscode";
import { FeatureDefinition } from "./types";

/**
* This class helps populate the tree view
*/
export class FeatureListTreeDataProvider implements TreeDataProvider<FeatureListTreeItem> {
export class FeatureListTreeDataProvider
implements TreeDataProvider<FeatureListTreeItem>
{
constructor(
private context: ExtensionContext,
private features: FeatureDefinition[]
) {
}
) {}

onDidChangeTreeData?: Event<void | FeatureListTreeItem | FeatureListTreeItem[] | null | undefined> | undefined;
onDidChangeTreeData?:
| Event<
void | FeatureListTreeItem | FeatureListTreeItem[] | null | undefined
>
| undefined;

getTreeItem(element: FeatureListTreeItem): TreeItem | Thenable<TreeItem> {
console.log('returning element', element);
console.log("returning element", element);
return element;
}
getChildren(element?: FeatureListTreeItem | undefined): ProviderResult<FeatureListTreeItem[]> {
const treeItems = this.features
.map((feature) => (
new FeatureListTreeItem(feature.id, feature, TreeItemCollapsibleState.None)
));

// TODO: Do we need this element??
getChildren(
element?: FeatureListTreeItem | undefined
): ProviderResult<FeatureListTreeItem[]> {
const treeItems = this.features.map(
(feature) =>
new FeatureListTreeItem(
feature.id,
feature,
TreeItemCollapsibleState.None
)
);

return Promise.resolve(treeItems);
}
Expand Down Expand Up @@ -51,12 +71,12 @@ class FeatureListTreeItem extends TreeItem {
public readonly collapsibleState: TreeItemCollapsibleState
) {
super(label, collapsibleState);
this.tooltip = this.feature.description || '';
this.tooltip = this.feature.description || "";
this.description = this.feature.valueType;
}

iconPath = {
light: Path.join(__filename, '..', '..', '..', 'resources', 'ic_flag.svg'),
dark: Path.join(__filename, '..', '..', '..', 'resources', 'ic_flag.svg')
light: Path.join(__filename, "..", "..", "..", "resources", "ic_flag.svg"),
dark: Path.join(__filename, "..", "..", "..", "resources", "ic_flag.svg"),
};
}
}
5 changes: 0 additions & 5 deletions src/features/types.d.ts

This file was deleted.

5 changes: 5 additions & 0 deletions src/features/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export type FeatureDefinition = {
id: string;
description: string;
valueType: string;
};
30 changes: 15 additions & 15 deletions src/test/runTest.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import * as path from 'path';
import * as path from "path";

import { runTests } from '@vscode/test-electron';
import { runTests } from "@vscode/test-electron";

async function main() {
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, '../../');
try {
// The folder containing the Extension Manifest package.json
// Passed to `--extensionDevelopmentPath`
const extensionDevelopmentPath = path.resolve(__dirname, "../../");

// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, './suite/index');
// The path to test runner
// Passed to --extensionTestsPath
const extensionTestsPath = path.resolve(__dirname, "./suite/index");

// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error('Failed to run tests');
process.exit(1);
}
// Download VS Code, unzip it and run the integration test
await runTests({ extensionDevelopmentPath, extensionTestsPath });
} catch (err) {
console.error("Failed to run tests");
process.exit(1);
}
}

main();
16 changes: 8 additions & 8 deletions src/test/suite/extension.test.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import * as assert from 'assert';
import * as assert from "assert";

// You can import and use all API from the 'vscode' module
// as well as import your extension to test it
import * as vscode from 'vscode';
import * as vscode from "vscode";
// import * as myExtension from '../../extension';

suite('Extension Test Suite', () => {
vscode.window.showInformationMessage('Start all tests.');
suite("Extension Test Suite", () => {
vscode.window.showInformationMessage("Start all tests.");

test('Sample test', () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
test("Sample test", () => {
assert.strictEqual(-1, [1, 2, 3].indexOf(5));
assert.strictEqual(-1, [1, 2, 3].indexOf(0));
});
});
Loading

0 comments on commit 1ad341c

Please sign in to comment.