diff --git a/src/Buffer.ts b/src/Buffer.ts index 3ccff9606..bcaf9430f 100644 --- a/src/Buffer.ts +++ b/src/Buffer.ts @@ -108,7 +108,7 @@ export default class Buffer extends events.EventEmitter { } toLines(): string[] { - return this.storage.map(row => row.map(char => char.toString()).join("")).toArray(); + return this.storage.map(row => row!.map(char => char!.toString()).join("")).toArray(); } toString(): string { diff --git a/src/CommandExpander.ts b/src/CommandExpander.ts index bc8e7de26..55d1147ab 100644 --- a/src/CommandExpander.ts +++ b/src/CommandExpander.ts @@ -30,7 +30,7 @@ export function lex(input: string): string[] { return []; } - let lexemes = input.match(/"(?:\\"|[^"])+"|'(?:\\'|[^'])+'|(?:[^ ]+\\ )+[^ ]+|[^ ]+/g); + let lexemes: string[] = input.match(/"(?:\\"|[^"])+"|'(?:\\'|[^'])+'|(?:[^ ]+\\ )+[^ ]+|[^ ]+/g) || []; if (input.endsWith(" ")) { lexemes.push(""); diff --git a/src/Decorators.ts b/src/Decorators.ts index 7e419c72c..efd249e31 100644 --- a/src/Decorators.ts +++ b/src/Decorators.ts @@ -1,6 +1,6 @@ import * as _ from "lodash"; -export function memoize(resolver: Function = undefined) { +export function memoize(resolver: Function | undefined = undefined) { if (typeof resolver !== "function") { resolver = (...args: any[]) => JSON.stringify(args); } diff --git a/src/Job.ts b/src/Job.ts index d38f05323..4b2200a7b 100644 --- a/src/Job.ts +++ b/src/Job.ts @@ -128,7 +128,11 @@ export default class Job extends EmitterWithUniqueID { } decorate(): React.ReactElement { - return this.firstApplicableDecorator.decorate(this); + if (this.firstApplicableDecorator) { + return this.firstApplicableDecorator.decorate(this); + } else { + throw "No applicable decorator found."; + } } get environment(): Environment { @@ -142,7 +146,7 @@ export default class Job extends EmitterWithUniqueID { ); } - private get firstApplicableDecorator(): i.OutputDecorator { + private get firstApplicableDecorator(): i.OutputDecorator | undefined { return this.decorators.find(decorator => decorator.isApplicable(this)); } diff --git a/src/Parser.ts b/src/Parser.ts index 0743dacd7..759fd1a2a 100644 --- a/src/Parser.ts +++ b/src/Parser.ts @@ -60,8 +60,6 @@ export const string = (expected: string) => { const progress = getProgress(context.input, expected); return [{ - parser: parser, - context: context, parse: progress === Progress.Finished ? expected : "", progress: progress, suggestions: (progress === Progress.Finished) diff --git a/src/Serializer.ts b/src/Serializer.ts index 55eaa8f8e..f70625c1c 100644 --- a/src/Serializer.ts +++ b/src/Serializer.ts @@ -8,7 +8,7 @@ export default class Serializer { } else if (typeof serializable === "string") { return `String:${serializable}`; } else { - console.error(`Don"t know how to serialize ${serializable}`); + throw `Don"t know how to serialize ${serializable}`; } } @@ -18,7 +18,7 @@ export default class Serializer { } else if (_.startsWith(serialized, "History:")) { return History.deserialize(serialized.slice("History:".length)); } else { - console.error(`Don"t know how to deserialize ${serialized}`); + throw `Don"t know how to deserialize ${serialized}`; } } } diff --git a/src/main/Main.ts b/src/main/Main.ts index 837598d85..764ae0649 100644 --- a/src/main/Main.ts +++ b/src/main/Main.ts @@ -3,55 +3,46 @@ import menu from "./Menu"; import {readFileSync} from "fs"; import {windowBoundsFilePath} from "../utils/Common"; - -let browserWindow: Electron.BrowserWindow = undefined; - if (app.dock) { app.dock.setIcon(nativeImage.createFromPath("build/icon.png")); } -app.on("open-file", (event: Event, file: string) => getMainWindow().webContents.send("change-working-directory", file)); -app.on("ready", getMainWindow); -app.on("activate", getMainWindow); -app.on("mainWindow-all-closed", () => process.platform === "darwin" || app.quit()); - -ipcMain.on("quit", app.quit); - -function getMainWindow(): Electron.BrowserWindow { +app.on("ready", () => { const bounds = windowBounds(); - if (!browserWindow) { - let options: Electron.BrowserWindowOptions = { - webPreferences: { - experimentalFeatures: true, - experimentalCanvasFeatures: true, - }, - titleBarStyle: "hidden", - resizable: true, - minWidth: 500, - minHeight: 300, - width: bounds.width, - height: bounds.height, - x: bounds.x, - y: bounds.y, - show: false, - }; - browserWindow = new BrowserWindow(options); + let options: Electron.BrowserWindowOptions = { + webPreferences: { + experimentalFeatures: true, + experimentalCanvasFeatures: true, + }, + titleBarStyle: "hidden", + resizable: true, + minWidth: 500, + minHeight: 300, + width: bounds.width, + height: bounds.height, + x: bounds.x, + y: bounds.y, + show: false, + }; + const browserWindow = new BrowserWindow(options); + + browserWindow.loadURL("file://" + __dirname + "/../views/index.html"); + menu.setMenu(app, browserWindow); + + browserWindow.on("focus", () => app.dock && app.dock.setBadge("")); + + browserWindow.webContents.on("did-finish-load", () => { + browserWindow.show(); + browserWindow.focus(); + }); + + app.on("open-file", (event, file) => browserWindow.webContents.send("change-working-directory", file)); +}); - browserWindow.loadURL("file://" + __dirname + "/../views/index.html"); - menu.setMenu(app, browserWindow); - - browserWindow.on("closed", (): void => browserWindow = undefined) - .on("focus", (): void => app.dock && app.dock.setBadge("")); - - browserWindow.webContents.on("did-finish-load", () => { - browserWindow.show(); - browserWindow.focus(); - }); - } +app.on("mainWindow-all-closed", () => process.platform === "darwin" || app.quit()); - return browserWindow; -} +ipcMain.on("quit", app.quit); function windowBounds(): Electron.Bounds { try { diff --git a/src/plugins/GitWatcher.ts b/src/plugins/GitWatcher.ts index 432bd3d9b..f7f532374 100644 --- a/src/plugins/GitWatcher.ts +++ b/src/plugins/GitWatcher.ts @@ -53,13 +53,15 @@ class GitWatcher extends EventEmitter { @debounce(1000 / 60) private async updateGitData() { let content = await readFile(Path.join(this.gitDirectory, "HEAD")); + const headMatch = /ref: refs\/heads\/(.*)/.exec(content); + const head = headMatch ? headMatch[1] : "Couldn't parse branch"; executeCommand("git", ["status", "--porcelain"], this.directory).then(changes => { const status: VcsStatus = changes.length ? "dirty" : "clean"; const data: VcsData = { isRepository: true, - branch: /ref: refs\/heads\/(.*)/.exec(content)[1], + branch: head, status: status, }; @@ -83,7 +85,7 @@ class WatchManager implements EnvironmentObserverPlugin { return; } - const details = this.directoryToDetails.get(oldDirectory); + const details = this.directoryToDetails.get(oldDirectory)!; details.sessions.delete(session); if (details.sessions.size === 0) { @@ -94,7 +96,7 @@ class WatchManager implements EnvironmentObserverPlugin { currentWorkingDirectoryDidChange(session: Session, directory: string) { if (this.directoryToDetails.has(directory)) { - this.directoryToDetails.get(directory).sessions.add(session); + this.directoryToDetails.get(directory)!.sessions.add(session); } else { const watcher = new GitWatcher(directory); diff --git a/src/plugins/autocompletion_providers/Alias.ts b/src/plugins/autocompletion_providers/Alias.ts index 886b0be59..e39737764 100644 --- a/src/plugins/autocompletion_providers/Alias.ts +++ b/src/plugins/autocompletion_providers/Alias.ts @@ -1,10 +1,9 @@ -import * as _ from "lodash"; import {description, styles, style} from "./Suggestions"; import {choice, decorate, Context, string} from "../../Parser"; -import {compose} from "../../utils/Common"; +import {compose, mapObject} from "../../utils/Common"; import {command} from "./Command"; -export const makeAlias = (aliases: Dictionary) => choice(_.map(aliases, (expanded, key) => choice([ +export const makeAlias = (aliases: Dictionary) => choice(mapObject(aliases, (key, expanded) => choice([ decorate(string(key), compose(style(styles.alias), description(expanded))), async (context: Context) => { if (context.input.startsWith(key)) {