Skip to content

Commit

Permalink
Enable prettier
Browse files Browse the repository at this point in the history
Enables the prettier rules on eslint.
Fixes the prettier errors.
Updates prettier dependency to 2.0
  • Loading branch information
gorkem authored and joshuawilson committed May 26, 2020
1 parent 34a8970 commit 5643233
Show file tree
Hide file tree
Showing 26 changed files with 144 additions and 233 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@
"object-shorthand": ["error", "properties"],
"prefer-const": ["error", { "destructuring": "all" }],
"prefer-template": 2,
"prettier/prettier": "error",
"radix": 2
},
"settings": {
Expand Down
3 changes: 2 additions & 1 deletion .prettierrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
"arrowParens": "always",
"printWidth": 130,
"singleQuote": true,
"trailingComma": "all"
"trailingComma": "all",
"endOfLine": "auto"
}
9 changes: 1 addition & 8 deletions build/install-vscode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,7 @@ import { platform } from 'os';
downloadAndUnzipVSCode().then((executable: string): void => {
let exe: string = executable;
if (platform() === 'darwin') {
exe = `'${join(
exe.substring(0, exe.indexOf('.app') + 4),
'Contents',
'Resources',
'app',
'bin',
'code',
)}'`;
exe = `'${join(exe.substring(0, exe.indexOf('.app') + 4), 'Contents', 'Resources', 'app', 'bin', 'code')}'`;
} else {
exe = join(dirname(exe), 'bin', 'code');
}
Expand Down
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"eslint-plugin-prettier": "^3.1.2",
"istanbul": "^0.4.5",
"mocha-jenkins-reporter": "^0.4.2",
"prettier": "^1.19.1",
"prettier": "^2.0.5",
"remap-istanbul": "^0.13.0",
"sinon": "^9.0.1",
"sinon-chai": "^3.5.0",
Expand Down
4 changes: 2 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import { vfsUri, KnativeResourceVirtualFileSystemProvider, KN_RESOURCE_SCHEME }
* @param treeItem
*/
export function openInEditor(treeItem: KnativeTreeItem): void {
const {contextValue} = treeItem;
const { contextValue } = treeItem;
const name: string = treeItem.getName();
const outputFormat = vscode.workspace.getConfiguration('vs-knative')['vs-knative.outputFormat'];
const uri = vfsUri(contextValue, name, outputFormat);
Expand All @@ -39,7 +39,7 @@ export function activate(extensionContext: vscode.ExtensionContext): void {
const resourceDocProvider = new KnativeResourceVirtualFileSystemProvider();
// 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.
// The commandId parameter must match the command field in package.json.
const disposable = [
vscode.commands.registerCommand('knative.service.open-in-browser', (treeItem: KnativeTreeItem) => {
const service = treeItem.getKnativeItem() as Service;
Expand Down
2 changes: 1 addition & 1 deletion src/kn/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { Uri, workspace } from 'vscode';

const EXTENSION_CONFIG_KEY = "vs-knative";
const EXTENSION_CONFIG_KEY = 'vs-knative';

export const enum Kind {
LocalConfig,
Expand Down
9 changes: 5 additions & 4 deletions src/kn/kn-api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ export class KnAPI {
// Set up the initial values for the command.
const commandArguments: string[] = ['service', 'create'];
// check if --force was set
if (createServiceObj.force) {commandArguments.push('--force');}
if (createServiceObj.force) {
commandArguments.push('--force');
}
// It should always have a name value.
commandArguments.push(createServiceObj.name);
// If the port was set, use it.
Expand Down Expand Up @@ -133,7 +135,7 @@ export class KnAPI {
/**
* Return the list of all Knative Revisions in JSON format in the current namespace.
*/
static listRevisionsForService(service: string ): CliCommand {
static listRevisionsForService(service: string): CliCommand {
const a = ['revision', 'list', '-o', 'json', '-s', service];
return newKnCommand(a);
}
Expand All @@ -149,12 +151,11 @@ export class KnAPI {
/**
* Return the list of all Knative routes in JSON format in the current namespace.
*/
static listRoutesForService(service: string ): CliCommand {
static listRoutesForService(service: string): CliCommand {
const a = ['route', 'list', service, '-o', 'json'];
return newKnCommand(a);
}


static printKnVersion(): CliCommand {
return newKnCommand(['version']);
}
Expand Down
35 changes: 7 additions & 28 deletions src/kn/kn-cli-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,7 @@ async function getVersion(location: string): Promise<string> {
* @param locations
* @param versionRange
*/
async function selectTool(
locations: string[],
versionRange: string,
versionLocalBuildRange: number,
): Promise<string> {
async function selectTool(locations: string[], versionRange: string, versionLocalBuildRange: number): Promise<string> {
let foundLocation: string;
// Check the version of the cli to make sure it matches what we coded against.
try {
Expand All @@ -113,10 +109,7 @@ async function selectTool(
const locationsVersion: string = await getVersion(location);

// Check if the version is a local build after a certain date or matches the given vesion range for releases version.
if (
Number(locationsVersion) > versionLocalBuildRange ||
satisfies(locationsVersion, versionRange)
) {
if (Number(locationsVersion) > versionLocalBuildRange || satisfies(locationsVersion, versionRange)) {
foundLocation = location;
break;
}
Expand Down Expand Up @@ -175,18 +168,11 @@ export class KnCliConfig {
// So if the tool location hasn't been set then we need to figure that out.
if (toolLocation === undefined) {
// Look in [HOME]/.vs-kn/ for the kn cli executable
const toolCacheLocation = path.resolve(
Platform.getUserHomePath(),
'.vs-kn',
KnCliConfig.tools[cmd].cmdFileName,
);
const toolCacheLocation = path.resolve(Platform.getUserHomePath(), '.vs-kn', KnCliConfig.tools[cmd].cmdFileName);
// If kn cli is installed, get it's install location/path
const whichLocation = which(cmd);
// Get a list of locations.
const toolLocations: string[] = [
whichLocation ? whichLocation.stdout : null,
toolCacheLocation,
];
const toolLocations: string[] = [whichLocation ? whichLocation.stdout : null, toolCacheLocation];
// Check the list of locations and see if what we need is there.
// selectTool(toolLocations, KnCliConfig.tools[cmd].versionRange).then((foundToolLocation) => {
let foundToolLocation: string = await selectTool(
Expand All @@ -197,11 +183,7 @@ export class KnCliConfig {
// If the cli tool is still not found then we will need to install it.
if (foundToolLocation === undefined || foundToolLocation === null) {
// Set the download location for the cli executable.
const toolDlLocation = path.resolve(
Platform.getUserHomePath(),
'.vs-kn',
KnCliConfig.tools[cmd].dlFileName,
);
const toolDlLocation = path.resolve(Platform.getUserHomePath(), '.vs-kn', KnCliConfig.tools[cmd].dlFileName);
// Message for expected version number
const installRequest = `Download and install v${KnCliConfig.tools[cmd].version}`;
// Create a pop-up that asks to download and install.
Expand Down Expand Up @@ -231,8 +213,7 @@ export class KnCliConfig {
KnCliConfig.tools[cmd].url,
toolDlLocation,
// token,
(dlProgress, increment) =>
progress.report({ increment, message: `${dlProgress}%` }),
(dlProgress, increment) => progress.report({ increment, message: `${dlProgress}%` }),
);

// Get the hash for the downloaded file.
Expand Down Expand Up @@ -269,9 +250,7 @@ export class KnCliConfig {
} else if (response === `Help`) {
commands.executeCommand(
'vscode.open',
Uri.parse(
`https://github.com/talamer/vscode-knative/blob/master/README.md#requirements`,
),
Uri.parse(`https://github.com/talamer/vscode-knative/blob/master/README.md#requirements`),
);
}
}
Expand Down
12 changes: 2 additions & 10 deletions src/kn/knCli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,10 @@ export class KnCli implements Cli {
kn.on('exit', () => {
if (error) {
if (typeof error === 'string' && error.search('no such host') > 0) {
window.showErrorMessage(
`The cluster is not up. Please log into a running cluster.`,
{ modal: true },
'OK',
);
window.showErrorMessage(`The cluster is not up. Please log into a running cluster.`, { modal: true }, 'OK');
}
if (typeof error === 'string' && error.search('no configuration') > 0) {
window.showErrorMessage(
`The kubeconfig file can't be found.`,
{ modal: true },
'OK',
);
window.showErrorMessage(`The kubeconfig file can't be found.`, { modal: true }, 'OK');
}
if (typeof error === 'string' && error.search('no Knative') > 0) {
window.showErrorMessage(
Expand Down
6 changes: 4 additions & 2 deletions src/knative/createUserItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import { QuickPickItem } from 'vscode';

export class CreateUserItem implements QuickPickItem {
// eslint-disable-next-line class-methods-use-this
get label(): string { return `$(plus) Add new user...`; }
// eslint-disable-next-line class-methods-use-this
get label(): string {
return `$(plus) Add new user...`;
}
}
5 changes: 1 addition & 4 deletions src/knative/knativeItem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,4 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/


export class KnativeItem {

}
export class KnativeItem {}
20 changes: 10 additions & 10 deletions src/knative/knativeServices.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import { Service } from './service';
import { Revision } from './revision';
// import { compareNodes } from '../kn/knativeTreeObject';

type revisionService = {revision: Revision, service: Service};
type revisionServiceIndex = {revisionIndex?: number, serviceIndex?: number};
type revisionService = { revision: Revision; service: Service };
type revisionServiceIndex = { revisionIndex?: number; serviceIndex?: number };

export class KnativeServices {
private static instance: KnativeServices;
Expand Down Expand Up @@ -46,8 +46,8 @@ export class KnativeServices {

this.services.find((s: Service) => {
revision = s.revisions.find((r: Revision) => r.name === revisionName);
return revision.name === revisionName
})
return revision.name === revisionName;
});

return revision;
}
Expand All @@ -57,10 +57,10 @@ export class KnativeServices {

const service: Service = this.services.find((s: Service) => {
revision = s.revisions.find((r: Revision) => r.name === revisionName);
return revision.name === revisionName
})
return revision.name === revisionName;
});

const rs: revisionService = {revision, service};
const rs: revisionService = { revision, service };
return rs;
}

Expand All @@ -70,10 +70,10 @@ export class KnativeServices {
const serviceIndex: number = this.services.findIndex((s: Service) => {
const revision: Revision = s.revisions.find((r: Revision) => r.name === revisionName);
revisionIndex = s.revisions.findIndex((r: Revision) => r.name === revisionName);
return revision.name === revisionName
})
return revision.name === revisionName;
});

const rs: revisionServiceIndex = {revisionIndex, serviceIndex};
const rs: revisionServiceIndex = { revisionIndex, serviceIndex };
return rs;
}

Expand Down
4 changes: 2 additions & 2 deletions src/knative/quickPickCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* Licensed under the MIT License. See LICENSE file in the project root for license information.
*-----------------------------------------------------------------------------------------------*/

import { QuickPickItem } from "vscode";
import { QuickPickItem } from 'vscode';

export class QuickPickCommand implements QuickPickItem {
// eslint-disable-next-line no-useless-constructor
Expand All @@ -14,6 +14,6 @@ export class QuickPickCommand implements QuickPickItem {
public detail?: string,
public picked?: boolean,
public alwaysShow?: boolean,
public getName?: () => string
public getName?: () => string,
) {}
}
2 changes: 1 addition & 1 deletion src/knative/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export abstract class Validation {
}

static lengthName(message: string, value: string, offset: number): string {
return validator.isLength(value, {min:2, max: 63 - offset}) ? null : message;
return validator.isLength(value, { min: 2, max: 63 - offset }) ? null : message;
}

static validateUrl(message: string, value: string): string {
Expand Down
16 changes: 2 additions & 14 deletions src/tree/serviceDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,7 @@ export class ServiceDataProvider implements TreeDataProvider<KnativeTreeItem> {
// Create an empty state message when there is no Service.
if (services.length === 0) {
return [
new KnativeTreeItem(
null,
null,
'No Service Found',
ContextType.SERVICE,
TreeItemCollapsibleState.Collapsed,
null,
null,
),
new KnativeTreeItem(null, null, 'No Service Found', ContextType.SERVICE, TreeItemCollapsibleState.Collapsed, null, null),
];
}
// Convert the fetch Services into TreeItems
Expand All @@ -154,11 +146,7 @@ export class ServiceDataProvider implements TreeDataProvider<KnativeTreeItem> {
}

public async deleteFeature(node: KnativeTreeItem): Promise<void> {
const response = await window.showInformationMessage(
`Please confirm deletion.`,
{ modal: true },
'Delete',
);
const response = await window.showInformationMessage(`Please confirm deletion.`, { modal: true }, 'Delete');
if (response === 'Delete') {
await this.knExecutor.execute(KnAPI.deleteFeature(node.contextValue, node.getName()));
this.refresh();
Expand Down
17 changes: 10 additions & 7 deletions src/tree/serviceExplorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ const kubeConfigFolder: string = path.join(Platform.getUserHomePath(), '.kube');
const kubeconfigEnv: string = process.env.KUBECONFIG;
let kubeconfigList: string[] = [];
// check to make sure there is an ENV for KUBECONFIG
if (kubeconfigEnv) {kubeconfigList = kubeconfigEnv.split(path.delimiter);}
if (kubeconfigEnv) {
kubeconfigList = kubeconfigEnv.split(path.delimiter);
}
const kubeconfigParam: string[][] = [[kubeConfigFolder, 'config']];
kubeconfigList.forEach((value): void => {
const kubeconfigSplit: string[] = value.split(path.sep);
const kubeconfigFileName: string = kubeconfigSplit.pop();
const kubeconfigDir: string = kubeconfigSplit.join(path.sep);
kubeconfigParam.push([kubeconfigDir, kubeconfigFileName])
})
kubeconfigParam.push([kubeconfigDir, kubeconfigFileName]);
});

function issueUrl(): string {
const { packageJSON } = extensions.getExtension('redhat.vscode-knative');
Expand All @@ -34,7 +36,6 @@ async function reportIssue(): Promise<unknown> {
return commands.executeCommand('vscode.open', Uri.parse(issueUrl()));
}


export class ServiceExplorer implements Disposable {
private treeView: TreeView<KnativeTreeItem>;

Expand All @@ -44,8 +45,8 @@ export class ServiceExplorer implements Disposable {
const treeDataProvider = new ServiceDataProvider();
kubeconfigParam.forEach((params) => {
const l = this.fsw.push(WatchUtil.watchFileForContextChange(params[0], params[1]));
this.fsw[l -1].emitter.on('file-changed', ()=>treeDataProvider.refresh());
})
this.fsw[l - 1].emitter.on('file-changed', () => treeDataProvider.refresh());
});

// Initialize the tree/explorer view by linking the refernece in the package.json to this class.
this.treeView = window.createTreeView('knativeProjectExplorerServices', { treeDataProvider });
Expand All @@ -58,7 +59,9 @@ export class ServiceExplorer implements Disposable {

dispose(): void {
// this.fsw.watcher.close();
this.fsw.forEach((value) => {value.watcher.close();})
this.fsw.forEach((value) => {
value.watcher.close();
});
this.treeView.dispose();
}

Expand Down
Loading

0 comments on commit 5643233

Please sign in to comment.