From 546f78f2c51e6765ec28ab70ee5bbf80a1ef6f6b Mon Sep 17 00:00:00 2001 From: Lyss Date: Fri, 15 Nov 2024 17:42:45 +0100 Subject: [PATCH] Make lint pass --- eslint.config.js | 16 +++++---- package.json | 1 + pnpm-lock.yaml | 3 ++ src/lib/actions/focusTrap.ts | 3 +- src/lib/actions/index.ts | 2 +- src/lib/actions/inputs.ts | 2 +- src/lib/actions/keyboard.ts | 4 +-- src/lib/actions/resizable.ts | 6 ++-- src/lib/actions/scroll.ts | 2 +- src/lib/actions/shortcut.ts | 2 +- src/lib/components/Button.svelte | 2 +- src/lib/components/OptimizedDiv.svelte | 2 +- src/lib/components/PathGenerator.svelte | 2 +- src/lib/components/menu/ContextMenu.svelte | 4 ++- .../components/modal/ModalComponent.svelte | 2 +- src/lib/components/modal/modal.svelte.ts | 34 +++++++++---------- src/lib/components/tree/Tree.svelte | 6 ++-- src/lib/datastructure.ts | 1 + src/lib/utils/eventModifier.test.ts | 4 +-- src/lib/utils/html.svelte.ts | 5 +-- src/lib/utils/layout.ts | 4 +-- src/lib/utils/string.ts | 3 +- src/lib/utils/xml.ts | 7 ++-- src/lib/utils/xsd.ts | 6 ++-- src/routes/checkbox/+page.svelte | 1 - src/routes/classifier/+page.svelte | 1 - src/routes/layout/+page.svelte | 2 +- src/routes/resizable/+page.svelte | 10 +----- src/routes/shortcut/+page.svelte | 8 ++--- src/routes/test/flip/+page.svelte | 2 +- 30 files changed, 76 insertions(+), 71 deletions(-) diff --git a/eslint.config.js b/eslint.config.js index 7ee2e38..d4356c8 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -1,11 +1,11 @@ +import prettier from 'eslint-config-prettier'; import js from '@eslint/js'; -import ts from 'typescript-eslint'; import svelte from 'eslint-plugin-svelte'; -import prettier from 'eslint-config-prettier'; import globals from 'globals'; +import ts from 'typescript-eslint'; +import svelteParser from 'svelte-eslint-parser'; -/** @type {import('eslint').Linter.FlatConfig[]} */ -export default [ +export default ts.config( js.configs.recommended, ...ts.configs.recommended, ...svelte.configs['flat/recommended'], @@ -22,12 +22,16 @@ export default [ { files: ['**/*.svelte'], languageOptions: { + parser: svelteParser, parserOptions: { - parser: ts.parser + parser: ts.parser, + svelteFeatures: { + experimentalGenerics: true + } } } }, { ignores: ['build/', '.svelte-kit/', 'dist/', 'docs/', 'selenite-commons-rs'] } -]; +); diff --git a/package.json b/package.json index d60f40b..971077d 100644 --- a/package.json +++ b/package.json @@ -80,6 +80,7 @@ "prettier-plugin-svelte": "^3.2.8", "publint": "^0.2.12", "svelte-check": "^4.0.8", + "svelte-eslint-parser": "^0.43.0", "svelte-persisted-store": "0.12.0", "tailwindcss": "^3.4.15", "tslib": "^2.8.1", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 194b2ac..bcb9806 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -144,6 +144,9 @@ importers: svelte-check: specifier: ^4.0.8 version: 4.0.8(svelte@5.2.0)(typescript@5.6.3) + svelte-eslint-parser: + specifier: ^0.43.0 + version: 0.43.0(svelte@5.2.0) svelte-persisted-store: specifier: 0.12.0 version: 0.12.0(svelte@5.2.0) diff --git a/src/lib/actions/focusTrap.ts b/src/lib/actions/focusTrap.ts index 6cd11b7..5af178a 100644 --- a/src/lib/actions/focusTrap.ts +++ b/src/lib/actions/focusTrap.ts @@ -90,7 +90,8 @@ export function focusTrap(node: HTMLElement, enabled: boolean) { return { update(newArgs: boolean) { enabled = newArgs; - newArgs ? onScanElements(false) : onCleanUp(); + if (newArgs) onScanElements(false); + else onCleanUp(); }, destroy() { onCleanUp(); diff --git a/src/lib/actions/index.ts b/src/lib/actions/index.ts index 5dd0d74..b420bd8 100644 --- a/src/lib/actions/index.ts +++ b/src/lib/actions/index.ts @@ -39,7 +39,7 @@ export const handleFocusLeave: Action void } handleFocusLeaveRefCount++; handleFocusLeaveCallbacks.push(callback); - function handleFocusIn(e: Event) {} + function handleFocusIn() {} function handleFocusOut() { requestAnimationFrame(() => { diff --git a/src/lib/actions/inputs.ts b/src/lib/actions/inputs.ts index 4cb1b3c..d836983 100644 --- a/src/lib/actions/inputs.ts +++ b/src/lib/actions/inputs.ts @@ -1,4 +1,4 @@ -import type { Action, ActionReturn } from 'svelte/action'; +import type { Action } from 'svelte/action'; import baseAutosize from 'autosize'; import { tick } from 'svelte'; diff --git a/src/lib/actions/keyboard.ts b/src/lib/actions/keyboard.ts index 81b7afb..50a8dc3 100644 --- a/src/lib/actions/keyboard.ts +++ b/src/lib/actions/keyboard.ts @@ -23,11 +23,11 @@ export const keyboardNavigation: Action = (node) => { candidate.focus(); } } - function handleFocusIn(e: Event) { + function handleFocusIn() { console.debug('Add keydown listener'); node.addEventListener('keydown', handleKeydown); } - function handleFocusOut(e: Event) { + function handleFocusOut() { console.debug('Remove keydown listener'); node.removeEventListener('keydown', handleKeydown); } diff --git a/src/lib/actions/resizable.ts b/src/lib/actions/resizable.ts index 6ea8f04..b4709d5 100644 --- a/src/lib/actions/resizable.ts +++ b/src/lib/actions/resizable.ts @@ -1,6 +1,6 @@ import { Vector2D } from '$lib/datastructure'; import { PointerDownWatcher, posFromClient } from '$lib/utils'; -import type { Action, ActionReturn } from 'svelte/action'; +import type { ActionReturn } from 'svelte/action'; const resizeHandleMap = new Map< HTMLElement, @@ -70,12 +70,12 @@ export function resizable( node: N, params: ResizeHandleParams = {} ): ActionReturn> { - function onpointerenter(e: PointerEvent) { + function onpointerenter() { document.addEventListener('pointermove', onpointermove, { passive: true }); removePointermoveCleanup?.(); } let removePointermoveCleanup: (() => void) | undefined; - function onpointerleave(e: PointerEvent) { + function onpointerleave() { // Wait for pointer up to stop resizing removePointermoveCleanup = PointerDownWatcher.instance.subscribe((down) => { if (!down) { diff --git a/src/lib/actions/scroll.ts b/src/lib/actions/scroll.ts index 23b85c4..c72fa77 100644 --- a/src/lib/actions/scroll.ts +++ b/src/lib/actions/scroll.ts @@ -66,7 +66,7 @@ export const horizontalScroll: Action { + node.addEventListener('scroll', () => { if (!isActionScroll) { scroll.set(node.scrollLeft); } diff --git a/src/lib/actions/shortcut.ts b/src/lib/actions/shortcut.ts index 186225b..c3a8fb6 100644 --- a/src/lib/actions/shortcut.ts +++ b/src/lib/actions/shortcut.ts @@ -6,7 +6,7 @@ */ import { isArray } from 'lodash-es'; -import type { Action, ActionReturn } from 'svelte/action'; +import type { ActionReturn } from 'svelte/action'; /** * Basic definition of a keyboard shortcut based on key and modifier keys. diff --git a/src/lib/components/Button.svelte b/src/lib/components/Button.svelte index 654ea2d..603fb81 100644 --- a/src/lib/components/Button.svelte +++ b/src/lib/components/Button.svelte @@ -1,7 +1,7 @@ diff --git a/src/lib/components/OptimizedDiv.svelte b/src/lib/components/OptimizedDiv.svelte index 6f05b67..175c935 100644 --- a/src/lib/components/OptimizedDiv.svelte +++ b/src/lib/components/OptimizedDiv.svelte @@ -1,7 +1,7 @@ diff --git a/src/lib/components/PathGenerator.svelte b/src/lib/components/PathGenerator.svelte index cc6c059..ff98841 100644 --- a/src/lib/components/PathGenerator.svelte +++ b/src/lib/components/PathGenerator.svelte @@ -149,7 +149,7 @@ bind:value={createdPart} bind:this={creationInput} class="input input-bordered" - oninput={(e) => { + oninput={() => { focusedOption = ''; }} placeholder={(focusedOptionIndex === -1 diff --git a/src/lib/components/menu/ContextMenu.svelte b/src/lib/components/menu/ContextMenu.svelte index da8ff77..63f72ed 100644 --- a/src/lib/components/menu/ContextMenu.svelte +++ b/src/lib/components/menu/ContextMenu.svelte @@ -19,6 +19,7 @@ // Update position when menu is visible $effect(() => { + /* eslint-disable @typescript-eslint/no-unused-expressions */ if (!menu.visible) return; menu.pos.x; menu.pos.y; @@ -33,6 +34,7 @@ import { shortcut } from '$lib/actions'; let searchInput = $state(); let menuCmpnt = $state(); + $effect(() => { menu.filteredItems; if (menu.expanded) { @@ -99,7 +101,7 @@ use:shortcut={{ ignoreElements: [], key: 'Escape', - action(n, e) { + action() { menu.visible = false; } }} diff --git a/src/lib/components/modal/ModalComponent.svelte b/src/lib/components/modal/ModalComponent.svelte index 256fde1..cc2ea61 100644 --- a/src/lib/components/modal/ModalComponent.svelte +++ b/src/lib/components/modal/ModalComponent.svelte @@ -72,7 +72,7 @@ {/if}
- +
{/if} diff --git a/src/lib/components/modal/modal.svelte.ts b/src/lib/components/modal/modal.svelte.ts index d89ba8a..b7c7d01 100644 --- a/src/lib/components/modal/modal.svelte.ts +++ b/src/lib/components/modal/modal.svelte.ts @@ -21,32 +21,32 @@ export type BaseModalSettings = { buttons?: ModalButtonSettings[]; response?: (r: unknown) => void; }; - -export type ComponentModalSettings = {}> = { - component: Component unknown }>; - props: Props; +type Props = Record; +export type ComponentModalSettings

= { + component: Component

unknown }>; + props: P; } & BaseModalSettings; -export type SnippetModalSettings = {}> = { - snippet: Snippet<[Props]>; - props: Props; +export type SnippetModalSettings

= { + snippet: Snippet<[P]>; + props: P; } & BaseModalSettings; export type PromptModalSettings = { prompt: string; initial?: string } & BaseModalSettings; -export type ModalSettings = {}> = +export type ModalSettings

= | PromptModalSettings - | ComponentModalSettings - | SnippetModalSettings; + | ComponentModalSettings

+ | SnippetModalSettings

; -export function isComponentModalSettings>( - modal: ModalSettings -): modal is ComponentModalSettings { +export function isComponentModalSettings

( + modal: ModalSettings

+): modal is ComponentModalSettings

{ return 'component' in modal; } -export function isSnippetModalSettings>( - modal: ModalSettings -): modal is SnippetModalSettings { +export function isSnippetModalSettings

( + modal: ModalSettings

+): modal is SnippetModalSettings

{ return 'snippet' in modal; } @@ -150,7 +150,7 @@ export class Modal { private constructor() {} - show>(params: ModalSettings) { + show

(params: ModalSettings

) { console.debug('Show modal', params); if ('prompt' in params) { params.buttons = params.buttons || ['cancel', 'promptConfirm']; diff --git a/src/lib/components/tree/Tree.svelte b/src/lib/components/tree/Tree.svelte index 38ef033..8a761cc 100644 --- a/src/lib/components/tree/Tree.svelte +++ b/src/lib/components/tree/Tree.svelte @@ -1,7 +1,7 @@ -

Checkbox action

Hold to trigger multiple checkboxes.

diff --git a/src/routes/classifier/+page.svelte b/src/routes/classifier/+page.svelte index e870d37..93f213f 100644 --- a/src/routes/classifier/+page.svelte +++ b/src/routes/classifier/+page.svelte @@ -1,5 +1,4 @@