Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
chore: address requested changes
Elian Doranfcaf9cb3569a
diff --git a/packages/codemirror/package.json b/packages/codemirror/package.jsonindex f5bec91f10..23cb406dc1 100644--- a/packages/codemirror/package.json+++ b/packages/codemirror/package.json@@ -17,6 +17,7 @@"@codemirror/lang-vue": "0.1.3","@codemirror/lang-xml": "6.1.0","@codemirror/legacy-modes": "6.5.3",+ "@codemirror/lint": "6.9.6","@codemirror/autocomplete": "6.20.2","@codemirror/search": "6.7.0","@codemirror/state": "6.6.0",diff --git a/packages/codemirror/src/type_completion/index.spec.ts b/packages/codemirror/src/type_completion/index.spec.tsindex 7ed73d2c4a..16f8f02ebf 100644--- a/packages/codemirror/src/type_completion/index.spec.ts+++ b/packages/codemirror/src/type_completion/index.spec.ts@@ -18,6 +18,8 @@ const TS_TYPE_NOT_ASSIGNABLE = 2322;const TS_TOP_LEVEL_AWAIT = 1375;/** "Cannot find name '$'. Do you need to install type definitions for jQuery?…" */const TS_JQUERY_NOT_FOUND = 2592;+/** "Unreachable code detected." — the one diagnostic rendered as a warning marker. */+const TS_UNREACHABLE_CODE = 7027;// Loading TypeScript + the bundled lib.*.d.ts the first time is not instant.const TIMEOUT = 30_000;@@ -104,6 +106,16 @@ describe("script note diagnostics", () => {expect(codes).toContain(TS_UNKNOWN_PROPERTY);}, TIMEOUT);+ it("flags unreachable code (TS7027) — the editor's one warning-severity diagnostic", async () => {+ // `allowUnreachableCode: false` surfaces dead code after a `return` as a+ // warning marker in the gutter.+ const codes = await getScriptDiagnosticCodes(+ SCRIPT_MIME_BACKEND,+ "function f() {\n return 1;\n console.log('dead');\n}"+ );+ expect(codes).toContain(TS_UNREACHABLE_CODE);+ }, TIMEOUT);+it("allows extending api widget base classes (constructor types, not unknown)", async () => {const codes = await getScriptDiagnosticCodes(SCRIPT_MIME_FRONTEND,diff --git a/packages/codemirror/src/type_completion/index.ts b/packages/codemirror/src/type_completion/index.tsindex e9548d4dda..752c81b05c 100644--- a/packages/codemirror/src/type_completion/index.ts+++ b/packages/codemirror/src/type_completion/index.ts@@ -80,6 +80,11 @@ const COMPILER_OPTIONS = {// useful semantic checks (unknown api members, wrong arg counts) but don't nag about// missing type annotations.noImplicitAny: false,+ // Surface dead code (e.g. statements after a `return`) as a TS7027 "Unreachable+ // code detected." diagnostic, which `@valtown/codemirror-ts` renders as a+ // *warning* marker rather than an error — the one warning-severity diagnostic+ // the script linter emits.+ allowUnreachableCode: false,// `@typescript/vfs` defaults moduleResolution to the legacy `node10`, which// TypeScript 6 rejects unless deprecations are explicitly silenced.ignoreDeprecations: "6.0"@@ -191,6 +196,9 @@ export async function buildTypeCompletion(mime: string, context: ScriptApiContexconst env = await createEnv(mime, context);const { tsFacet, tsSync, tsAutocomplete, tsLinter, tsHover } = await import("@valtown/codemirror-ts");+ // `tsLinter` only underlines diagnostics inline; `lintGutter` adds the+ // error/warning markers in the gutter (as the old ESLint integration did).+ const { lintGutter } = await import("@codemirror/lint");return {extensions: [@@ -198,6 +206,7 @@ export async function buildTypeCompletion(mime: string, context: ScriptApiContextsSync(),tsLinter({ diagnosticCodesToIgnore: ignoredDiagnosticCodes(mime) }),tsHover({ renderTooltip: renderHoverTooltip }),+ lintGutter(),hoverTheme],source: tsAutocomplete()diff --git a/packages/trilium-e2e/src/note_types/code.spec.ts b/packages/trilium-e2e/src/note_types/code.spec.tsindex 325c6100b0..c342e8836b 100644--- a/packages/trilium-e2e/src/note_types/code.spec.ts+++ b/packages/trilium-e2e/src/note_types/code.spec.ts@@ -1,6 +1,12 @@import { test, expect, Page } from "@playwright/test";import App from "../support/app";+// The script linter runs the real TypeScript language service, loaded lazily the+// first time a script note opens. Pulling in the TS compiler + bundled lib.*.d.ts+// is far slower than Playwright's default 5s assertion timeout, so the diagnostic+// assertions get a generous window.+const DIAGNOSTICS_TIMEOUT = 30_000;+test("Displays lint warnings for backend script", async ({ page, context }) => {const app = new App(page, context);await app.goto();@@ -9,12 +15,13 @@ test("Displays lint warnings for backend script", async ({ page, context }) => {const codeEditor = app.currentNoteSplit.locator(".cm-editor");- // Expect two warning signs in the gutter.- await expect(codeEditor.locator(".cm-gutter-lint .cm-lint-marker-warning")).toHaveCount(2);+ // The fixture has unreachable code (statements after `return`) in two+ // functions, so TypeScript emits two TS7027 warnings — one gutter marker each.+ const warningMarker = codeEditor.locator(".cm-gutter-lint .cm-lint-marker-warning");+ await expect(warningMarker).toHaveCount(2, { timeout: DIAGNOSTICS_TIMEOUT });- // Hover over hello- await codeEditor.getByText("hello").first().hover();- await expectTooltip(page, "'hello' is defined but never used.");+ await warningMarker.first().hover();+ await expectTooltip(page, "Unreachable code detected.");});test("Displays lint errors for backend script", async ({ page, context }) => {@@ -25,13 +32,13 @@ test("Displays lint errors for backend script", async ({ page, context }) => {const codeEditor = app.currentNoteSplit.locator(".cm-editor");- // Expect two warning signs in the gutter.+ // The fixture has a typo (`functiox`) that TypeScript can't parse — several+ // diagnostics, all on the same line, collapse to a single error gutter marker.const errorMarker = codeEditor.locator(".cm-gutter-lint .cm-lint-marker-error");- await expect(errorMarker).toHaveCount(1);+ await expect(errorMarker).toHaveCount(1, { timeout: DIAGNOSTICS_TIMEOUT });- // Hover over helloawait errorMarker.hover();- await expectTooltip(page, "Parsing error: Unexpected token world");+ await expectTooltip(page, "Unknown keyword or identifier. Did you mean 'function'?");});async function expectTooltip(page: Page, tooltip: string) {diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex b5e83327dd..6553b4c686 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -1393,6 +1393,9 @@ importers:'@codemirror/legacy-modes':specifier: 6.5.3version: 6.5.3+ '@codemirror/lint':+ specifier: 6.9.6+ version: 6.9.6'@codemirror/search':specifier: 6.7.0version: 6.7.0