From eeeae91e85f5ff79d8188b7c4d739b9df7f6f747 Mon Sep 17 00:00:00 2001 From: Kevin Woblick Date: Wed, 13 May 2026 23:37:19 +0200 Subject: [PATCH] Minor corrections after plugin review --- esbuild.config.mjs | 4 ++-- main.ts | 33 ++++++++++++++++++++++++++++----- manifest.json | 4 ++-- package-lock.json | 24 +++++------------------- package.json | 1 - 5 files changed, 37 insertions(+), 29 deletions(-) diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 7c3c2a5..709c1ad 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -1,6 +1,6 @@ -import builtins from 'builtin-modules'; import esbuild from 'esbuild'; import { sassPlugin } from 'esbuild-sass-plugin'; +import { builtinModules } from 'node:module'; import process from 'process'; const banner = @@ -35,7 +35,7 @@ const context = await esbuild.context({ '@lezer/common', '@lezer/highlight', '@lezer/lr', - ...builtins + ...builtinModules ], format: 'cjs', target: 'es2018', diff --git a/main.ts b/main.ts index f6251b8..4d66e9e 100644 --- a/main.ts +++ b/main.ts @@ -20,6 +20,28 @@ const DEFAULT_SETTINGS: JiraAutoLinkerSettings = { registrations: [], }; +function isRecord(value: unknown): value is Record { + return typeof value === 'object' && value !== null; +} + +function isJiraProjectRegistration(value: unknown): value is JiraProjectRegistration { + return isRecord(value) + && typeof value.projectKey === 'string' + && typeof value.baseUrl === 'string'; +} + +function normalizeSettings(data: unknown): JiraAutoLinkerSettings { + if (!isRecord(data) || !Array.isArray(data.registrations)) { + return { + registrations: [...DEFAULT_SETTINGS.registrations], + }; + } + + return { + registrations: data.registrations.filter(isJiraProjectRegistration), + }; +} + export default class JiraAutoLinker extends Plugin { settings: JiraAutoLinkerSettings; @@ -87,15 +109,15 @@ export default class JiraAutoLinker extends Plugin { } private replaceWithLinks(node: Node, text: string, matches: Array) { - const fragment = document.createDocumentFragment(); + const fragment = createFragment(); let cursor = 0; for (const match of matches) { if (match.start > cursor) { - fragment.appendChild(document.createTextNode(text.substring(cursor, match.start))); + fragment.appendChild(activeDocument.createTextNode(text.substring(cursor, match.start))); } - const anchor = document.createElement('a'); + const anchor = activeDocument.createElement('a'); anchor.textContent = match.matchedText; anchor.href = `${match.registration.baseUrl}/browse/${match.matchedText}`; anchor.target = '_blank'; @@ -105,7 +127,7 @@ export default class JiraAutoLinker extends Plugin { } if (cursor < text.length) { - fragment.appendChild(document.createTextNode(text.substring(cursor))); + fragment.appendChild(activeDocument.createTextNode(text.substring(cursor))); } node.parentNode?.replaceChild(fragment, node); @@ -116,7 +138,8 @@ export default class JiraAutoLinker extends Plugin { } async loadSettings() { - this.settings = Object.assign({}, DEFAULT_SETTINGS, await this.loadData()); + const data: unknown = await this.loadData(); + this.settings = normalizeSettings(data); } async saveSettings() { diff --git a/manifest.json b/manifest.json index d6126a2..782b289 100644 --- a/manifest.json +++ b/manifest.json @@ -2,7 +2,7 @@ "id": "atlassian-jira-auto-linker", "name": "Atlassian Jira Auto-Linker", "version": "1.0.1", - "minAppVersion": "1.0.0", + "minAppVersion": "1.1.0", "description": "Automatically create links to Jira from issue IDs like APP-1426.", "author": "Kevin Woblick", "authorUrl": "https://woblick.dev", @@ -12,4 +12,4 @@ "Liberapay": "https://liberapay.com/kovah" }, "isDesktopOnly": false -} \ No newline at end of file +} diff --git a/package-lock.json b/package-lock.json index 3a0d153..27c1847 100644 --- a/package-lock.json +++ b/package-lock.json @@ -9,15 +9,14 @@ "version": "1.0.1", "license": "MIT", "devDependencies": { - "@types/node": "^22.13.4", - "@typescript-eslint/eslint-plugin": "^8.24.0", - "@typescript-eslint/parser": "^8.24.0", - "builtin-modules": "^4.0.0", - "esbuild": "^0.25.0", + "@types/node": "^22.13.10", + "@typescript-eslint/eslint-plugin": "^8.26.1", + "@typescript-eslint/parser": "^8.26.1", + "esbuild": "^0.25.1", "esbuild-sass-plugin": "^3.3.1", "obsidian": "latest", "tslib": "^2.8.1", - "typescript": "^5.7.3" + "typescript": "^5.8.2" } }, "node_modules/@bufbuild/protobuf": { @@ -1492,19 +1491,6 @@ "license": "MIT/X11", "peer": true }, - "node_modules/builtin-modules": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/builtin-modules/-/builtin-modules-4.0.0.tgz", - "integrity": "sha512-p1n8zyCkt1BVrKNFymOHjcDSAl7oq/gUvfgULv2EblgpPVQlQr9yHnWjg9IJ2MhfwPqiYqMMrr01OY7yQoK2yA==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=18.20" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", diff --git a/package.json b/package.json index 888c940..bb87455 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,6 @@ "@types/node": "^22.13.10", "@typescript-eslint/eslint-plugin": "^8.26.1", "@typescript-eslint/parser": "^8.26.1", - "builtin-modules": "^4.0.0", "esbuild": "^0.25.1", "esbuild-sass-plugin": "^3.3.1", "obsidian": "latest",