diff --git a/packages/disposable/src/disposable.ts b/packages/disposable/src/disposable.ts index 273a45adc..4fc3d52d6 100644 --- a/packages/disposable/src/disposable.ts +++ b/packages/disposable/src/disposable.ts @@ -1,5 +1,3 @@ export interface IDisposable { - dispose(): void; - } diff --git a/packages/events/src/events.ts b/packages/events/src/events.ts index 51990272c..907cbf24d 100644 --- a/packages/events/src/events.ts +++ b/packages/events/src/events.ts @@ -8,7 +8,6 @@ export interface Event { * Emitter typecasts for a single event type */ export class Emitter { - private listeners: Array<(e: T) => void> | undefined; public constructor() { @@ -56,5 +55,4 @@ export class Emitter { public get hasListeners(): boolean { return !!this.listeners && this.listeners.length > 0; } - -} \ No newline at end of file +} diff --git a/packages/ide/src/client.ts b/packages/ide/src/client.ts index a189cda3f..5c281c95a 100644 --- a/packages/ide/src/client.ts +++ b/packages/ide/src/client.ts @@ -17,7 +17,6 @@ import { IURIFactory } from "./fill/uri"; * It also provides task management to help asynchronously load and time code. */ export abstract class Client { - public readonly retry = retry; public readonly clipboard = clipboard; public readonly uriFactory: IURIFactory; @@ -191,5 +190,4 @@ export abstract class Client { * Create URI factory. */ protected abstract createUriFactory(): IURIFactory; - } diff --git a/packages/ide/src/fill/client.ts b/packages/ide/src/fill/client.ts index c389348f8..1ae033924 100644 --- a/packages/ide/src/fill/client.ts +++ b/packages/ide/src/fill/client.ts @@ -8,7 +8,6 @@ import { retry } from "../retry"; * messages during connection. */ class Connection implements ReadWriteConnection { - private activeSocket: WebSocket | undefined; private readonly messageEmitter: Emitter = new Emitter(); private readonly closeEmitter: Emitter = new Emitter(); @@ -143,7 +142,6 @@ class Connection implements ReadWriteConnection { this.activeSocket.close(); } } - } // Global instance so all fills can use the same client. diff --git a/packages/ide/src/fill/clipboard.ts b/packages/ide/src/fill/clipboard.ts index eb82f0436..a26be853f 100644 --- a/packages/ide/src/fill/clipboard.ts +++ b/packages/ide/src/fill/clipboard.ts @@ -2,10 +2,9 @@ import { IDisposable } from "@coder/disposable"; import { Emitter } from "@coder/events"; /** - * Native clipboard. + * Wrapper around the native clipboard with some fallbacks. */ export class Clipboard { - private readonly enableEmitter: Emitter = new Emitter(); private _isEnabled: boolean = false; @@ -149,7 +148,6 @@ export class Clipboard { return Promise.resolve(); } - } // Global clipboard instance since it's used in the Electron fill. diff --git a/packages/ide/src/fill/dialog.ts b/packages/ide/src/fill/dialog.ts index 4c2900d4f..3389a863f 100644 --- a/packages/ide/src/fill/dialog.ts +++ b/packages/ide/src/fill/dialog.ts @@ -3,9 +3,6 @@ import { Emitter } from "@coder/events"; import "./dialog.scss"; -/** - * Dialog options. - */ export interface IDialogOptions { message?: string; detail?: string; @@ -24,16 +21,12 @@ export interface IDialogAction { key?: IKey; } -/** - * Pressed keys. - */ export enum IKey { Enter = "Enter", Escape = "Escape", } export class Dialog { - private options: IDialogOptions; private overlay: HTMLElement; private cachedActiveElement: HTMLElement | undefined; @@ -190,5 +183,4 @@ export class Dialog { }); } } - } diff --git a/packages/ide/src/fill/electron.ts b/packages/ide/src/fill/electron.ts index 5c236060f..8ff64aea5 100644 --- a/packages/ide/src/fill/electron.ts +++ b/packages/ide/src/fill/electron.ts @@ -84,7 +84,6 @@ const newCreateElement = (tagName: K): HT document.createElement = newCreateElement; class Clipboard { - public has(): boolean { return false; } @@ -92,21 +91,17 @@ class Clipboard { public writeText(value: string): Promise { return clipboard.writeText(value); } - } class Shell { - public async moveItemToTrash(path: string): Promise { await promisify(exec)( `trash-put --trash-dir ${escapePath("~/.Trash")} ${escapePath(path)}`, ); } - } class App extends EventEmitter { - public isAccessibilitySupportEnabled(): boolean { return false; } @@ -114,11 +109,9 @@ class App extends EventEmitter { public setAsDefaultProtocolClient(): void { throw new Error("not implemented"); } - } class Dialog { - public showSaveDialog(_: void, options: Electron.SaveDialogOptions, callback: (filename: string | undefined) => void): void { const defaultPath = options.defaultPath || "/untitled"; const fileIndex = defaultPath.lastIndexOf("/"); @@ -203,11 +196,9 @@ class Dialog { }); dialog.show(); } - } class WebFrame { - public getZoomFactor(): number { return 1; } @@ -219,19 +210,15 @@ class WebFrame { public setZoomLevel(): void { // Nothing. } - } class Screen { - public getAllDisplays(): [] { return []; } - } class WebRequest extends EventEmitter { - public onBeforeRequest(): void { throw new Error("not implemented"); } @@ -243,28 +230,22 @@ class WebRequest extends EventEmitter { public onHeadersReceived(): void { throw new Error("not implemented"); } - } class Session extends EventEmitter { - public webRequest = new WebRequest(); public resolveProxy(url: string, callback: (proxy: string) => void): void { // TODO: not sure what this actually does. callback(url); } - } class WebContents extends EventEmitter { - public session = new Session(); - } class BrowserWindow extends EventEmitter { - public webContents = new WebContents(); private representedFilename: string = ""; @@ -323,7 +304,6 @@ class BrowserWindow extends EventEmitter { public setTitle(value: string): void { document.title = value; } - } /** @@ -331,7 +311,6 @@ class BrowserWindow extends EventEmitter { * example returns a boolean while we need a promise. */ class ElectronFill { - public readonly shell = new Shell(); public readonly clipboard = new Clipboard(); public readonly app = new App(); @@ -382,7 +361,6 @@ class ElectronFill { }; } // tslint:enable no-any - } module.exports = new ElectronFill(); diff --git a/packages/ide/src/fill/notification.ts b/packages/ide/src/fill/notification.ts index 71e2e6727..ebda3eeea 100644 --- a/packages/ide/src/fill/notification.ts +++ b/packages/ide/src/fill/notification.ts @@ -1,30 +1,11 @@ import { logger, field } from "@coder/logger"; -/** - * Handle for a notification that allows it to be closed and updated. - */ export interface INotificationHandle { - - /** - * Closes the notification. - */ close(): void; - - /** - * Update the message. - */ updateMessage(message: string): void; - - /** - * Update the buttons. - */ updateButtons(buttons: INotificationButton[]): void; - } -/** - * Notification severity. - */ export enum Severity { Ignore = 0, Info = 1, @@ -32,9 +13,6 @@ export enum Severity { Error = 3, } -/** - * Notification button. - */ export interface INotificationButton { label: string; run(): void; @@ -44,48 +22,28 @@ export interface INotificationButton { * Optional notification service. */ export interface INotificationService { - - /** - * Display an error message. - */ error(error: Error): void; - - /** - * Show a notification. - */ prompt(severity: Severity, message: string, buttons: INotificationButton[], onCancel: () => void): INotificationHandle; - } -/** - * Updatable progress. - */ export interface IProgress { - /** - * Report progress. Progress is the completed percentage from 0 to 100. + * Report progress, which should be the completed percentage from 0 to 100. */ report(progress: number): void; - } -/** - * Option progress reporting service. - */ export interface IProgressService { - /** * Start a new progress bar that resolves & disappears when the task finishes. */ start(title: string, task: (progress: IProgress) => Promise, onCancel: () => void): Promise; - } /** * Temporary notification service. */ export class NotificationService implements INotificationService { - public error(error: Error): void { logger.error(error.message, field("error", error)); } @@ -93,14 +51,12 @@ export class NotificationService implements INotificationService { public prompt(_severity: Severity, message: string, _buttons: INotificationButton[], _onCancel: () => void): INotificationHandle { throw new Error(`cannot prompt using the console: ${message}`); } - } /** * Temporary progress service. */ export class ProgressService implements IProgressService { - public start(title: string, task: (progress: IProgress) => Promise): Promise { logger.info(title); @@ -110,5 +66,4 @@ export class ProgressService implements IProgressService { }, }); } - } diff --git a/packages/ide/src/fill/os.ts b/packages/ide/src/fill/os.ts index 71f78d475..a59338466 100644 --- a/packages/ide/src/fill/os.ts +++ b/packages/ide/src/fill/os.ts @@ -2,7 +2,6 @@ import { InitData } from "@coder/protocol"; import { client } from "./client"; class OS { - private _homedir: string | undefined; private _tmpdir: string | undefined; @@ -40,9 +39,9 @@ class OS { if (navigator.appVersion.indexOf("Mac") != -1) { return "darwin"; } + return "linux"; } - } export = new OS(); diff --git a/packages/ide/src/fill/uri.ts b/packages/ide/src/fill/uri.ts index 6e306e169..d3192ee34 100644 --- a/packages/ide/src/fill/uri.ts +++ b/packages/ide/src/fill/uri.ts @@ -1,18 +1,14 @@ export interface IURI { - readonly path: string; readonly fsPath: string; readonly scheme: string; - } export interface IURIFactory { - /** * Convert the object to an instance of a real URI. */ create(uri: IURI): T; file(path: string): IURI; parse(raw: string): IURI; - } diff --git a/packages/ide/src/retry.ts b/packages/ide/src/retry.ts index fb84addee..e5703764b 100644 --- a/packages/ide/src/retry.ts +++ b/packages/ide/src/retry.ts @@ -21,7 +21,6 @@ interface IRetryItem { * to the user explaining what is happening with an option to immediately retry. */ export class Retry { - private items: Map; // Times are in seconds. @@ -284,7 +283,6 @@ export class Retry { item.timeout = undefined; item.end = undefined; } - } // Global instance so we can block other retries when retrying the main diff --git a/packages/ide/src/upload.ts b/packages/ide/src/upload.ts index 00bd1580a..8faf19174 100644 --- a/packages/ide/src/upload.ts +++ b/packages/ide/src/upload.ts @@ -32,7 +32,6 @@ interface IEntry { * Handles file uploads. */ export class Upload { - private readonly maxParallelUploads = 100; private readonly readSize = 32000; // ~32kb max while reading in the file. private readonly packetSize = 32000; // ~32kb max when writing. @@ -353,7 +352,6 @@ export class Upload { }); } } - } // Global instance. diff --git a/packages/logger/src/logger.ts b/packages/logger/src/logger.ts index f294ef0e8..360fb510d 100644 --- a/packages/logger/src/logger.ts +++ b/packages/logger/src/logger.ts @@ -12,7 +12,6 @@ export enum Level { * A field to log. */ export class Field { - public constructor( public readonly identifier: string, public readonly value: T, @@ -27,19 +26,16 @@ export class Field { value: this.value, }; } - } /** * Represents the time something takes. */ export class Time { - public constructor( public readonly expected: number, public readonly ms: number, ) { } - } // tslint:disable-next-line no-any @@ -117,7 +113,6 @@ const hashStringToColor = (str: string): string => { * currently built items and appends to that. */ export abstract class Formatter { - protected format: string = ""; protected args: string[] = []; @@ -159,14 +154,12 @@ export abstract class Formatter { return "%s"; } } - } /** * Browser formatter. */ export class BrowserFormatter extends Formatter { - public tag(name: string, color: string): void { this.format += `%c ${name} `; this.args.push( @@ -207,14 +200,12 @@ export class BrowserFormatter extends Formatter { // tslint:disable-next-line no-console console.groupEnd(); } - } /** * Server (Node) formatter. */ export class ServerFormatter extends Formatter { - public tag(name: string, color: string): void { const [r, g, b] = hexToRgb(color); while (name.length < 5) { @@ -250,14 +241,12 @@ export class ServerFormatter extends Formatter { this.args.push(JSON.stringify(obj)); console.log(...this.flush()); // tslint:disable-line no-console } - } /** * Class for logging. */ export class Logger { - public level = Level.Info; private readonly nameColor?: string; @@ -429,7 +418,6 @@ export class Logger { } // tslint:enable no-console } - } export const logger = new Logger( diff --git a/packages/protocol/src/browser/client.ts b/packages/protocol/src/browser/client.ts index 031a63d8b..0d9df4e3e 100644 --- a/packages/protocol/src/browser/client.ts +++ b/packages/protocol/src/browser/client.ts @@ -9,7 +9,6 @@ import { EventEmitter } from "events"; * Client accepts an arbitrary connection intended to communicate with the Server. */ export class Client { - public Socket: typeof ServerSocket; private evalId: number = 0; @@ -453,5 +452,4 @@ export class Client { } this.connections.set(id, socket); } - } diff --git a/packages/protocol/src/browser/command.ts b/packages/protocol/src/browser/command.ts index 6e1be26f5..64060002c 100644 --- a/packages/protocol/src/browser/command.ts +++ b/packages/protocol/src/browser/command.ts @@ -170,7 +170,6 @@ export interface Socket { } export class ServerSocket extends events.EventEmitter implements Socket { - public writable: boolean = true; public readable: boolean = true; @@ -276,7 +275,6 @@ export class ServerSocket extends events.EventEmitter implements Socket { public setDefaultEncoding(encoding: string): this { throw new Error("Method not implemented."); } - } export interface Server { @@ -307,7 +305,6 @@ export interface Server { } export class ServerListener extends events.EventEmitter implements Server { - private _listening: boolean = false; public constructor( @@ -358,7 +355,6 @@ export class ServerListener extends events.EventEmitter implements Server { return this; } - } export interface ActiveEval { diff --git a/packages/protocol/src/browser/modules/child_process.ts b/packages/protocol/src/browser/modules/child_process.ts index 182895f7e..10d9e85c3 100644 --- a/packages/protocol/src/browser/modules/child_process.ts +++ b/packages/protocol/src/browser/modules/child_process.ts @@ -3,7 +3,6 @@ import { Client } from "../client"; import { useBuffer } from "../../common/util"; export class CP { - public constructor( private readonly client: Client, ) { } @@ -75,5 +74,4 @@ export class CP { Array.isArray(args) || !args ? options : args, ); } - } diff --git a/packages/protocol/src/browser/modules/fs.ts b/packages/protocol/src/browser/modules/fs.ts index 8092485b3..8bd6e0d72 100644 --- a/packages/protocol/src/browser/modules/fs.ts +++ b/packages/protocol/src/browser/modules/fs.ts @@ -19,7 +19,6 @@ declare var _Buffer: typeof Buffer; * _this somehow which the __awaiter helper uses. */ export class FS { - public constructor( private readonly client: Client, ) { } @@ -686,11 +685,9 @@ export class FS { return watcher; } - } class Watcher extends EventEmitter implements fs.FSWatcher { - public constructor(private readonly process: ChildProcess) { super(); } @@ -698,7 +695,6 @@ class Watcher extends EventEmitter implements fs.FSWatcher { public close(): void { this.process.kill(); } - } interface IStats { @@ -730,7 +726,6 @@ interface IStats { } class Stats implements fs.Stats { - public readonly atime: Date; public readonly mtime: Date; public readonly ctime: Date; @@ -768,7 +763,6 @@ class Stats implements fs.Stats { public toObject(): object { return JSON.parse(JSON.stringify(this)); } - } /** @@ -776,7 +770,6 @@ class Stats implements fs.Stats { * Assumes that messages are split by newlines. */ export class NewlineInputBuffer { - private callback: (msg: string) => void; private buffer: string | undefined; @@ -804,5 +797,4 @@ export class NewlineInputBuffer { this.callback(lines[i]); } } - } diff --git a/packages/protocol/src/browser/modules/net.ts b/packages/protocol/src/browser/modules/net.ts index 0402573fe..0748e27c5 100644 --- a/packages/protocol/src/browser/modules/net.ts +++ b/packages/protocol/src/browser/modules/net.ts @@ -7,7 +7,6 @@ type NodeNet = typeof net; * Implementation of net for the browser. */ export class Net implements NodeNet { - public constructor( private readonly client: Client, ) {} @@ -51,5 +50,4 @@ export class Net implements NodeNet { ): net.Server { return this.client.createServer() as net.Server; } - } diff --git a/packages/protocol/src/node/evaluate.ts b/packages/protocol/src/node/evaluate.ts index 2489c1048..0e3b4a5ef 100644 --- a/packages/protocol/src/node/evaluate.ts +++ b/packages/protocol/src/node/evaluate.ts @@ -1,5 +1,5 @@ import * as vm from "vm"; -import { NewEvalMessage, TypedValue, EvalFailedMessage, EvalDoneMessage, ServerMessage, EvalEventMessage, ClientMessage } from "../proto"; +import { NewEvalMessage, TypedValue, EvalFailedMessage, EvalDoneMessage, ServerMessage, EvalEventMessage } from "../proto"; import { SendableConnection } from "../common/connection"; import { EventEmitter } from "events"; diff --git a/packages/protocol/src/node/server.ts b/packages/protocol/src/node/server.ts index db49cc7a4..26e5ec0b7 100644 --- a/packages/protocol/src/node/server.ts +++ b/packages/protocol/src/node/server.ts @@ -20,7 +20,6 @@ export interface ServerOptions { } export class Server { - private readonly sessions: Map = new Map(); private readonly connections: Map = new Map(); private readonly servers: Map = new Map(); @@ -250,5 +249,4 @@ export class Server { private getSession(id: number): Process | undefined { return this.sessions.get(id); } - } diff --git a/packages/protocol/test/evaluate.test.ts b/packages/protocol/test/evaluate.test.ts index 46ef99960..e58587869 100644 --- a/packages/protocol/test/evaluate.test.ts +++ b/packages/protocol/test/evaluate.test.ts @@ -7,7 +7,7 @@ describe("Evaluate", () => { const value = await client.evaluate(function () { return "hi"; }); - + expect(value).toEqual("hi"); }, 100); @@ -24,7 +24,7 @@ describe("Evaluate", () => { const value = await client.evaluate((arg) => { return arg.bananas * 2; }, { bananas: 1 }); - + expect(value).toEqual(2); }, 100); @@ -32,14 +32,14 @@ describe("Evaluate", () => { const value = await client.evaluate(() => { return { alpha: "beta" }; }); - + expect(value.alpha).toEqual("beta"); }, 100); it("should require", async () => { const value = await client.evaluate(() => { const fs = require("fs") as typeof import("fs"); - + return Object.keys(fs).filter((f) => f === "readFileSync"); }); @@ -69,4 +69,4 @@ describe("Evaluate", () => { runner.on("2", () => runner.emit("3")); runner.on("close", () => done()); }); -}); \ No newline at end of file +}); diff --git a/packages/requirefs/src/requirefs.ts b/packages/requirefs/src/requirefs.ts index 97241cd37..31a343bd5 100644 --- a/packages/requirefs/src/requirefs.ts +++ b/packages/requirefs/src/requirefs.ts @@ -13,7 +13,6 @@ export interface IFileReader { * RequireFS allows users to require from a file system. */ export class RequireFS { - private readonly reader: IFileReader; private readonly customModules: Map; private readonly requireCache: Map; @@ -126,7 +125,6 @@ export class RequireFS { return stripPrefix(resolvedPath); } - } export const fromTar = (content: Uint8Array): RequireFS => { diff --git a/packages/requirefs/src/tarReader.ts b/packages/requirefs/src/tarReader.ts index ddd7f8e08..4e403e56f 100644 --- a/packages/requirefs/src/tarReader.ts +++ b/packages/requirefs/src/tarReader.ts @@ -5,7 +5,6 @@ const textDecoder = new (typeof TextDecoder === "undefined" ? require("text-enco * Tar represents a tar archive. */ export class Tar { - /** * Return a tar object from a Uint8Array. */ @@ -42,14 +41,12 @@ export class Tar { public get files(): ReadonlyMap { return this._files; } - } /** * Represents a tar files location within a reader */ export class TarFile { - /** * Locate a tar file from a reader. */ @@ -186,14 +183,12 @@ export class TarFile { public read(): Uint8Array { return this.reader.jump(this.data.offset).read(this.data.size); } - } /** * Reads within a Uint8Array. */ export class Reader { - private array: Uint8Array; private _offset: number; private lastClamp: number; @@ -281,5 +276,4 @@ export class Reader { return data; } - } diff --git a/packages/server/src/cli.ts b/packages/server/src/cli.ts index 4881be50e..8774157bc 100644 --- a/packages/server/src/cli.ts +++ b/packages/server/src/cli.ts @@ -8,11 +8,10 @@ import * as WebSocket from "ws"; import { createApp } from "./server"; import { requireModule } from "./vscode/bootstrapFork"; import { SharedProcess, SharedProcessState } from "./vscode/sharedProcess"; -import { setup as setupNativeModules } from './modules'; -import { fillFs } from './fill'; +import { setup as setupNativeModules } from "./modules"; +import { fillFs } from "./fill"; export class Entry extends Command { - public static description = "Start your own self-hosted browser-accessible VS Code"; public static flags = { cert: flags.string(), @@ -167,7 +166,6 @@ export class Entry extends Command { logger.info(`http://localhost:${flags.port}/`); logger.info(" "); } - } Entry.run(undefined, { diff --git a/packages/server/src/fill.ts b/packages/server/src/fill.ts index cb86e95cc..4622ec31a 100644 --- a/packages/server/src/fill.ts +++ b/packages/server/src/fill.ts @@ -3,7 +3,7 @@ import * as util from "util"; const oldAccess = fs.access; const existsWithinBinary = (path: fs.PathLike): Promise => { - return new Promise((resolve) => { + return new Promise((resolve): void => { if (typeof path === "number") { if (path < 0) { return resolve(true); @@ -18,7 +18,7 @@ const existsWithinBinary = (path: fs.PathLike): Promise => { }); }; -export const fillFs = () => { +export const fillFs = (): void => { /** * Refer to https://github.com/nexe/nexe/blob/master/src/fs/patch.ts * For impls diff --git a/packages/server/src/ipc.ts b/packages/server/src/ipc.ts index 0f556f854..c25a17155 100644 --- a/packages/server/src/ipc.ts +++ b/packages/server/src/ipc.ts @@ -7,7 +7,6 @@ export interface IpcMessage { } export class StdioIpcHandler extends EventEmitter { - private isListening: boolean = false; public constructor( @@ -66,5 +65,4 @@ export class StdioIpcHandler extends EventEmitter { process.stdin.on("data", onData); } } - -} \ No newline at end of file +} diff --git a/packages/server/src/server.ts b/packages/server/src/server.ts index 2cfd6576e..a508cc2fd 100644 --- a/packages/server/src/server.ts +++ b/packages/server/src/server.ts @@ -1,7 +1,7 @@ import { logger } from "@coder/logger"; import { ReadWriteConnection } from "@coder/protocol"; import { Server, ServerOptions } from "@coder/protocol/src/node/server"; -import { NewSessionMessage } from '@coder/protocol/src/proto'; +import { NewSessionMessage } from "@coder/protocol/src/proto"; import { ChildProcess } from "child_process"; import * as express from "express"; //@ts-ignore diff --git a/packages/server/src/vscode/sharedProcess.ts b/packages/server/src/vscode/sharedProcess.ts index 5a78ed938..e780f6092 100644 --- a/packages/server/src/vscode/sharedProcess.ts +++ b/packages/server/src/vscode/sharedProcess.ts @@ -6,7 +6,7 @@ import { forkModule } from "./bootstrapFork"; import { StdioIpcHandler } from "../ipc"; import { ParsedArgs } from "vs/platform/environment/common/environment"; import { LogLevel } from "vs/platform/log/common/log"; -import { Emitter, Event } from '@coder/events/src'; +import { Emitter, Event } from "@coder/events/src"; export enum SharedProcessState { Stopped, @@ -22,7 +22,6 @@ export type SharedProcessEvent = { }; export class SharedProcess { - public readonly socketPath: string = path.join(os.tmpdir(), `.vscode-remote${Math.random().toString()}`); private _state: SharedProcessState = SharedProcessState.Stopped; private activeProcess: ChildProcess | undefined; diff --git a/packages/vscode/src/client.ts b/packages/vscode/src/client.ts index 12f94f000..d7a51b944 100644 --- a/packages/vscode/src/client.ts +++ b/packages/vscode/src/client.ts @@ -26,7 +26,6 @@ import { ServiceCollection } from "vs/platform/instantiation/common/serviceColle import { RawContextKey, IContextKeyService } from "vs/platform/contextkey/common/contextkey"; export class Client extends IDEClient { - private readonly windowId = parseInt(new Date().toISOString().replace(/[-:.TZ]/g, ""), 10); private _serviceCollection: ServiceCollection | undefined; private _clipboardContextKey: RawContextKey | undefined; @@ -192,7 +191,6 @@ export class Client extends IDEClient { this.clipboard.initialize(); }, this.initData, pathSets); } - } export const client = new Client(); diff --git a/packages/vscode/src/fill/codeEditor.ts b/packages/vscode/src/fill/codeEditor.ts index d6a5fbd67..e1134724e 100644 --- a/packages/vscode/src/fill/codeEditor.ts +++ b/packages/vscode/src/fill/codeEditor.ts @@ -6,7 +6,6 @@ import { IDecorationRenderOptions } from "vs/editor/common/editorCommon"; * This converts icon paths for decorations to the correct URL. */ abstract class CodeEditorServiceImpl extends editor.CodeEditorServiceImpl { - public registerDecorationType(key: string, options: IDecorationRenderOptions, parentTypeKey?: string): void { super.registerDecorationType(key, options ? { ...options, @@ -18,7 +17,6 @@ abstract class CodeEditorServiceImpl extends editor.CodeEditorServiceImpl { } :options.gutterIconPath, } : {}, parentTypeKey); } - } const target = editor as typeof editor; diff --git a/packages/vscode/src/fill/environmentService.ts b/packages/vscode/src/fill/environmentService.ts index 048db1e32..b57ad0fa4 100644 --- a/packages/vscode/src/fill/environmentService.ts +++ b/packages/vscode/src/fill/environmentService.ts @@ -2,11 +2,9 @@ import * as paths from "./paths"; import * as environment from "vs/platform/environment/node/environmentService"; export class EnvironmentService extends environment.EnvironmentService { - public get sharedIPCHandle(): string { return paths._paths.socketPath || super.sharedIPCHandle; } - } const target = environment as typeof environment; diff --git a/packages/vscode/src/fill/iconv-lite.ts b/packages/vscode/src/fill/iconv-lite.ts index 1ea47d6a9..92d036908 100644 --- a/packages/vscode/src/fill/iconv-lite.ts +++ b/packages/vscode/src/fill/iconv-lite.ts @@ -2,7 +2,6 @@ import * as iconv from "../../node_modules/iconv-lite"; import { Transform, TransformCallback } from "stream"; class IconvLiteDecoderStream extends Transform { - // tslint:disable-next-line no-any private conv: any; private encoding: string; diff --git a/packages/vscode/src/fill/mouseEvent.ts b/packages/vscode/src/fill/mouseEvent.ts index bfef104da..08ca66663 100644 --- a/packages/vscode/src/fill/mouseEvent.ts +++ b/packages/vscode/src/fill/mouseEvent.ts @@ -4,7 +4,6 @@ import * as mouse from "vs/base/browser/mouseEvent"; * Fix the wheel event for Firefox. */ class StandardWheelEvent extends mouse.StandardWheelEvent { - public constructor(event: mouse.IMouseWheelEvent | null) { super( event, @@ -12,7 +11,6 @@ class StandardWheelEvent extends mouse.StandardWheelEvent { (-(event as any as MouseWheelEvent).deltaY || 0) / 3, // tslint:disable-line no-any ); } - } const target = mouse as typeof mouse; diff --git a/packages/vscode/src/fill/native-keymap.ts b/packages/vscode/src/fill/native-keymap.ts index 32b71723c..f3749ceab 100644 --- a/packages/vscode/src/fill/native-keymap.ts +++ b/packages/vscode/src/fill/native-keymap.ts @@ -1,5 +1,4 @@ class NativeKeymap { - public getCurrentKeyboardLayout(): null { return null; } @@ -7,7 +6,6 @@ class NativeKeymap { public getKeyMap(): undefined[] { return []; } - } export = new NativeKeymap(); diff --git a/packages/vscode/src/fill/native-watchdog.ts b/packages/vscode/src/fill/native-watchdog.ts index 85b786e2e..cf8d8346b 100644 --- a/packages/vscode/src/fill/native-watchdog.ts +++ b/packages/vscode/src/fill/native-watchdog.ts @@ -1,9 +1,7 @@ class Watchdog { - public start(): void { // No action required. } - } export = new Watchdog(); diff --git a/packages/vscode/src/fill/node-pty.ts b/packages/vscode/src/fill/node-pty.ts index a47700962..439d68d6d 100644 --- a/packages/vscode/src/fill/node-pty.ts +++ b/packages/vscode/src/fill/node-pty.ts @@ -9,7 +9,6 @@ type nodePtyType = typeof nodePty; * Implementation of nodePty for the browser. */ class Pty implements nodePty.IPty { - private readonly emitter: EventEmitter; private readonly cp: ChildProcess; @@ -54,15 +53,12 @@ class Pty implements nodePty.IPty { public kill(signal?: string): void { this.emitter.emit("kill", signal); } - } const ptyType: nodePtyType = { - spawn: (file: string, args: string[] | string, options: nodePty.IPtyForkOptions): nodePty.IPty => { return new Pty(file, args, options); }, - }; module.exports = ptyType; diff --git a/packages/vscode/src/fill/paste.ts b/packages/vscode/src/fill/paste.ts index 7e557d3ff..f6f5851e1 100644 --- a/packages/vscode/src/fill/paste.ts +++ b/packages/vscode/src/fill/paste.ts @@ -13,7 +13,6 @@ const getLabel = (key: string, enabled: boolean): string => { }; export class PasteAction extends Action { - private static readonly KEY = "paste"; public constructor() { @@ -30,11 +29,9 @@ export class PasteAction extends Action { this.enabled = enabled; }); } - } class TerminalPasteAction extends Action { - private static readonly KEY = "workbench.action.terminal.paste"; public static readonly ID = TERMINAL_COMMAND_ID.PASTE; @@ -61,11 +58,9 @@ class TerminalPasteAction extends Action { return Promise.resolve(); } - } class TerminalInstance extends instance.TerminalInstance { - public async paste(): Promise { this.focus(); if (clipboard.isEnabled) { @@ -75,7 +70,6 @@ class TerminalInstance extends instance.TerminalInstance { document.execCommand("paste"); } } - } const actionsTarget = actions as typeof actions; diff --git a/packages/vscode/src/fill/spdlog.ts b/packages/vscode/src/fill/spdlog.ts index 147e6b5e5..ff0403689 100644 --- a/packages/vscode/src/fill/spdlog.ts +++ b/packages/vscode/src/fill/spdlog.ts @@ -9,7 +9,6 @@ import { escapePath } from "@coder/protocol"; // use that for the logging. Or maybe create an instance when the server starts, // and just always use that one (make it part of the protocol). export class RotatingLogger implements NodeRotatingLogger { - private format = true; private buffer = ""; private flushPromise: Promise | undefined; @@ -178,7 +177,6 @@ export class RotatingLogger implements NodeRotatingLogger { await this.rotate(); } } - } export const setAsyncMode = (): void => { diff --git a/packages/vscode/src/fill/stdioElectron.ts b/packages/vscode/src/fill/stdioElectron.ts index 48cefdca9..9f2de4781 100644 --- a/packages/vscode/src/fill/stdioElectron.ts +++ b/packages/vscode/src/fill/stdioElectron.ts @@ -4,7 +4,6 @@ import { IpcRenderer } from "electron"; export * from "@coder/ide/src/fill/electron"; class StdioIpcRenderer extends StdioIpcHandler implements IpcRenderer { - public sendTo(windowId: number, channel: string, ...args: any[]): void { throw new Error("Method not implemented."); } @@ -16,7 +15,6 @@ class StdioIpcRenderer extends StdioIpcHandler implements IpcRenderer { public eventNames(): string[] { return super.eventNames() as string[]; } - } export const ipcRenderer = new StdioIpcRenderer(); diff --git a/packages/vscode/src/fill/storageDatabase.ts b/packages/vscode/src/fill/storageDatabase.ts index 161949c4e..ffde38f75 100644 --- a/packages/vscode/src/fill/storageDatabase.ts +++ b/packages/vscode/src/fill/storageDatabase.ts @@ -9,7 +9,6 @@ import * as paths from "./paths"; import { logger, field } from "@coder/logger"; class StorageDatabase implements workspaceStorage.IStorageDatabase { - public readonly onDidChangeItemsExternal = Event.None; private items = new Map(); private fetched: boolean = false; @@ -78,11 +77,9 @@ class StorageDatabase implements workspaceStorage.IStorageDatabase { return promisify(writeFile)(this.path, JSON.stringify(json)); } - } class GlobalStorageDatabase extends StorageDatabase implements IDisposable { - public constructor() { super(path.join(paths.getAppDataPath(), "globalStorage", "state.vscdb")); } @@ -90,7 +87,6 @@ class GlobalStorageDatabase extends StorageDatabase implements IDisposable { public dispose(): void { // Nothing to do. } - } const workspaceTarget = workspaceStorage as typeof workspaceStorage; diff --git a/packages/vscode/src/fill/windowsService.ts b/packages/vscode/src/fill/windowsService.ts index 5f68d98dc..7c66b4f69 100644 --- a/packages/vscode/src/fill/windowsService.ts +++ b/packages/vscode/src/fill/windowsService.ts @@ -14,7 +14,6 @@ import { client } from "../client"; * the client. This setup means we can only control the current window. */ class WindowsService implements IWindowsService { - // tslint:disable-next-line no-any public _serviceBrand: any; @@ -278,7 +277,6 @@ class WindowsService implements IWindowsService { private getWindowById(_windowId: number): electron.BrowserWindow { return this.window; } - } const target = windowsIpc as typeof windowsIpc; diff --git a/rules/src/noBlockPaddingRule.ts b/rules/src/noBlockPaddingRule.ts new file mode 100644 index 000000000..cd41b179e --- /dev/null +++ b/rules/src/noBlockPaddingRule.ts @@ -0,0 +1,89 @@ +import * as ts from "typescript"; +import * as Lint from "tslint"; + +/** + * Rule for disallowing blank lines around the content of blocks. + */ +export class Rule extends Lint.Rules.AbstractRule { + public static BEFORE_FAILURE_STRING = "Blocks must not start with blank lines"; + public static AFTER_FAILURE_STRING = "Blocks must not end with blank lines"; + + /** + * Apply the rule. + */ + public apply(sourceFile: ts.SourceFile): Lint.RuleFailure[] { + return this.applyWithWalker(new NoBlockPaddingWalker(sourceFile, this.getOptions())); + } +} + +/** + * Walker for checking block padding. + */ +class NoBlockPaddingWalker extends Lint.RuleWalker { + /** + * Apply this rule to interfaces. + */ + public visitInterfaceDeclaration(node: ts.InterfaceDeclaration): void { + this.visitBlockNode(node); + super.visitInterfaceDeclaration(node); + } + + /** + * Apply this rule to classes. + */ + public visitClassDeclaration(node: ts.ClassDeclaration): void { + this.visitBlockNode(node); + super.visitClassDeclaration(node); + } + + /** + * Add failures to blank lines surrounding a block's content. + */ + private visitBlockNode(node: ts.ClassDeclaration | ts.InterfaceDeclaration): void { + const sourceFile = node.getSourceFile(); + const children = node.getChildren(); + + const openBraceIndex = children.findIndex((n) => n.kind === ts.SyntaxKind.OpenBraceToken); + if (openBraceIndex !== -1) { + const nextToken = children[openBraceIndex + 1]; + if (nextToken) { + const startLine = this.getStartIncludingComments(sourceFile, nextToken); + const openBraceToken = children[openBraceIndex]; + if (ts.getLineAndCharacterOfPosition(sourceFile, openBraceToken.getEnd()).line + 1 < startLine) { + this.addFailureAt(openBraceToken.getEnd(), openBraceToken.getEnd(), Rule.BEFORE_FAILURE_STRING); + } + } + } + + const closeBraceIndex = children.findIndex((n) => n.kind === ts.SyntaxKind.CloseBraceToken); + if (closeBraceIndex >= 2) { + const previousToken = children[closeBraceIndex - 1]; + if (previousToken) { + let endLine = ts.getLineAndCharacterOfPosition(sourceFile, previousToken.getEnd()).line; + const closeBraceToken = children[closeBraceIndex]; + if (this.getStartIncludingComments(sourceFile, closeBraceToken) > endLine + 1) { + this.addFailureAt(closeBraceToken.getStart(), closeBraceToken.getStart(), Rule.AFTER_FAILURE_STRING); + } + } + } + } + + /** + * getStart() doesn't account for comments while this does. + */ + private getStartIncludingComments(sourceFile: ts.SourceFile, node: ts.Node): number { + // This gets the line the node starts on without counting comments. + let startLine = ts.getLineAndCharacterOfPosition(sourceFile, node.getStart()).line; + + // Adjust the start line for the comments. + const comments = ts.getLeadingCommentRanges(sourceFile.text, node.pos) || []; + comments.forEach((c) => { + const commentStartLine = ts.getLineAndCharacterOfPosition(sourceFile, c.pos).line; + if (commentStartLine < startLine) { + startLine = commentStartLine; + } + }); + + return startLine; + } +} diff --git a/tslint.json b/tslint.json index dd8709a55..0b4bc8e43 100644 --- a/tslint.json +++ b/tslint.json @@ -3,12 +3,14 @@ "rules": { "only-arrow-functions": true, "curly-statement-newlines": true, + "no-block-padding": true, "adjacent-overload-signatures": true, "align": true, "await-promise": [true, "Thenable"], "class-name": true, "eofline": true, "import-spacing": true, + "indent": [true, "tabs"], "no-angle-bracket-type-assertion": false, "no-bitwise": false, "no-any": true,