diff --git a/.eslintrc.js b/.eslintrc.js index c7518b82..e1475227 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -108,7 +108,7 @@ module.exports = { "@typescript-eslint/no-floating-promises": "off", //"error", "@typescript-eslint/no-for-in-array": "error", "@typescript-eslint/no-implied-eval": "error", - "@typescript-eslint/no-inferrable-types": "off", //"error", + "@typescript-eslint/no-inferrable-types": "error", "@typescript-eslint/no-misused-new": "error", "@typescript-eslint/no-misused-promises": ["error", { diff --git a/src/completions/Bindings.ts b/src/completions/Bindings.ts index 4c41d09d..8d8396d8 100644 --- a/src/completions/Bindings.ts +++ b/src/completions/Bindings.ts @@ -12,10 +12,10 @@ class BindingsCompletionOption extends Completions.CompletionOptionHTML ) { super() this.html = html` - ${binding.name} - ${binding.value} - ${binding.mode} - ` + ${binding.name} + ${binding.value} + ${binding.mode} + ` } } @@ -36,10 +36,10 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse { this.lastExstr = exstr let options = "" let [prefix, query] = this.splitOnPrefix(exstr) - const args = query ? query.split(/\s+/) : [] - let configName: string = "nmaps" + const args = query ? query.split(/\s+/) : [] + let configName = "nmaps" let modeName = "normal" - let urlPattern: string = null + let urlPattern: string = null // Hide self and stop if prefixes don't match if (prefix) { @@ -64,12 +64,14 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse { this.options = Object.keys(patterns) .filter(pattern => pattern.startsWith(urlPattern)) .sort() - .map(pattern => new BindingsCompletionOption( - pattern, { - name: pattern, - value: "", - mode: "URL Pattern", - })) + .map( + pattern => + new BindingsCompletionOption(pattern, { + name: pattern, + value: "", + mode: "URL Pattern", + }), + ) return this.updateChain() } @@ -81,13 +83,18 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse { if ("--mode".includes(margs[0])) { const modeStr = margs.length > 1 ? margs[1] : "" this.options = Binding.modes - .filter(k => k.startsWith(modeStr)) - .map(name => new BindingsCompletionOption( - options + "--mode=" + name, { - name, - value: "", - mode: "Mode Name", - })) + .filter(k => k.startsWith(modeStr)) + .map( + name => + new BindingsCompletionOption( + options + "--mode=" + name, + { + name, + value: "", + mode: "Mode Name", + }, + ), + ) return this.updateChain() } } @@ -109,7 +116,9 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse { return this.updateChain() } - const bindings = urlPattern ? config.getURL(urlPattern, [configName]) : config.get(configName as any) + const bindings = urlPattern + ? config.getURL(urlPattern, [configName]) + : config.get(configName as any) if (bindings === undefined) { this.options = [] @@ -118,14 +127,19 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse { query = args.join(" ").toLowerCase() this.options = Object.keys(bindings) - .filter(x => x.toLowerCase().startsWith(query) ) + .filter(x => x.toLowerCase().startsWith(query)) .sort() - .map(keystr => new BindingsCompletionOption( - options + keystr + " " + bindings[keystr], { - name: keystr, - value: JSON.stringify(bindings[keystr]), - mode: `${configName} (${modeName})`, - })) + .map( + keystr => + new BindingsCompletionOption( + options + keystr + " " + bindings[keystr], + { + name: keystr, + value: JSON.stringify(bindings[keystr]), + mode: `${configName} (${modeName})`, + }, + ), + ) return this.updateChain() } @@ -137,6 +151,4 @@ export class BindingsCompletionSource extends Completions.CompletionSourceFuse { // Call concrete class return this.updateDisplay() } - - } diff --git a/src/content/scrolling.ts b/src/content/scrolling.ts index d2efb58a..07825973 100644 --- a/src/content/scrolling.ts +++ b/src/content/scrolling.ts @@ -63,17 +63,22 @@ class ScrollingData { * It might be useful to make this function more configurable by making it * accept an argument instead of using performance.now() */ - private getStep(): number { + private getStep(): number { if (this.startTime === undefined) { this.startTime = performance.now() } const elapsed: number = performance.now() - this.startTime // If the animation should be done, return the position the element should have - if (elapsed >= this.duration || this.elem[this.scrollDirection] === this.endPos) + if ( + elapsed >= this.duration || + this.elem[this.scrollDirection] === this.endPos + ) return this.endPos - let pixelToScrollTo: number = this.startPos + (((this.endPos - this.startPos) * elapsed) / this.duration) + let pixelToScrollTo: number = + this.startPos + + ((this.endPos - this.startPos) * elapsed) / this.duration if (this.startPos < this.endPos) { // We need to ceil() because only highdpi screens have a decimal this.elem[this.pos] pixelToScrollTo = Math.ceil(pixelToScrollTo) @@ -104,7 +109,6 @@ class ScrollingData { this.scrollStep() ? this.scheduleStep() : (this.scrolling = false), ) } - } // Stores elements that are currently being horizontally scrolled @@ -116,8 +120,8 @@ const verticallyScrolling = new Map() * last duration milliseconds */ export async function scroll( - xDistance: number = 0, - yDistance: number = 0, + xDistance = 0, + yDistance = 0, e: Node, duration?: number, ): Promise { @@ -189,15 +193,15 @@ export async function recursiveScroll( startingFromCached = true node = lastRecursiveScrolled } else { - // Try scrolling the active node or one of its parent elements // If nothing has been given focus explicitly use the activeElement - if (!currentFocused || currentFocused.nodeName == "#document") currentFocused = document.activeElement + if (!currentFocused || currentFocused.nodeName == "#document") + currentFocused = document.activeElement node = currentFocused while (true) { - if ((await scroll(xDistance, yDistance, node))) return true + if (await scroll(xDistance, yDistance, node)) return true node = node.parentElement if (!node) break } @@ -215,7 +219,9 @@ export async function recursiveScroll( if ( (await scroll(xDistance, yDistance, treeWalker.currentNode)) || ((treeWalker.currentNode as any).contentDocument && - !(treeWalker.currentNode as any).src.startsWith("moz-extension://") && + !(treeWalker.currentNode as any).src.startsWith( + "moz-extension://", + ) && (await recursiveScroll( xDistance, yDistance, diff --git a/src/content/state_content.ts b/src/content/state_content.ts index 2be9233d..b2a78247 100644 --- a/src/content/state_content.ts +++ b/src/content/state_content.ts @@ -19,10 +19,14 @@ export class PrevInput { class ContentState { mode: ModeName = "normal" - suffix: string = "" + suffix = "" } -export type ContentStateProperty = "mode" | "cmdHistory" | "prevInputs" | "suffix" +export type ContentStateProperty = + | "mode" + | "cmdHistory" + | "prevInputs" + | "suffix" export type ContentStateChangedCallback = ( property: ContentStateProperty, diff --git a/src/lib/config.ts b/src/lib/config.ts index 2ea6436a..6452455f 100644 --- a/src/lib/config.ts +++ b/src/lib/config.ts @@ -1031,7 +1031,7 @@ export class default_config { * statistics, so somewhere around 10k samples. * */ - perfsamples: string = "10000" + perfsamples = "10000" /** * Show (partial) command in the mode indicator. diff --git a/src/lib/containers.ts b/src/lib/containers.ts index 094d6dcc..9bfc170e 100644 --- a/src/lib/containers.ts +++ b/src/lib/containers.ts @@ -144,12 +144,7 @@ export async function exists(cname: string): Promise { @param color @param icon */ -export function fromString( - name: string, - color: string, - icon: string, - id: string = "", -) { +export function fromString(name: string, color: string, icon: string, id = "") { return { name, color: color as browser.contextualIdentities.IdentityColor, diff --git a/src/lib/editor_utils.ts b/src/lib/editor_utils.ts index 1a9f8c06..6567b0ff 100644 --- a/src/lib/editor_utils.ts +++ b/src/lib/editor_utils.ts @@ -278,13 +278,13 @@ export function wordAfterPos(text: string, position: number) { /** @hidden * Rots by 13. */ -export const rot13_helper = (s: string, n: number = 13): string => { +export const rot13_helper = (s: string, n = 13): string => { let sa = s.split("") sa = sa.map(x => charesar(x, n)) return sa.join("") } -export const charesar = (c: string, n: number = 13): string => { +export const charesar = (c: string, n = 13): string => { const cn = c.charCodeAt(0) if (cn >= 65 && cn <= 90) return String.fromCharCode(((cn - 65 + n) % 26) + 65) diff --git a/src/parsers/nmode.ts b/src/parsers/nmode.ts index a5bf8d66..d0a7edb2 100644 --- a/src/parsers/nmode.ts +++ b/src/parsers/nmode.ts @@ -16,7 +16,7 @@ let modeState: NModeState /** Init n [mode] mode. After parsing the defined number of commands, execute `endCmd`. `Escape` cancels the mode and executes `endCmd`. */ -export function init(endCommand: string, mode = "normal", numCommands: number = 1) { +export function init(endCommand: string, mode = "normal", numCommands = 1) { contentState.mode = "nmode" modeState = new NModeState() modeState.endCommand = endCommand @@ -40,10 +40,13 @@ export function parser(keys: KeyboardEvent[]) { } const response = keyseq.parse(keys, maps) - if ((response.exstr !== undefined && response.isMatch) || !response.isMatch) modeState.curCommands += 1 + if ((response.exstr !== undefined && response.isMatch) || !response.isMatch) + modeState.curCommands += 1 if (modeState.curCommands >= modeState.numCommands) { const prefix = - (response.exstr === undefined) ? "" : ("composite " + response.exstr + "; ") + response.exstr === undefined + ? "" + : "composite " + response.exstr + "; " response.exstr = prefix + modeState.endCommand // NB: this probably breaks any `js` binds modeState = undefined } diff --git a/src/perf.ts b/src/perf.ts index 0f4dd000..295961e0 100644 --- a/src/perf.ts +++ b/src/perf.ts @@ -192,9 +192,9 @@ export class StatsLogger { // mapped symbol instead of the name so we're storing more like 50 // bytes per sample instead of 130 @_@ public buffer: PerformanceEntry[] = [] - private idx: number = 0 - private buffersize: number = 10000 - private lastError: number = 0 + private idx = 0 + private buffersize = 10000 + private lastError = 0 /** * Target for receiving stats entries from other threads - there @@ -301,8 +301,8 @@ export class StatsLogger { */ export function renderStatsHistogram( samples: PerformanceEntry[], - buckets: number = 15, - width: number = 80, + buckets = 15, + width = 80, ): string { const durs: number[] = samples.map(sample => sample.duration) @@ -362,7 +362,7 @@ export class StatsFilter { } } -const TRI_PERFORMANCE_NAME_PREFIX: string = "tri" +const TRI_PERFORMANCE_NAME_PREFIX = "tri" function performanceApiAvailable(): boolean { return performance.mark !== undefined diff --git a/src/state.ts b/src/state.ts index 340b4b7d..fa93a118 100644 --- a/src/state.ts +++ b/src/state.ts @@ -12,7 +12,7 @@ import Logger from "@src/lib/logging" import * as messaging from "@src/lib/messaging" -import {notBackground} from "@src/lib/webext" +import { notBackground } from "@src/lib/webext" const logger = new Logger("state") @@ -26,7 +26,7 @@ class State { jumppos: undefined, }, ] - last_ex_str: string = "echo" + last_ex_str = "echo" } // Don't change these from const or you risk breaking the Proxy below. @@ -43,10 +43,11 @@ browser.storage.local }) .catch((...args) => logger.error(...args)) -const state = (new Proxy(overlay, { +const state = new Proxy(overlay, { /** Give defaults if overlay doesn't have the key */ get(target, property) { - if (notBackground()) throw "State object must be accessed with getAsync in content" + if (notBackground()) + throw "State object must be accessed with getAsync in content" if (property in target) { return target[property] } else { @@ -61,7 +62,11 @@ const state = (new Proxy(overlay, { logger.debug("State changed!", property, value) if (notBackground()) { - browser.runtime.sendMessage({type: "state", command: "stateUpdate", args: {property, value}}) + browser.runtime.sendMessage({ + type: "state", + command: "stateUpdate", + args: { property, value }, + }) return true } // Do we need a global storage lock? @@ -69,10 +74,15 @@ const state = (new Proxy(overlay, { browser.storage.local.set({ state: target } as any) return true }, -})) +}) export async function getAsync(property) { - if (notBackground()) return browser.runtime.sendMessage({type: "state", command: "stateGet", args: [{prop: property}]}) + if (notBackground()) + return browser.runtime.sendMessage({ + type: "state", + command: "stateGet", + args: [{ prop: property }], + }) else return state[property] } @@ -85,7 +95,7 @@ messaging.addListener("state", (message, sender, sendResponse) => { overlay[property] = value } else if (message.command == "stateGet") { sendResponse(state[message.args[0].prop]) - } else throw("Unsupported message to state, type " + message.command) + } else throw "Unsupported message to state, type " + message.command }) export { state as default }