Reduce lint errors

This commit is contained in:
Zef Hemel
2022-10-15 19:02:56 +02:00
parent 68809ff958
commit 574014a8be
27 changed files with 199 additions and 194 deletions
+12 -12
View File
@@ -12,17 +12,17 @@ export const pasteLinkExtension = ViewPlugin.fromClass(
update(update: ViewUpdate): void {
update.transactions.forEach((tr) => {
if (tr.isUserEvent("input.paste")) {
let pastedText: string[] = [];
const pastedText: string[] = [];
let from = 0;
let to = 0;
tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
tr.changes.iterChanges((fromA, _toA, _fromB, toB, inserted) => {
pastedText.push(inserted.sliceString(0));
from = fromA;
to = toB;
});
let pastedString = pastedText.join("");
const pastedString = pastedText.join("");
if (pastedString.match(urlRegexp)) {
let selection = update.startState.selection.main;
const selection = update.startState.selection.main;
if (!selection.empty) {
setTimeout(() => {
update.view.dispatch({
@@ -57,7 +57,7 @@ export function attachmentExtension(editor: Editor) {
// TODO: This doesn't take into account the target cursor position,
// it just drops the attachment wherever the cursor was last.
if (event.dataTransfer) {
let payload = [...event.dataTransfer.files];
const payload = [...event.dataTransfer.files];
if (!payload.length) {
return;
}
@@ -67,7 +67,7 @@ export function attachmentExtension(editor: Editor) {
}
},
paste: (event: ClipboardEvent) => {
let payload = [...event.clipboardData!.items];
const payload = [...event.clipboardData!.items];
if (!payload.length || payload.length === 0) {
return false;
}
@@ -78,23 +78,23 @@ export function attachmentExtension(editor: Editor) {
});
async function processFileTransfer(payload: File[]) {
let data = await payload[0].arrayBuffer();
const data = await payload[0].arrayBuffer();
await saveFile(data!, payload[0].name, payload[0].type);
}
async function processItemTransfer(payload: DataTransferItem[]) {
let file = payload.find((item) => item.kind === "file");
const file = payload.find((item) => item.kind === "file");
if (!file) {
return false;
}
const fileType = file.type;
let ext = fileType.split("/")[1];
let fileName = new Date()
const ext = fileType.split("/")[1];
const fileName = new Date()
.toISOString()
.split(".")[0]
.replace("T", "_")
.replaceAll(":", "-");
let data = await file!.getAsFile()?.arrayBuffer();
const data = await file!.getAsFile()?.arrayBuffer();
await saveFile(data!, `${fileName}.${ext}`, fileType);
}
@@ -113,7 +113,7 @@ export function attachmentExtension(editor: Editor) {
return;
}
let finalFileName = prompt(
const finalFileName = prompt(
"File name for pasted attachment",
suggestedName,
);
+6 -6
View File
@@ -31,7 +31,7 @@ export class SlashCommandHook implements Hook<SlashCommandHookT> {
buildAllCommands(system: System<SlashCommandHookT>) {
this.slashCommands.clear();
for (let plug of system.loadedPlugs.values()) {
for (const plug of system.loadedPlugs.values()) {
for (
const [name, functionDef] of Object.entries(
plug.manifest!.functions,
@@ -55,19 +55,19 @@ export class SlashCommandHook implements Hook<SlashCommandHookT> {
public slashCommandCompleter(
ctx: CompletionContext,
): CompletionResult | null {
let prefix = ctx.matchBefore(slashCommandRegexp);
const prefix = ctx.matchBefore(slashCommandRegexp);
if (!prefix) {
return null;
}
const prefixText = prefix.text;
let options: Completion[] = [];
const options: Completion[] = [];
// No slash commands in comment blocks (queries and such)
let currentNode = syntaxTree(ctx.state).resolveInner(ctx.pos);
const currentNode = syntaxTree(ctx.state).resolveInner(ctx.pos);
if (currentNode.type.name === "CommentBlock") {
return null;
}
for (let [name, def] of this.slashCommands.entries()) {
for (const def of this.slashCommands.values()) {
options.push({
label: def.slashCommand.name,
detail: def.slashCommand.description,
@@ -105,7 +105,7 @@ export class SlashCommandHook implements Hook<SlashCommandHookT> {
}
validateManifest(manifest: Manifest<SlashCommandHookT>): string[] {
let errors = [];
const errors = [];
for (const [name, functionDef] of Object.entries(manifest.functions)) {
if (!functionDef.slashCommand) {
continue;
+3 -3
View File
@@ -35,10 +35,10 @@ class InlineImageWidget extends WidgetType {
}
const inlineImages = (view: EditorView) => {
let widgets: Range<Decoration>[] = [];
const widgets: Range<Decoration>[] = [];
const imageRegex = /!\[(?<title>[^\]]*)\]\((?<url>.+)\)/;
for (let { from, to } of view.visibleRanges) {
for (const { from, to } of view.visibleRanges) {
syntaxTree(view.state).iterate({
from,
to,
@@ -56,7 +56,7 @@ const inlineImages = (view: EditorView) => {
const url = imageRexexResult.groups.url;
const title = imageRexexResult.groups.title;
let deco = Decoration.widget({
const deco = Decoration.widget({
widget: new InlineImageWidget(url, title),
});
widgets.push(deco.range(node.to));
+11 -10
View File
@@ -1,8 +1,5 @@
import { Action, AppViewState } from "./types.ts";
let m = new Map();
m.size;
export default function reducer(
state: AppViewState,
action: Action,
@@ -49,11 +46,13 @@ export default function reducer(
...state,
showPageNavigator: false,
};
case "pages-listed":
case "pages-listed": {
// Let's move over any "lastOpened" times to the "allPages" list
let oldPageMeta = new Map([...state.allPages].map((pm) => [pm.name, pm]));
for (let pageMeta of action.pages) {
let oldPageMetaItem = oldPageMeta.get(pageMeta.name);
const oldPageMeta = new Map(
[...state.allPages].map((pm) => [pm.name, pm]),
);
for (const pageMeta of action.pages) {
const oldPageMetaItem = oldPageMeta.get(pageMeta.name);
if (oldPageMetaItem && oldPageMetaItem.lastOpened) {
pageMeta.lastOpened = oldPageMetaItem.lastOpened;
}
@@ -62,9 +61,10 @@ export default function reducer(
...state,
allPages: action.pages,
};
case "show-palette":
let commands = new Map(state.commands);
for (let [k, v] of state.commands.entries()) {
}
case "show-palette": {
const commands = new Map(state.commands);
for (const [k, v] of state.commands.entries()) {
if (
v.command.contexts &&
(!action.context || !v.command.contexts.includes(action.context))
@@ -77,6 +77,7 @@ export default function reducer(
commands,
showCommandPalette: true,
};
}
case "hide-palette":
return {
...state,
+30 -30
View File
@@ -11,9 +11,9 @@ type SyntaxNode = {
};
function ensureAnchor(expr: any, start: boolean) {
var _a;
let { source } = expr;
let addStart = start && source[0] != "^",
let _a;
const { source } = expr;
const addStart = start && source[0] != "^",
addEnd = source[source.length - 1] != "$";
if (!addStart && !addEnd) return expr;
return new RegExp(
@@ -40,11 +40,11 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
"editor.getSelection": (): { from: number; to: number } => {
return editor.editorView!.state.selection.main;
},
"editor.save": async () => {
"editor.save": () => {
return editor.save(true);
},
"editor.navigate": async (
ctx,
_ctx,
name: string,
pos: number | string,
replaceState = false,
@@ -55,29 +55,29 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
await editor.reloadPage();
},
"editor.openUrl": (_ctx, url: string) => {
let win = window.open(url, "_blank");
const win = window.open(url, "_blank");
if (win) {
win.focus();
}
},
"editor.flashNotification": (
ctx,
_ctx,
message: string,
type: "error" | "info" = "info",
) => {
editor.flashNotification(message, type);
},
"editor.filterBox": (
ctx,
_ctx,
label: string,
options: FilterOption[],
helpText: string = "",
placeHolder: string = "",
helpText = "",
placeHolder = "",
): Promise<FilterOption | undefined> => {
return editor.filterBox(label, options, helpText, placeHolder);
},
"editor.showPanel": (
ctx,
_ctx,
id: string,
mode: number,
html: string,
@@ -89,13 +89,13 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
config: { html, script, mode },
});
},
"editor.hidePanel": (ctx, id: string) => {
"editor.hidePanel": (_ctx, id: string) => {
editor.viewDispatch({
type: "hide-panel",
id: id as any,
});
},
"editor.insertAtPos": (ctx, text: string, pos: number) => {
"editor.insertAtPos": (_ctx, text: string, pos: number) => {
editor.editorView!.dispatch({
changes: {
insert: text,
@@ -103,7 +103,7 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
},
});
},
"editor.replaceRange": (ctx, from: number, to: number, text: string) => {
"editor.replaceRange": (_ctx, from: number, to: number, text: string) => {
editor.editorView!.dispatch({
changes: {
insert: text,
@@ -112,15 +112,15 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
},
});
},
"editor.moveCursor": (ctx, pos: number) => {
"editor.moveCursor": (_ctx, pos: number) => {
editor.editorView!.dispatch({
selection: {
anchor: pos,
},
});
},
"editor.setSelection": (ctx, from: number, to: number) => {
let editorView = editor.editorView!;
"editor.setSelection": (_ctx, from: number, to: number) => {
const editorView = editor.editorView!;
editorView.dispatch({
selection: {
anchor: from,
@@ -129,9 +129,9 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
});
},
"editor.insertAtCursor": (ctx, text: string) => {
let editorView = editor.editorView!;
let from = editorView.state.selection.main.from;
"editor.insertAtCursor": (_ctx, text: string) => {
const editorView = editor.editorView!;
const from = editorView.state.selection.main.from;
editorView.dispatch({
changes: {
insert: text,
@@ -144,17 +144,17 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
},
"editor.matchBefore": (
ctx,
_ctx,
regexp: string,
): { from: number; to: number; text: string } | null => {
const editorState = editor.editorView!.state;
let selection = editorState.selection.main;
let from = selection.from;
const selection = editorState.selection.main;
const from = selection.from;
if (selection.empty) {
let line = editorState.doc.lineAt(from);
let start = Math.max(line.from, from - 250);
let str = line.text.slice(start - line.from, from - line.from);
let found = str.search(ensureAnchor(new RegExp(regexp), false));
const line = editorState.doc.lineAt(from);
const start = Math.max(line.from, from - 250);
const str = line.text.slice(start - line.from, from - line.from);
const found = str.search(ensureAnchor(new RegExp(regexp), false));
// console.log("Line", line, start, str, new RegExp(regexp), found);
return found < 0
? null
@@ -162,17 +162,17 @@ export function editorSyscalls(editor: Editor): SysCallMapping {
}
return null;
},
"editor.dispatch": (ctx, change: Transaction) => {
"editor.dispatch": (_ctx, change: Transaction) => {
editor.editorView!.dispatch(change);
},
"editor.prompt": (
ctx,
_ctx,
message: string,
defaultValue = "",
): string | null => {
return prompt(message, defaultValue);
},
"editor.enableReadOnlyMode": (ctx, enabled: boolean) => {
"editor.enableReadOnlyMode": (_ctx, enabled: boolean) => {
editor.viewDispatch({
type: "set-editor-ro",
enabled,