From 47f504f2cec4048db1e44d0eca7fddda58efd60f Mon Sep 17 00:00:00 2001 From: Zef Hemel Date: Fri, 2 Aug 2024 17:14:40 +0200 Subject: [PATCH] deno fmt --- cmd/test/test_func.test.ts | 12 ++-- common/expression_parser.test.ts | 4 +- common/expression_parser.ts | 8 +-- common/markdown_parser/constants.ts | 2 +- common/syscalls/jsonschema.ts | 34 +++++----- deno.json | 8 ++- lib/data/datastore.bench.ts | 96 ++++++++++++++--------------- plugs/federation/util.test.ts | 24 ++++---- plugs/federation/util.ts | 14 ++--- plugs/search/search.ts | 5 +- server/syscalls/space.ts | 6 +- web/cm_plugins/iframe_widget.ts | 5 +- web/cm_plugins/markdown_widget.ts | 2 +- web/cm_plugins/util.ts | 6 +- web/commands.ts | 6 +- web/components/filter.tsx | 4 +- web/components/panel.tsx | 11 +++- web/components/top_bar.tsx | 6 +- web/sync_service.ts | 6 +- web/syscalls/space.ts | 6 +- web/syscalls/util.ts | 5 +- 21 files changed, 153 insertions(+), 117 deletions(-) diff --git a/cmd/test/test_func.test.ts b/cmd/test/test_func.test.ts index 29db199b..47094da9 100644 --- a/cmd/test/test_func.test.ts +++ b/cmd/test/test_func.test.ts @@ -1,10 +1,10 @@ import * as YAML from "js-yaml"; export async function hello() { - // @ts-ignore: syscall is a global function - const numbers = await syscall("addNumbers", 1, 2); - return { - yamlMessage: YAML.dump({ hello: "world" }), - addedNumbers: numbers, - }; + // @ts-ignore: syscall is a global function + const numbers = await syscall("addNumbers", 1, 2); + return { + yamlMessage: YAML.dump({ hello: "world" }), + addedNumbers: numbers, + }; } diff --git a/common/expression_parser.test.ts b/common/expression_parser.test.ts index c8f7f239..b272d763 100644 --- a/common/expression_parser.test.ts +++ b/common/expression_parser.test.ts @@ -2,6 +2,6 @@ import { assertEquals } from "@std/assert"; import { parseExpression } from "$common/expression_parser.ts"; Deno.test("Test expression parser", () => { - // Just a sanity check here - assertEquals(parseExpression("1 + 2"), ["+", ["number", 1], ["number", 2]]); + // Just a sanity check here + assertEquals(parseExpression("1 + 2"), ["+", ["number", 1], ["number", 2]]); }); diff --git a/common/expression_parser.ts b/common/expression_parser.ts index 74c54ad0..db12353d 100644 --- a/common/expression_parser.ts +++ b/common/expression_parser.ts @@ -5,8 +5,8 @@ import { expressionToKvQueryExpression } from "$sb/lib/parse-query.ts"; import { lezerToParseTree } from "$common/markdown_parser/parse_tree.ts"; export function parseExpression(s: string): QueryExpression { - const ast = parseTreeToAST( - lezerToParseTree(s, expressionLanguage.parser.parse(s).topNode), - ); - return expressionToKvQueryExpression(ast[1]); + const ast = parseTreeToAST( + lezerToParseTree(s, expressionLanguage.parser.parse(s).topNode), + ); + return expressionToKvQueryExpression(ast[1]); } diff --git a/common/markdown_parser/constants.ts b/common/markdown_parser/constants.ts index 69d1a383..f976b23e 100644 --- a/common/markdown_parser/constants.ts +++ b/common/markdown_parser/constants.ts @@ -1,5 +1,5 @@ export const wikiLinkRegex = /(!?\[\[)([^\]\|]+)(?:\|([^\]]+))?(\]\])/g; // [fullMatch, firstMark, url, alias, lastMark] export const mdLinkRegex = /!?\[(?[^\]]*)\]\((?<url>.+)\)/g; // [fullMatch, alias, url] export const tagRegex = - /#[^\d\s!@#$%^&*(),.?":{}|<>\\][^\s!@#$%^&*(),.?":{}|<>\\]*/; + /#[^\d\s!@#$%^&*(),.?":{}|<>\\][^\s!@#$%^&*(),.?":{}|<>\\]*/; export const pWikiLinkRegex = new RegExp("^" + wikiLinkRegex.source); // Modified regex used only in parser diff --git a/common/syscalls/jsonschema.ts b/common/syscalls/jsonschema.ts index bac7bc53..cb351e76 100644 --- a/common/syscalls/jsonschema.ts +++ b/common/syscalls/jsonschema.ts @@ -4,21 +4,21 @@ import Ajv from "ajv"; const ajv = new Ajv(); export function jsonschemaSyscalls(): SysCallMapping { - return { - "jsonschema.validateObject": ( - _ctx, - schema: any, - object: any, - ): undefined | string => { - const validate = ajv.compile(schema); - if (validate(object)) { - return; - } else { - let text = ajv.errorsText(validate.errors); - text = text.replaceAll("/", "."); - text = text.replace(/^data\./, ""); - return text; - } - }, - }; + return { + "jsonschema.validateObject": ( + _ctx, + schema: any, + object: any, + ): undefined | string => { + const validate = ajv.compile(schema); + if (validate(object)) { + return; + } else { + let text = ajv.errorsText(validate.errors); + text = text.replaceAll("/", "."); + text = text.replace(/^data\./, ""); + return text; + } + }, + }; } diff --git a/deno.json b/deno.json index 3b2a8389..96d9604d 100644 --- a/deno.json +++ b/deno.json @@ -18,6 +18,7 @@ "check": "find . -name '*.ts*' | xargs deno check", "lint": "deno lint", + "fmt": "deno fmt", "test": "deno test -A --unstable-kv --unstable-worker-options", "bench": "deno bench", @@ -53,12 +54,13 @@ }, "fmt": { "exclude": [ - "dist", - "dist_bundle", + "dist*", "website", "website_build", "test_space", - "README.md" + "**/*.md", + "**/*.js", + "**/*.json" ] }, "compilerOptions": { diff --git a/lib/data/datastore.bench.ts b/lib/data/datastore.bench.ts index 3774a0a1..6561a448 100644 --- a/lib/data/datastore.bench.ts +++ b/lib/data/datastore.bench.ts @@ -2,59 +2,59 @@ import { DataStore } from "$lib/data/datastore.ts"; import { MemoryKvPrimitives } from "$lib/data/memory_kv_primitives.ts"; Deno.bench("DataStore enrichment benchmark with match", (b) => { - // Dummy datastore with a single object enricher - const datastore = new DataStore(new MemoryKvPrimitives(), {}); + // Dummy datastore with a single object enricher + const datastore = new DataStore(new MemoryKvPrimitives(), {}); - datastore.objectDecorators = [ - { - where: ["=", ["attr", "tags"], ["string", "person"]], - attributes: { - fullName: ["+", ["+", ["attr", "firstName"], ["string", " "]], [ - "attr", - "lastName", - ]], - }, - }, - ]; + datastore.objectDecorators = [ + { + where: ["=", ["attr", "tags"], ["string", "person"]], + attributes: { + fullName: ["+", ["+", ["attr", "firstName"], ["string", " "]], [ + "attr", + "lastName", + ]], + }, + }, + ]; - b.start(); - // Let's try with half a million entries - for (let i = 0; i < 500000; i++) { - const obj = { - firstName: "Pete", - lastName: "Smith", - tags: ["person"], - }; - datastore.enrichObject(obj); - } - b.end(); + b.start(); + // Let's try with half a million entries + for (let i = 0; i < 500000; i++) { + const obj = { + firstName: "Pete", + lastName: "Smith", + tags: ["person"], + }; + datastore.enrichObject(obj); + } + b.end(); }); Deno.bench("DataStore enrichment benchmark without match", (b) => { - // Dummy datastore with a single object enricher - const datastore = new DataStore(new MemoryKvPrimitives(), {}); + // Dummy datastore with a single object enricher + const datastore = new DataStore(new MemoryKvPrimitives(), {}); - datastore.objectDecorators = [ - { - where: ["=", ["attr", "tags"], ["string", "person"]], - attributes: { - fullName: ["+", ["+", ["attr", "firstName"], ["string", " "]], [ - "attr", - "lastName", - ]], - }, - }, - ]; + datastore.objectDecorators = [ + { + where: ["=", ["attr", "tags"], ["string", "person"]], + attributes: { + fullName: ["+", ["+", ["attr", "firstName"], ["string", " "]], [ + "attr", + "lastName", + ]], + }, + }, + ]; - b.start(); - // Let's try with half a million entries - for (let i = 0; i < 500000; i++) { - const obj = { - firstName: "Pete", - lastName: "Smith", - tags: ["peson"], - }; - datastore.enrichObject(obj); - } - b.end(); + b.start(); + // Let's try with half a million entries + for (let i = 0; i < 500000; i++) { + const obj = { + firstName: "Pete", + lastName: "Smith", + tags: ["peson"], + }; + datastore.enrichObject(obj); + } + b.end(); }); diff --git a/plugs/federation/util.test.ts b/plugs/federation/util.test.ts index 29d1348a..1322fe2a 100644 --- a/plugs/federation/util.test.ts +++ b/plugs/federation/util.test.ts @@ -2,19 +2,19 @@ import { assert, assertEquals } from "@std/assert"; import { federatedPathToLocalPath, wildcardPathToRegex } from "./util.ts"; Deno.test("Test wildcardPathToRegex", () => { - assert(wildcardPathToRegex("test").test("test")); - assert(wildcardPathToRegex("test").test("test.md")); - assert(wildcardPathToRegex("test*").test("test")); - assert(wildcardPathToRegex("test/*").test("test/bla")); - assert(wildcardPathToRegex("test/*").test("test/bla.md")); - assert(wildcardPathToRegex("test/*").test("test/bla/bla")); - assert(!wildcardPathToRegex("test/*").test("tests/bla/bla")); + assert(wildcardPathToRegex("test").test("test")); + assert(wildcardPathToRegex("test").test("test.md")); + assert(wildcardPathToRegex("test*").test("test")); + assert(wildcardPathToRegex("test/*").test("test/bla")); + assert(wildcardPathToRegex("test/*").test("test/bla.md")); + assert(wildcardPathToRegex("test/*").test("test/bla/bla")); + assert(!wildcardPathToRegex("test/*").test("tests/bla/bla")); }); Deno.test("Test federatedPathToLocalPath", () => { - assertEquals(federatedPathToLocalPath("!silverbullet.md"), ""); - assertEquals( - federatedPathToLocalPath("!silverbullet.md/Library/Core/test"), - "Library/Core/test", - ); + assertEquals(federatedPathToLocalPath("!silverbullet.md"), ""); + assertEquals( + federatedPathToLocalPath("!silverbullet.md/Library/Core/test"), + "Library/Core/test", + ); }); diff --git a/plugs/federation/util.ts b/plugs/federation/util.ts index ebe3fedf..6cdee867 100644 --- a/plugs/federation/util.ts +++ b/plugs/federation/util.ts @@ -1,14 +1,14 @@ export function wildcardPathToRegex(pattern: string): RegExp { - // Escape special characters in the pattern except for the wildcard "*" - const escapedPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&"); + // Escape special characters in the pattern except for the wildcard "*" + const escapedPattern = pattern.replace(/[.+?^${}()|[\]\\]/g, "\\$&"); - // Replace the wildcard "*" with ".*" to match any character sequence - const regexPattern = escapedPattern.replace(/\*/g, ".*"); + // Replace the wildcard "*" with ".*" to match any character sequence + const regexPattern = escapedPattern.replace(/\*/g, ".*"); - // Create a new regular expression with the converted pattern - return new RegExp(`^${regexPattern}(\\.md)?$`); + // Create a new regular expression with the converted pattern + return new RegExp(`^${regexPattern}(\\.md)?$`); } export function federatedPathToLocalPath(path: string): string { - return path.split("/").slice(1).join("/"); + return path.split("/").slice(1).join("/"); } diff --git a/plugs/search/search.ts b/plugs/search/search.ts index 27d0dc98..7c0a3c68 100644 --- a/plugs/search/search.ts +++ b/plugs/search/search.ts @@ -1,4 +1,7 @@ -import type { IndexTreeEvent, QueryProviderEvent } from "../../plug-api/types.ts"; +import type { + IndexTreeEvent, + QueryProviderEvent, +} from "../../plug-api/types.ts"; import { renderToText } from "$sb/lib/tree.ts"; import { applyQuery, liftAttributeFilter } from "$sb/lib/query.ts"; import { editor } from "$sb/syscalls.ts"; diff --git a/server/syscalls/space.ts b/server/syscalls/space.ts index 05de4301..e41965a3 100644 --- a/server/syscalls/space.ts +++ b/server/syscalls/space.ts @@ -1,4 +1,8 @@ -import type { AttachmentMeta, FileMeta, PageMeta } from "../../plug-api/types.ts"; +import type { + AttachmentMeta, + FileMeta, + PageMeta, +} from "../../plug-api/types.ts"; import type { SysCallMapping } from "../../lib/plugos/system.ts"; import type { Space } from "../../common/space.ts"; diff --git a/web/cm_plugins/iframe_widget.ts b/web/cm_plugins/iframe_widget.ts index c0c0052c..9b0fa61f 100644 --- a/web/cm_plugins/iframe_widget.ts +++ b/web/cm_plugins/iframe_widget.ts @@ -1,4 +1,7 @@ -import type { CodeWidgetCallback, WidgetContent } from "../../plug-api/types.ts"; +import type { + CodeWidgetCallback, + WidgetContent, +} from "../../plug-api/types.ts"; import { WidgetType } from "@codemirror/view"; import type { Client } from "../client.ts"; import { createWidgetSandboxIFrame } from "../components/widget_sandbox_iframe.ts"; diff --git a/web/cm_plugins/markdown_widget.ts b/web/cm_plugins/markdown_widget.ts index d7f23d73..13e6a6d6 100644 --- a/web/cm_plugins/markdown_widget.ts +++ b/web/cm_plugins/markdown_widget.ts @@ -93,7 +93,7 @@ export class MarkdownWidget extends WidgetType { extendedMarkdownLanguage, trimmedMarkdown, ); - + const html = renderMarkdownToHtml(mdTree, { // Annotate every element with its position so we can use it to put // the cursor there when the user clicks on the table. diff --git a/web/cm_plugins/util.ts b/web/cm_plugins/util.ts index 012376a5..1cf107f9 100644 --- a/web/cm_plugins/util.ts +++ b/web/cm_plugins/util.ts @@ -1,7 +1,11 @@ // Forked from https://codeberg.org/retronav/ixora // Original author: Pranav Karawale // License: Apache License 2.0. -import { type EditorState, StateField, type Transaction } from "@codemirror/state"; +import { + type EditorState, + StateField, + type Transaction, +} from "@codemirror/state"; import type { DecorationSet } from "@codemirror/view"; import { Decoration, EditorView, WidgetType } from "@codemirror/view"; type LinkOptions = { diff --git a/web/commands.ts b/web/commands.ts index 8a714641..04663c9d 100644 --- a/web/commands.ts +++ b/web/commands.ts @@ -1,4 +1,8 @@ -import { EditorSelection, type StateCommand, Transaction } from "@codemirror/state"; +import { + EditorSelection, + type StateCommand, + Transaction, +} from "@codemirror/state"; import { Text } from "@codemirror/state"; export function insertMarker(marker: string): StateCommand { diff --git a/web/components/filter.tsx b/web/components/filter.tsx index c651cae1..95e0a8da 100644 --- a/web/components/filter.tsx +++ b/web/components/filter.tsx @@ -200,7 +200,9 @@ export function FilterList({ className={(selectedOption === idx ? "sb-option sb-selected-option" : "sb-option") + - (option.cssClass ? " sb-decorated-object " + option.cssClass : "")} + (option.cssClass + ? " sb-decorated-object " + option.cssClass + : "")} onMouseMove={() => { if (selectedOption !== idx) { setSelectionOption(idx); diff --git a/web/components/panel.tsx b/web/components/panel.tsx index c1a3dfd8..dc503e5d 100644 --- a/web/components/panel.tsx +++ b/web/components/panel.tsx @@ -21,7 +21,7 @@ export function Panel({ type: "html", html: config.html, script: config.script, - theme: document.getElementsByTagName("html")[0].dataset.theme + theme: document.getElementsByTagName("html")[0].dataset.theme, }); } @@ -31,7 +31,7 @@ export function Panel({ return; } - iframe.addEventListener("load", updateContent) + iframe.addEventListener("load", updateContent); updateContent(); return () => { @@ -89,7 +89,12 @@ export function Panel({ return ( <div className="sb-panel" style={{ flex: config.mode }}> - <iframe srcDoc={panelHtml} ref={iFrameRef} style={{ visibility: 'hidden' }} onLoad={() => iFrameRef.current!.style.visibility = "visible" }/> + <iframe + srcDoc={panelHtml} + ref={iFrameRef} + style={{ visibility: "hidden" }} + onLoad={() => iFrameRef.current!.style.visibility = "visible"} + /> </div> ); } diff --git a/web/components/top_bar.tsx b/web/components/top_bar.tsx index 33c8c4f4..521ca491 100644 --- a/web/components/top_bar.tsx +++ b/web/components/top_bar.tsx @@ -69,10 +69,8 @@ export function TopBar({ ? "sb-loading" : unsavedChanges ? "sb-unsaved" - : "sb-saved") + - (cssClass - ? " sb-decorated-object " + cssClass - : "")} + : "sb-saved") + + (cssClass ? " sb-decorated-object " + cssClass : "")} > <MiniEditor text={pageName ?? ""} diff --git a/web/sync_service.ts b/web/sync_service.ts index 87d91491..71e0663b 100644 --- a/web/sync_service.ts +++ b/web/sync_service.ts @@ -1,6 +1,10 @@ import { plugPrefix } from "$common/spaces/constants.ts"; import type { SpacePrimitives } from "$common/spaces/space_primitives.ts"; -import { SpaceSync, type SyncStatus, type SyncStatusItem } from "$common/spaces/sync.ts"; +import { + SpaceSync, + type SyncStatus, + type SyncStatusItem, +} from "$common/spaces/sync.ts"; import { sleep } from "$lib/async.ts"; import type { EventHook } from "../common/hooks/event.ts"; import type { DataStore } from "$lib/data/datastore.ts"; diff --git a/web/syscalls/space.ts b/web/syscalls/space.ts index e8531d5b..30f6e54d 100644 --- a/web/syscalls/space.ts +++ b/web/syscalls/space.ts @@ -1,6 +1,10 @@ import type { Client } from "../client.ts"; import type { SysCallMapping } from "../../lib/plugos/system.ts"; -import type { AttachmentMeta, FileMeta, PageMeta } from "../../plug-api/types.ts"; +import type { + AttachmentMeta, + FileMeta, + PageMeta, +} from "../../plug-api/types.ts"; export function spaceReadSyscalls(editor: Client): SysCallMapping { return { diff --git a/web/syscalls/util.ts b/web/syscalls/util.ts index 2b2a8531..67e9cb96 100644 --- a/web/syscalls/util.ts +++ b/web/syscalls/util.ts @@ -1,5 +1,8 @@ import type { HttpSpacePrimitives } from "$common/spaces/http_space_primitives.ts"; -import type { SyscallContext, SysCallMapping } from "../../lib/plugos/system.ts"; +import type { + SyscallContext, + SysCallMapping, +} from "../../lib/plugos/system.ts"; import type { Client } from "../client.ts"; export function proxySyscalls(client: Client, names: string[]): SysCallMapping {