From 456d2fd7c439d9da54a341e6512ae39410fb227e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20E=2E?= Date: Thu, 20 Feb 2025 11:38:28 +0100 Subject: [PATCH] [Misc] Code style: use arrow functions --- .../backend-github/src/githubStorage.ts | 2 +- .../src/parseInternalImages.ts | 5 ++-- .../src/parseInternalLinks.ts | 5 ++-- .../src/CristalTiptapImage.ts | 4 ++-- .../src/components/extensions/link-suggest.ts | 4 ++-- editors/tiptap/src/extensions/link.ts | 2 +- editors/tiptap/src/extensions/markdown.ts | 6 ++--- .../impl/src/components/defaultQueueWorker.ts | 2 +- skin/src/vue/c-field.vue | 4 +--- skin/src/vue/contentTools.ts | 23 +++++++++++++++---- .../src/vue/c-edit-xwikiremote.vue | 2 +- 11 files changed, 35 insertions(+), 24 deletions(-) diff --git a/core/backends/backend-github/src/githubStorage.ts b/core/backends/backend-github/src/githubStorage.ts index 820e75b32..58e2f6ce7 100644 --- a/core/backends/backend-github/src/githubStorage.ts +++ b/core/backends/backend-github/src/githubStorage.ts @@ -61,7 +61,7 @@ export class GitHubStorage extends AbstractStorage { return `${this.wikiConfig.baseRestURL}${directory}${image}`; } - hashCode = function (str: string): string { + hashCode = (str: string): string => { let hash = 0, i, chr; diff --git a/core/markdown/markdown-default/src/parseInternalImages.ts b/core/markdown/markdown-default/src/parseInternalImages.ts index 3646b4e32..dc1aba62a 100644 --- a/core/markdown/markdown-default/src/parseInternalImages.ts +++ b/core/markdown/markdown-default/src/parseInternalImages.ts @@ -173,9 +173,8 @@ export function parseInternalImages( modelReferenceParser: ModelReferenceParser, remoteURLSerializer: RemoteURLSerializer, ): MarkdownIt.Core.RuleCore { - return function (state: StateCore): void { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - state.tokens.forEach((blockToken: any) => { + return (state) => { + state.tokens.forEach((blockToken) => { if (blockToken.type == "inline") { handleInlineBlockToken( blockToken, diff --git a/core/markdown/markdown-default/src/parseInternalLinks.ts b/core/markdown/markdown-default/src/parseInternalLinks.ts index 49279b7fd..4e6dc4330 100644 --- a/core/markdown/markdown-default/src/parseInternalLinks.ts +++ b/core/markdown/markdown-default/src/parseInternalLinks.ts @@ -196,9 +196,8 @@ export function parseInternalLinks( modelReferenceParser: ModelReferenceParser, remoteURLSerializer: RemoteURLSerializer, ): MarkdownIt.Core.RuleCore { - return function (state: StateCore): void { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - state.tokens.forEach((blockToken: any) => { + return (state) => { + state.tokens.forEach((blockToken) => { if (blockToken.type == "inline") { handleInlineBlockToken( blockToken, diff --git a/core/tiptap-extensions/tiptap-extension-image/src/CristalTiptapImage.ts b/core/tiptap-extensions/tiptap-extension-image/src/CristalTiptapImage.ts index 0ca4117f0..9e4e902f6 100644 --- a/core/tiptap-extensions/tiptap-extension-image/src/CristalTiptapImage.ts +++ b/core/tiptap-extensions/tiptap-extension-image/src/CristalTiptapImage.ts @@ -41,10 +41,10 @@ function serializeExternal(node: Node, state: MarkdownSerializerState) { * We need to override the default image view to be able to easily add widgets (i.e., visual elements that are not * part of the persisted DOM) using Vue. */ -const initTiptapImage = function ( +const initTiptapImage = ( serializer: ModelReferenceSerializer, parser: RemoteURLParser, -) { +) => { function parseLink(mark: Node): EntityReference | undefined { try { return parser.parse(mark.attrs.src as string); diff --git a/editors/tiptap/src/components/extensions/link-suggest.ts b/editors/tiptap/src/components/extensions/link-suggest.ts index 80d7b3624..5db90cd4b 100644 --- a/editors/tiptap/src/components/extensions/link-suggest.ts +++ b/editors/tiptap/src/components/extensions/link-suggest.ts @@ -112,11 +112,11 @@ function initSuggestionsService( // Return an array of suggestions from a query // TODO: reduce the number of statements in the following method and reactivate the disabled eslint rule. // eslint-disable-next-line max-statements - return async function ({ + return async ({ query, }: { query: string; - }): Promise { + }): Promise => { // TODO: add upload attachment action // TODO: add create new page action // TODO: add links suggestions diff --git a/editors/tiptap/src/extensions/link.ts b/editors/tiptap/src/extensions/link.ts index 067f955cf..de0f1fb42 100644 --- a/editors/tiptap/src/extensions/link.ts +++ b/editors/tiptap/src/extensions/link.ts @@ -76,7 +76,7 @@ export default function initLinkExtension( return "["; } }, - close: function (state: unknown, mark: Mark) { + close: (state: unknown, mark: Mark) => { if (parseLink(mark)) { return `|${serializer.serialize(parser.parse(mark.attrs.href))}]]`; } else { diff --git a/editors/tiptap/src/extensions/markdown.ts b/editors/tiptap/src/extensions/markdown.ts index 4306a0bda..34bab31c7 100644 --- a/editors/tiptap/src/extensions/markdown.ts +++ b/editors/tiptap/src/extensions/markdown.ts @@ -27,10 +27,10 @@ import { RemoteURLSerializer } from "@xwiki/cristal-model-remote-url-api"; import MarkdownIt from "markdown-it"; import { Markdown } from "tiptap-markdown"; -export default function ( +export default ( modelReferenceParser: ModelReferenceParser, remoteURLSerializer: RemoteURLSerializer, -) { +) => { return Markdown.extend({ onBeforeCreate() { const content = this.editor.options.content; @@ -56,4 +56,4 @@ export default function ( this.editor.storage.markdown.parser.parse(content); }, }); -} +}; diff --git a/sharedworker/impl/src/components/defaultQueueWorker.ts b/sharedworker/impl/src/components/defaultQueueWorker.ts index 2e856db2e..fa681e6b2 100644 --- a/sharedworker/impl/src/components/defaultQueueWorker.ts +++ b/sharedworker/impl/src/components/defaultQueueWorker.ts @@ -78,7 +78,7 @@ export default class DefaultQueueWorker implements QueueWorker { // eslint-disable-next-line @typescript-eslint/no-this-alias const that = this; this.workerInstance.setPageLoadedCallback( - Comlink.proxy(function (page: string) { + Comlink.proxy((page) => { that.pageLoaded(page); }), ); diff --git a/skin/src/vue/c-field.vue b/skin/src/vue/c-field.vue index 34a08260e..38bf1f1cd 100644 --- a/skin/src/vue/c-field.vue +++ b/skin/src/vue/c-field.vue @@ -68,9 +68,7 @@ export default defineComponent({ .get(); logger?.debug("Ready to get edit field", props.name); editFieldValue.value = ""; - storage.getEditField(document, props.name).then(function ( - editField: string, - ) { + storage.getEditField(document, props.name).then((editField: string) => { editFieldValue.value = editField; }); } else { diff --git a/skin/src/vue/contentTools.ts b/skin/src/vue/contentTools.ts index 193f8cd27..be423d187 100644 --- a/skin/src/vue/contentTools.ts +++ b/skin/src/vue/contentTools.ts @@ -107,6 +107,7 @@ export class ContentTools { const contentToInject = range.createContextualFragment(html); contentToInject .querySelectorAll("link[href], script[src]") +<<<<<<< HEAD // TODO get rid of any // eslint-disable-next-line @typescript-eslint/no-explicit-any .forEach(function (resource: any) { @@ -121,6 +122,20 @@ export class ContentTools { return null; } }); +======= + .forEach((resource) => { + url1 = resource.getAttribute("src") ?? resource.getAttribute("ref"); + document + .querySelectorAll("link[href], script[src]") + .forEach((resource2) => { + const url2 = + resource2.getAttribute("src") ?? resource2.getAttribute("href"); + + if (url1 && url1 == url2) { + return null; + } + }); +>>>>>>> ad4c7cd7 ([Misc] Code style: use arrow functions) }); return url1; } @@ -128,7 +143,7 @@ export class ContentTools { public static transformImages(cristal: CristalApp, element: string): void { const xwikiContentEl = document.getElementById(element); if (xwikiContentEl) { - const transform = function (img: HTMLImageElement | HTMLScriptElement) { + const transform = (img: HTMLImageElement | HTMLScriptElement) => { const srcItem = img.attributes.getNamedItem("src"); if (srcItem) { ContentTools.logger?.debug("Found image with url ", srcItem.value); @@ -148,7 +163,7 @@ export class ContentTools { } } }; - new MutationObserver(function (mutations: Array) { + new MutationObserver((mutations) => { ContentTools.logger?.debug("Called in mutation records"); for (const { addedNodes } of mutations) { addedNodes.forEach((addedNode) => { @@ -171,7 +186,7 @@ export class ContentTools { * Experimental function to transform scripts */ public static transformScripts(): void { - const transformScript = function (scriptEl: HTMLScriptElement) { + const transformScript = (scriptEl: HTMLScriptElement) => { const srcItem = scriptEl.attributes.getNamedItem("src"); if (srcItem) { ContentTools.logger?.debug( @@ -197,7 +212,7 @@ export class ContentTools { } }; - new MutationObserver(function (mutations: Array) { + new MutationObserver((mutations) => { ContentTools.logger?.debug("Called in mutation records"); for (const { addedNodes } of mutations) { addedNodes.forEach((addedNode) => { diff --git a/xwiki/remoteinlineeditor/src/vue/c-edit-xwikiremote.vue b/xwiki/remoteinlineeditor/src/vue/c-edit-xwikiremote.vue index e51f30cc5..1c4f58f53 100644 --- a/xwiki/remoteinlineeditor/src/vue/c-edit-xwikiremote.vue +++ b/xwiki/remoteinlineeditor/src/vue/c-edit-xwikiremote.vue @@ -74,7 +74,7 @@ export default { let path = "/" + cristal?.getCurrentPage() + "/view"; logger?.debug("pushing path in router", path); cristal?.getRouter().push({ path: path }); - cristal?.loadPage().then(function () {}); + cristal?.loadPage().then(() => { }); } }, false,