Merge pull request #3386 from Rummskartoffel/no-unsafe-call

Fix a few trivial no-unsafe-call errors
This commit is contained in:
Oliver Blanthorn 2021-02-20 11:56:05 +00:00 committed by GitHub
commit 6d8d962e5a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 44 additions and 41 deletions

View file

@ -45,7 +45,7 @@ import * as meta from "@src/background/meta"
state,
webext,
webrequests,
l: prom => prom.then(console.log).catch(console.error),
l: (prom: Promise<any>) => prom.then(console.log).catch(console.error),
contentLocation: window.location,
R,
perf,

View file

@ -1,9 +1,9 @@
import * as useractions from "@src/background/user_actions"
import { useractions } from "@src/background/user_actions"
import * as config from "@src/lib/config"
import * as keyseq from "@src/lib/keyseq"
import * as controller from "@src/lib/controller"
function makelistener(commands) {
function makelistener(commands: Array<browser.commands.Command>) {
return (command_name: string) => {
const command = commands.filter(c => c.name == command_name)[0]
const exstring = config.get(

View file

@ -9,7 +9,7 @@ import * as R from "ramda"
import * as config from "@src/lib/config"
import { getTridactylTabs } from "@src/background/meta"
export function escapehatch() {
function escapehatch() {
if (config.get("escapehatchsidebarhack") == "true") {
// Only works if called via commands API command - fail silently if called otherwise
browser.sidebarAction.open().catch()
@ -35,3 +35,7 @@ export function escapehatch() {
return browser.tabs.update(best.id, { active: true })
})()
}
export const useractions: Record<string, () => void> = {
escapehatch,
}

View file

@ -17,53 +17,54 @@
/** Script used in the commandline iframe. Communicates with background. */
import * as perf from "@src/perf"
import "@src/lib/number.clamp"
import "@src/lib/html-tagged-template"
import { TabAllCompletionSource } from "@src/completions/TabAll"
import * as SELF from "@src/commandline_frame"
import { CompletionSourceFuse } from "@src/completions"
import { AproposCompletionSource } from "@src/completions/Apropos"
import { BindingsCompletionSource } from "@src/completions/Bindings"
import { BufferCompletionSource } from "@src/completions/Tab"
import { BmarkCompletionSource } from "@src/completions/Bmark"
import { ExcmdCompletionSource } from "@src/completions/Excmd"
import { ThemeCompletionSource } from "@src/completions/Theme"
import { CompositeCompletionSource } from "@src/completions/Composite"
import { ExcmdCompletionSource } from "@src/completions/Excmd"
import { ExtensionsCompletionSource } from "@src/completions/Extensions"
import { FileSystemCompletionSource } from "@src/completions/FileSystem"
import { GuisetCompletionSource } from "@src/completions/Guiset"
import { HelpCompletionSource } from "@src/completions/Help"
import { AproposCompletionSource } from "@src/completions/Apropos"
import { HistoryCompletionSource } from "@src/completions/History"
import { PreferenceCompletionSource } from "@src/completions/Preferences"
import { RssCompletionSource } from "@src/completions/Rss"
import { SessionsCompletionSource } from "@src/completions/Sessions"
import { SettingsCompletionSource } from "@src/completions/Settings"
import { BufferCompletionSource } from "@src/completions/Tab"
import { TabAllCompletionSource } from "@src/completions/TabAll"
import { ThemeCompletionSource } from "@src/completions/Theme"
import { WindowCompletionSource } from "@src/completions/Window"
import { ExtensionsCompletionSource } from "@src/completions/Extensions"
import { contentState } from "@src/content/state_content"
import { theme } from "@src/content/styling"
import { getCommandlineFns } from "@src/lib/commandline_cmds"
import * as tri_editor from "@src/lib/editor"
import "@src/lib/html-tagged-template"
import Logger from "@src/lib/logging"
import * as Messaging from "@src/lib/messaging"
import "@src/lib/number.clamp"
import state from "@src/state"
import * as State from "@src/state"
import Logger from "@src/lib/logging"
import { theme } from "@src/content/styling"
import { contentState } from "@src/content/state_content"
import * as genericParser from "@src/parsers/genericmode"
import * as tri_editor from "@src/lib/editor"
import * as perf from "@src/perf"
import state, * as State from "@src/state"
import * as R from "ramda"
import { KeyEventLike } from "./lib/keyseq"
/** @hidden **/
const logger = new Logger("cmdline")
/** @hidden **/
const commandline_state = {
activeCompletions: undefined,
activeCompletions: undefined as CompletionSourceFuse[],
clInput: window.document.getElementById(
"tridactyl-input",
) as HTMLInputElement,
clear,
cmdline_history_position: 0,
completionsDiv: window.document.getElementById("completions"),
fns: undefined,
fns: undefined as ReturnType<typeof getCommandlineFns>,
getCompletion,
history,
/** @hidden
@ -206,7 +207,7 @@ commandline_state.clInput.addEventListener(
// Abuse async to wrap non-promises in a promise
// eslint-disable-next-line @typescript-eslint/require-await
(async () =>
commandline_state.fns[funcname](
commandline_state.fns[funcname as keyof typeof commandline_state.fns](
args.length === 0 ? undefined : args.join(" "),
))(),
)
@ -347,7 +348,7 @@ export function getContent() {
}
/** @hidden **/
export function editor_function(fn_name, ...args) {
export function editor_function(fn_name: keyof typeof tri_editor, ...args) {
let result = Promise.resolve([])
if (tri_editor[fn_name]) {
tri_editor[fn_name](commandline_state.clInput, ...args)
@ -360,11 +361,8 @@ export function editor_function(fn_name, ...args) {
return result
}
import * as SELF from "@src/commandline_frame"
Messaging.addListener("commandline_frame", Messaging.attributeCaller(SELF))
import { getCommandlineFns } from "@src/lib/commandline_cmds"
import { KeyEventLike } from "./lib/keyseq"
commandline_state.fns = getCommandlineFns(commandline_state)
Messaging.addListener(
"commandline_cmd",

View file

@ -86,6 +86,7 @@ import { AutoContain } from "@src/lib/autocontainers"
import * as CSS from "css"
import * as Perf from "@src/perf"
import * as Metadata from "@src/.metadata.generated"
import { ObjectType } from "../compiler/types/ObjectType"
import * as Native from "@src/lib/native"
import * as TTS from "@src/lib/text_to_speech"
import * as excmd_parser from "@src/parsers/exmode"
@ -189,9 +190,9 @@ export async function getNativeVersion(): Promise<string> {
//#content
export async function getRssLinks(): Promise<Array<{ type: string; url: string; title: string }>> {
const seen = new Set<string>()
return Array.from(document.querySelectorAll("a, link[rel='alternate']"))
.filter((e: any) => typeof e.href === "string")
.reduce((acc, e: any) => {
return Array.from(document.querySelectorAll<HTMLAnchorElement | HTMLLinkElement>("a, link[rel='alternate']"))
.filter((e) => typeof e.href === "string")
.reduce((acc, e) => {
let type = ""
// Start by detecting type because url doesn't necessarily contain the words "rss" or "atom"
if (e.type) {
@ -1339,7 +1340,7 @@ export async function url2args() {
/** @hidden */
//#content_helper
let sourceElement
let sourceElement: Element
/** @hidden */
//#content_helper
function removeSource() {
@ -1527,7 +1528,7 @@ export async function apropos(...helpItems: string[]) {
//#background
export async function tutor(newtab?: string) {
const tutor = browser.runtime.getURL("static/clippy/1-tutor.html")
let done
let done: Promise<any>
if (newtab) {
done = tabopen(tutor)
} else {
@ -1976,7 +1977,7 @@ export async function loadaucmds(cmdType: "DocStart" | "DocLoad" | "DocEnd" | "T
try {
await controller.acceptExCmd(aucmds[aukey])
} catch (e) {
logger.error(e.toString())
logger.error((e as Error).toString())
}
}
}
@ -2165,7 +2166,7 @@ export async function tabnext(increment = 1) {
*/
//#background
export async function tabnext_gt(index?: number) {
let done
let done: Promise<any>
if (index === undefined) {
done = tabnext()
} else {
@ -2288,7 +2289,7 @@ export async function tabopen(...addressarr: string[]): Promise<browser.tabs.Tab
const win = await browser.windows.getCurrent()
// Lets us pass both -b and -c in no particular order as long as they are up front.
async function argParse(args): Promise<string[]> {
async function argParse(args: string[]): Promise<string[]> {
if (args[0] === "-b") {
active = false
args.shift()
@ -2735,7 +2736,7 @@ export async function mute(...muteArgs: string[]): Promise<void> {
if (mute) {
updateObj.muted = true
}
let done
let done: Promise<any>
if (all) {
const tabs = await browser.tabs.query({ currentWindow: true })
const promises = []
@ -3105,7 +3106,7 @@ export async function shellescape(...quoteme: string[]) {
}
//#background_helper
import * as useractions from "@src/background/user_actions"
import { useractions } from "@src/background/user_actions"
/**
* Magic escape hatch: if Tridactyl can't run in the current tab, return to a tab in the current window where Tridactyl can run, making such a tab if it doesn't currently exist. If Tridactyl can run in the current tab, return focus to the document body from e.g. the URL bar or a video player.
@ -3628,7 +3629,7 @@ function validateSetArgs(key: string, values: string[]) {
const strval = values.join(" ")
// Note: the conversion will throw if strval can't be converted to the right type
if (md.type.kind === "object" && target.length > 1) {
value = (md as any).type.convertMember(target.slice(1), strval)
value = (md.type as ObjectType).convertMember(target.slice(1), strval)
} else {
value = md.type.convert(strval)
}
@ -4859,7 +4860,7 @@ export async function bmark(url?: string, ...titlearr: string[]) {
if (path != "") {
const tree = (await browser.bookmarks.getTree())[0] // Why would getTree return a tree? Obviously it returns an array of unit length.
// I hate recursion.
const treeClimber = (tree, treestr) => {
const treeClimber = (tree: browser.bookmarks.BookmarkTreeNode, treestr) => {
if (tree.type !== "folder") return {}
treestr += tree.title + "/"
if (!("children" in tree) || tree.children.length === 0) return [{ path: treestr, id: tree.id }]

View file

@ -108,7 +108,7 @@ export const transpose_chars = wrap_input(
* Applies a function to the word the caret is in, or to the next word if the caret is not in a word, or to the previous word if the current word is empty.
*/
function applyWord(
text,
text: string,
selectionStart,
selectionEnd,
fn: (s: string) => string,