Skip to content

Commit f61675c

Browse files
committed
lint
1 parent 86a19f5 commit f61675c

File tree

10 files changed

+107
-84
lines changed

10 files changed

+107
-84
lines changed

frontend/src/charts/SelectCombobox.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@
3636
/** Whether the list of options in the Combobox popup is hidden. */
3737
let hidden = $state(true);
3838
/** The index of the option that is currently focused */
39+
// Use the initial index in options (options does not change).
40+
// svelte-ignore state_referenced_locally
3941
let index = $state(options.indexOf(value));
4042
/** The popup list element. */
4143
let ul: HTMLUListElement | undefined = $state();

frontend/src/charts/Sunburst.svelte

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@
3434
3535
$effect.pre(() => {
3636
// if-expression to run on each change of chart
37-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
38-
data;
37+
void data;
3938
untrack(() => {
4039
current = null;
4140
});

frontend/src/codemirror/setup.ts

Lines changed: 79 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import {
2222
} from "@codemirror/language";
2323
import { lintGutter, lintKeymap } from "@codemirror/lint";
2424
import { highlightSelectionMatches, searchKeymap } from "@codemirror/search";
25-
import type { Extension } from "@codemirror/state";
2625
import { EditorState } from "@codemirror/state";
2726
import type { KeyBinding } from "@codemirror/view";
2827
import {
@@ -81,22 +80,14 @@ interface EditorAndAttachment {
8180
renderEditor: Attachment<HTMLDivElement | HTMLPreElement>;
8281
}
8382

84-
function setup(
85-
value: string | undefined,
86-
extensions: Extension[],
87-
): EditorAndAttachment {
88-
const view = new EditorView({
89-
state: EditorState.create(
90-
value !== undefined ? { doc: value, extensions } : { extensions },
91-
),
92-
});
83+
function editor_attachment(editor: EditorView): EditorAndAttachment {
9384
return {
94-
editor: view,
85+
editor,
9586
renderEditor: (el) => {
96-
el.appendChild(view.dom);
87+
el.appendChild(editor.dom);
9788

9889
return () => {
99-
el.removeChild(view.dom);
90+
el.removeChild(editor.dom);
10091
};
10192
},
10293
};
@@ -105,12 +96,16 @@ function setup(
10596
/**
10697
* A basic readonly editor for an asynchronously loaded document.
10798
*/
108-
export function initDocumentPreviewEditor(value: string): EditorAndAttachment {
109-
return setup(value, [
110-
baseExtensions,
111-
EditorState.readOnly.of(true),
112-
placeholder("Loading..."),
113-
]);
99+
export function initDocumentPreviewEditor(): EditorAndAttachment {
100+
return editor_attachment(
101+
new EditorView({
102+
extensions: [
103+
baseExtensions,
104+
EditorState.readOnly.of(true),
105+
placeholder("Loading..."),
106+
],
107+
}),
108+
);
114109
}
115110

116111
/**
@@ -121,11 +116,14 @@ export class BeancountTextarea extends HTMLTextAreaElement {
121116
super();
122117
getBeancountLanguageSupport()
123118
.then((beancount) => {
124-
const { editor } = setup(this.value, [
125-
beancount,
126-
syntaxHighlighting(defaultHighlightStyle),
127-
EditorView.editable.of(false),
128-
]);
119+
const editor = new EditorView({
120+
doc: this.value,
121+
extensions: [
122+
beancount,
123+
syntaxHighlighting(defaultHighlightStyle),
124+
EditorView.editable.of(false),
125+
],
126+
});
129127
this.parentNode?.insertBefore(editor.dom, this);
130128
this.style.display = "none";
131129
})
@@ -140,64 +138,80 @@ export function initBeancountEditor(
140138
value: string,
141139
onDocChanges: (s: EditorState) => void,
142140
commands: KeyBinding[],
143-
beancount: LanguageSupport,
141+
beancount: () => LanguageSupport,
144142
): EditorAndAttachment {
145143
const $indent = store_get(indent);
146144
const $currency_column = store_get(currency_column);
147-
return setup(value, [
148-
beancount,
149-
indentUnit.of(" ".repeat($indent)),
150-
...($currency_column ? [rulerPlugin($currency_column - 1)] : []),
151-
keymap.of(commands),
152-
EditorView.updateListener.of((update) => {
153-
if (update.docChanged) {
154-
onDocChanges(update.state);
155-
}
145+
return editor_attachment(
146+
new EditorView({
147+
doc: value,
148+
extensions: [
149+
beancount(),
150+
indentUnit.of(" ".repeat($indent)),
151+
...($currency_column ? [rulerPlugin($currency_column - 1)] : []),
152+
keymap.of(commands),
153+
EditorView.updateListener.of((update) => {
154+
if (update.docChanged) {
155+
onDocChanges(update.state);
156+
}
157+
}),
158+
baseExtensions,
159+
syntaxHighlighting(beancountEditorHighlight),
160+
],
156161
}),
157-
baseExtensions,
158-
syntaxHighlighting(beancountEditorHighlight),
159-
]);
162+
);
160163
}
161164

162165
/**
163166
* A basic readonly BQL editor that only does syntax highlighting.
164167
*/
165168
export function initReadonlyQueryEditor(value: string): EditorAndAttachment {
166-
return setup(value, [
167-
bql,
168-
syntaxHighlighting(beancountQueryHighlight),
169-
EditorView.editable.of(false),
170-
]);
169+
return editor_attachment(
170+
new EditorView({
171+
doc: value,
172+
extensions: [
173+
bql,
174+
syntaxHighlighting(beancountQueryHighlight),
175+
EditorView.editable.of(false),
176+
],
177+
}),
178+
);
171179
}
172180

173181
/**
174182
* The main BQL editor.
175183
*/
176184
export function initQueryEditor(
177-
value: string | undefined,
185+
value: string,
178186
onDocChanges: (s: EditorState) => void,
179-
_placeholder: string,
180-
submit: () => void,
187+
placeholder_value: string,
188+
get_submit: () => () => void,
181189
): EditorAndAttachment {
182-
return setup(value, [
183-
bql,
184-
EditorView.updateListener.of((update) => {
185-
if (update.docChanged) {
186-
onDocChanges(update.state);
187-
}
190+
return editor_attachment(
191+
new EditorView({
192+
doc: value,
193+
extensions: [
194+
bql,
195+
EditorView.updateListener.of((update) => {
196+
if (update.docChanged) {
197+
onDocChanges(update.state);
198+
}
199+
}),
200+
keymap.of([
201+
{
202+
key: "Control-Enter",
203+
mac: "Meta-Enter",
204+
run: () => {
205+
const submit = get_submit();
206+
submit();
207+
return true;
208+
},
209+
},
210+
]),
211+
placeholder(placeholder_value),
212+
baseExtensions,
213+
syntaxHighlighting(beancountQueryHighlight),
214+
],
188215
}),
189-
keymap.of([
190-
{
191-
key: "Control-Enter",
192-
mac: "Meta-Enter",
193-
run: () => {
194-
submit();
195-
return true;
196-
},
197-
},
198-
]),
199-
placeholder(_placeholder),
200-
baseExtensions,
201-
syntaxHighlighting(beancountQueryHighlight),
202-
]);
216+
);
203217
}

frontend/src/editor/DocumentPreviewEditor.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
let { url }: Props = $props();
1717
18-
const { editor, renderEditor } = initDocumentPreviewEditor("");
18+
const { editor, renderEditor } = initDocumentPreviewEditor();
1919
2020
const set_editor_content = (value: string) => {
2121
if (value !== editor.state.sliceDoc()) {

frontend/src/editor/SliceEditor.svelte

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
sha256sum = $bindable(),
2525
}: Props = $props();
2626
27-
let currentSlice = $state(slice);
28-
let changed = $derived(currentSlice !== slice);
27+
// Keep the initital slice value to check for changes.
28+
// svelte-ignore state_referenced_locally
29+
const initial_slice = slice;
30+
31+
let currentSlice = $state(initial_slice);
32+
let changed = $derived(currentSlice !== initial_slice);
2933
3034
let saving = $state(false);
3135
let deleting = $state(false);
@@ -67,7 +71,7 @@
6771
}
6872
6973
const { renderEditor } = initBeancountEditor(
70-
slice,
74+
initial_slice,
7175
(state) => {
7276
currentSlice = state.sliceDoc();
7377
},
@@ -83,7 +87,7 @@
8387
},
8488
},
8589
],
86-
beancount_language_support,
90+
() => beancount_language_support,
8791
);
8892
</script>
8993

frontend/src/reports/editor/Editor.svelte

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,12 @@
7272
},
7373
},
7474
],
75-
beancount_language_support,
75+
() => beancount_language_support,
7676
);
7777
7878
$effect(() => {
7979
// update editor contents if source changes
80-
// eslint-disable-next-line @typescript-eslint/no-unused-expressions
81-
source;
80+
void source;
8281
untrack(() => {
8382
editor.dispatch(replaceContents(editor.state, source.source));
8483
sha256sum = source.sha256sum;

frontend/src/reports/import/Import.svelte

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@
2323
2424
let { files }: ImportReportProps = $props();
2525
26-
/** Whether the `<details>` for the "other files" is open. */
27-
let show_other_files = $state.raw(
28-
// initially show the other files if no importable files are present
29-
files.every((file) => !file.identified_by_importers),
26+
// initially show the other files if no importable files are present
27+
// svelte-ignore state_referenced_locally
28+
const show_other_files_initially = files.every(
29+
(file) => !file.identified_by_importers,
3030
);
3131
32+
/** Whether the `<details>` for the "other files" is open. */
33+
let show_other_files = $state.raw(show_other_files_initially);
34+
3235
/** The array of entries to show the modal for. */
3336
let entries: Entry[] = $state([]);
3437

frontend/src/reports/query/QueryEditor.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
value = state.sliceDoc();
1818
},
1919
_("...enter a BQL query. 'help' to list available commands."),
20-
submit,
20+
() => submit,
2121
);
2222
2323
$effect(() => {

frontend/src/reports/query/ReadonlyQueryEditor.svelte

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
99
let { value, error = false }: Props = $props();
1010
11+
// This component is not used with updating values
12+
// svelte-ignore state_referenced_locally
1113
const { renderEditor } = initReadonlyQueryEditor(value);
1214
</script>
1315

frontend/src/tree-table/IntervalTreeTableNode.svelte

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,11 @@
1111
import { getTreeTableNotShownContext } from "./helpers.ts";
1212
import IntervalTreeTableNode from "./IntervalTreeTableNode.svelte";
1313
14+
type Nodes = NonEmptyArray<AccountTreeNode>;
15+
1416
interface Props {
1517
/** The account nodes to show. */
16-
nodes: NonEmptyArray<AccountTreeNode>;
18+
nodes: Nodes;
1719
/** The budgets (per account a list per date range). */
1820
budgets: Record<string, AccountBudget[]>;
1921
}
@@ -70,9 +72,7 @@
7072
{#each children as child, index (child.account)}
7173
{#if !$not_shown.has(child.account)}
7274
<IntervalTreeTableNode
73-
nodes={nodes.map(
74-
(n) => n.children[index],
75-
) as unknown as NonEmptyArray}
75+
nodes={nodes.map((n) => n.children[index]) as unknown as Nodes}
7676
{budgets}
7777
/>
7878
{/if}

0 commit comments

Comments
 (0)