Skip to content

Commit 151a21e

Browse files
committed
lint
1 parent 273165b commit 151a21e

File tree

9 files changed

+95
-51
lines changed

9 files changed

+95
-51
lines changed

frontend/css/journal-table.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
}
4343

4444
.journal .head .container {
45-
padding: 1.5em 1.5em 0 1.5em;
45+
padding: 1.5em 1.5em 0;
4646
margin-bottom: 0.25em;
4747
}
4848

@@ -222,7 +222,7 @@
222222
}
223223

224224
.journal .head .container {
225-
padding: 1em 1em 0 1em;
225+
padding: 1em 1em 0;
226226
}
227227

228228
.journal .head .table-head {

frontend/src/api/validators.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,10 @@ const account_budget = object({
152152
});
153153
export type AccountBudget = ValidationT<typeof account_budget>;
154154

155-
const simple_counter_inventory = record(number)
156-
export type SimpleCounterInventory = ValidationT<typeof simple_counter_inventory>
155+
const simple_counter_inventory = record(number);
156+
export type SimpleCounterInventory = ValidationT<
157+
typeof simple_counter_inventory
158+
>;
157159

158160
const account_journal_entry = tuple(
159161
entryValidator,

frontend/src/entries/index.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ export class Posting {
2525
readonly meta: EntryMetadata,
2626
readonly account: string,
2727
readonly amount: string,
28-
readonly flag: string | null
29-
) { }
28+
readonly flag: string | null,
29+
) {}
3030

3131
/** Create a new empty Posting. */
3232
static empty(): Posting {
@@ -53,7 +53,8 @@ export class Posting {
5353

5454
static validator: Validator<Posting> = (json) =>
5555
Posting.raw_validator(json).map(
56-
({ meta, account, amount, flag }) => new Posting(meta, account, amount, flag),
56+
({ meta, account, amount, flag }) =>
57+
new Posting(meta, account, amount, flag),
5758
);
5859
}
5960

@@ -83,7 +84,7 @@ abstract class EntryBase<T extends string> {
8384
readonly entry_hash: string,
8485
readonly sortFlag: string,
8586
readonly sortNarration: string,
86-
) { }
87+
) {}
8788

8889
/** Clone. */
8990
clone(): this {
@@ -159,7 +160,14 @@ export class Balance extends EntryBase<"Balance"> {
159160

160161
/** Create a new empty Balance entry on the date. */
161162
static empty(date: string): Balance {
162-
return new Balance(new EntryMetadata(), date, "", "", RawAmount.empty(), null);
163+
return new Balance(
164+
new EntryMetadata(),
165+
date,
166+
"",
167+
"",
168+
RawAmount.empty(),
169+
null,
170+
);
163171
}
164172

165173
private static raw_validator = object({
@@ -169,7 +177,7 @@ export class Balance extends EntryBase<"Balance"> {
169177
entry_hash: string,
170178
account: string,
171179
amount: RawAmount.validator,
172-
diff_amount: optional(Amount.validator)
180+
diff_amount: optional(Amount.validator),
173181
});
174182

175183
static validator: Validator<Balance> = (json) =>
@@ -442,14 +450,14 @@ export class CustomValue {
442450
constructor(
443451
readonly dtype: string,
444452
readonly value: unknown,
445-
) { }
453+
) {}
446454

447455
toString(): string {
448456
if (this.dtype === "<class 'beancount.core.amount.Amount'>") {
449-
const a = this.value as Amount
450-
return `${a.number.toString()} ${a.currency}`
457+
const a = this.value as Amount;
458+
return `${a.number.toString()} ${a.currency}`;
451459
}
452-
return this.value as string
460+
return this.value as string;
453461
}
454462

455463
private static raw_validator = object({

frontend/src/format.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export function localeFormatter(
1616
locale: string | null,
1717
precision = 2,
1818
): (num: number) => string {
19-
let f;
19+
let f: (value: number) => string;
2020
if (locale == null) {
2121
f = format(`.${precision.toString()}f`);
2222
} else {

frontend/src/journal/JournalEntry.svelte

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<script lang="ts">
2+
/* eslint-disable @typescript-eslint/no-confusing-void-expression */
3+
24
import type { MouseEventHandler } from "svelte/elements";
3-
import { addFilter, escape_for_regex } from ".";
5+
46
import type { AccountJournalEntry } from "../api/validators";
57
import type { Document, EntryMetadata, Transaction } from "../entries";
68
import { type Entry } from "../entries";
@@ -10,6 +12,7 @@
1012
import { currency_name } from "../stores";
1113
import { ctx } from "../stores/format";
1214
import type { JournalShowEntry } from "../stores/journal";
15+
import { addFilter, escape_for_regex } from ".";
1316
1417
interface Props {
1518
index: number;
@@ -62,9 +65,9 @@
6265
return liClasses;
6366
});
6467
65-
const unitRegex = /([\d\.\-]+)\s+(\w+)/;
66-
const costRegex = /\{([\d\.\-]+)\s+(\w+),\s([\w\-]+)\}/;
67-
const priceRegex = /@\s([\d\.\-]+)\s+(\w+)/;
68+
const unitRegex = /([\d.-]+)\s+(\w+)/;
69+
const costRegex = /\{([\d.-]+)\s+(\w+),\s([\w-]+)\}/;
70+
const priceRegex = /@\s([\d.-]+)\s+(\w+)/;
6871
6972
type PostingAmounts = [
7073
[amount: string, currency: string],
@@ -73,9 +76,10 @@
7376
];
7477
7578
function splitPostingAmount(str: string): PostingAmounts {
76-
const amount = str.match(unitRegex)!;
77-
const cost = str.match(costRegex);
78-
const price = str.match(priceRegex);
79+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
80+
const amount = unitRegex.exec(str)!;
81+
const cost = costRegex.exec(str);
82+
const price = priceRegex.exec(str);
7983
8084
return [
8185
[amount[1], amount[2]],
@@ -93,13 +97,15 @@
9397
9498
type ClickHandler = MouseEventHandler<HTMLElement>;
9599
96-
const clickTagLink: ClickHandler = ({ currentTarget }) =>
100+
const clickTagLink: ClickHandler = ({ currentTarget }) => {
97101
addFilter(currentTarget.innerText);
102+
};
98103
99104
// Note: any special characters in the payee string are escaped so the
100105
// filter matches against the payee literally.
101-
const clickPayee: ClickHandler = ({ currentTarget }) =>
106+
const clickPayee: ClickHandler = ({ currentTarget }) => {
102107
addFilter(`payee:"^${escape_for_regex(currentTarget.innerText)}$"`);
108+
};
103109
104110
const clickMetaKey: ClickHandler = ({ currentTarget }) => {
105111
const expr = `${currentTarget.innerText}""`;
@@ -127,6 +133,7 @@
127133
</script>
128134

129135
{#snippet amount(amount: Amount | RawAmount, cls: string)}
136+
<!-- eslint-disable-next-line @typescript-eslint/strict-boolean-expressions -->
130137
{#if !amount.number}
131138
<span class={cls}></span>
132139
{:else}
@@ -283,7 +290,8 @@
283290
{@render metadataIndicators(e.meta)}
284291
{#if e.t === "Transaction"}
285292
{#each e.postings as posting, index (index)}
286-
<span class={posting.flag ? flagToTypes(posting.flag) : null}></span>
293+
<span class={posting.flag != null ? flagToTypes(posting.flag) : null}
294+
></span>
287295
{@render metadataIndicators(posting.meta)}
288296
{/each}
289297
{/if}
@@ -302,23 +310,29 @@
302310
{#if showChangeAndBalance}
303311
{#if e.t === "Transaction"}
304312
<span class="change num">
305-
{#each Object.entries(change ?? {}) as [currency, number]}
306-
{$ctx.amount(number, currency)}<br />
307-
{/each}
313+
{#if change}
314+
{#each Object.entries(change) as [currency, number], index (index)}
315+
<!-- eslint-disable-next-line @typescript-eslint/no-unsafe-argument -->
316+
{$ctx.amount(number, currency)}<br />
317+
{/each}
318+
{/if}
308319
</span>
309320
{/if}
310321
<span class="num">
311-
{#each Object.entries(balance ?? {}) as [currency, number]}
312-
{$ctx.amount(number, currency)}<br />
313-
{/each}
322+
{#if balance}
323+
{#each Object.entries(balance) as [currency, number], index (index)}
324+
<!-- eslint-disable-next-line @typescript-eslint/no-unsafe-argument -->
325+
{$ctx.amount(number, currency)}<br />
326+
{/each}
327+
{/if}
314328
</span>
315329
{/if}
316330
</p>
317331
{@render metadata(e.meta, e.entry_hash)}
318332
{#if showPostings && e.t === "Transaction" && e.postings.length > 0}
319333
<ul class="postings">
320334
{#each e.postings as posting, index (index)}
321-
<li class={posting.flag ? flagToTypes(posting.flag) : null}>
335+
<li class={posting.flag != null ? flagToTypes(posting.flag) : null}>
322336
<p>
323337
<span class="datecell"></span>
324338
<span class="flag">{posting.flag ?? ""}</span>

frontend/src/journal/JournalTable.svelte

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<script lang="ts">
22
import { createVirtualizer } from "@tanstack/svelte-virtual";
3-
import { onDestroy, onMount, tick, type Snippet } from "svelte";
3+
import { onDestroy, onMount, type Snippet, tick } from "svelte";
44
import { derived, writable } from "svelte/store";
55
6+
import type { AccountJournalEntry } from "../api/validators";
67
import type { Entry } from "../entries";
78
import { _ } from "../i18n";
9+
import Header from "../sidebar/Header.svelte";
810
import { Sorter, StringColumn } from "../sort";
11+
import { hideHeader } from "../stores";
912
import {
1013
journalShow as journalShowStore,
1114
type JournalShowEntry,
@@ -14,9 +17,6 @@
1417
} from "../stores/journal";
1518
import JournalEntry from "./JournalEntry.svelte";
1619
import JournalFilters from "./JournalFilters.svelte";
17-
import type { AccountJournalEntry } from "../api/validators";
18-
import Header from "../sidebar/Header.svelte";
19-
import { hideHeader } from "../stores";
2020
2121
type E = Entry | AccountJournalEntry;
2222
interface Props {
@@ -114,8 +114,12 @@
114114
);
115115
116116
// Update the manual store when the prop update.
117-
$effect(() => entries.set(entriesProp));
118-
onDestroy(() => unsub());
117+
$effect(() => {
118+
entries.set(entriesProp);
119+
});
120+
onDestroy(() => {
121+
unsub();
122+
});
119123
120124
function headerClick(e: MouseEvent & { currentTarget: HTMLSpanElement }) {
121125
const name = e.currentTarget.getAttribute("data-sort-name");
@@ -144,8 +148,9 @@
144148
count: sortedEntries.length + 1,
145149
getItemKey: depend(
146150
sortedEntries,
147-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
151+
148152
(sortedEntries) => (i) =>
153+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
149154
i === 0 ? "head" : entry(sortedEntries[i - 1]!).entry_hash,
150155
),
151156
getScrollElement: depend(vlistOuter, (ol) => () => ol ?? null),
@@ -156,7 +161,9 @@
156161
let items = $derived($virtualizer.getVirtualItems());
157162
158163
$effect(() => {
159-
if (head) $virtualizer.measureElement(head);
164+
if (head) {
165+
$virtualizer.measureElement(head);
166+
}
160167
if (vlistItems.length) {
161168
vlistItems.forEach((li) => {
162169
$virtualizer.measureElement(li);
@@ -171,10 +178,14 @@
171178
// Wait for update tick so keyboard shortcut not duplicated.
172179
if (mediaQuery.matches) {
173180
$hideHeader = true;
174-
tick().then(() => mobileHeader = true);
181+
void tick().then(() => {
182+
mobileHeader = true;
183+
});
175184
} else {
176185
mobileHeader = false;
177-
tick().then(() => $hideHeader = false);
186+
void tick().then(() => {
187+
$hideHeader = false;
188+
});
178189
}
179190
};
180191

frontend/src/reports/accounts/AccountReport.svelte

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
<script lang="ts">
2+
/* eslint-disable @typescript-eslint/no-confusing-void-expression */
3+
24
import { parseChartData } from "../../charts";
35
import ChartSwitcher from "../../charts/ChartSwitcher.svelte";
46
import { chartContext } from "../../charts/context";
57
import { urlForAccount } from "../../helpers";
68
import { _ } from "../../i18n";
9+
import JournalTable from "../../journal/JournalTable.svelte";
710
import { is_non_empty } from "../../lib/array";
811
import { intervalLabel } from "../../lib/interval";
912
import { interval } from "../../stores";
1013
import IntervalTreeTable from "../../tree-table/IntervalTreeTable.svelte";
1114
import type { AccountReportProps } from ".";
12-
import JournalTable from "../../journal/JournalTable.svelte";
1315
1416
let {
1517
account,

frontend/src/sort/index.ts

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ export class Sorter<T = unknown> {
4545
constructor(
4646
readonly column: SortColumn<T>,
4747
readonly order: SortOrder,
48-
) { }
48+
) {}
4949

5050
/** Get a new sorter by switching to a possibly different column. */
5151
switchColumn(column: SortColumn<T>): Sorter<T> {
@@ -91,7 +91,7 @@ function sort_internal<T, U>(
9191

9292
/** A SortColumn that does no sorting. */
9393
export class UnsortedColumn<T> implements SortColumn<T> {
94-
constructor(readonly name: string) { }
94+
constructor(readonly name: string) {}
9595

9696
sort(data: readonly T[]): readonly T[] {
9797
return data;
@@ -104,8 +104,12 @@ export class NumberColumn<T> implements SortColumn<T> {
104104

105105
constructor(
106106
readonly name: string,
107-
private readonly value: (row: Readonly<T>, index: number, array: readonly T[]) => number,
108-
) { }
107+
private readonly value: (
108+
row: Readonly<T>,
109+
index: number,
110+
array: readonly T[],
111+
) => number,
112+
) {}
109113

110114
sort(data: readonly T[], direction: SortDirection): readonly T[] {
111115
return sort_internal(data, this.value, this.compare, direction);
@@ -126,8 +130,12 @@ export class StringColumn<T> implements SortColumn<T> {
126130

127131
constructor(
128132
readonly name: string,
129-
private readonly value: (row: Readonly<T>, index: number, array: readonly T[]) => string,
130-
) { }
133+
private readonly value: (
134+
row: Readonly<T>,
135+
index: number,
136+
array: readonly T[],
137+
) => string,
138+
) {}
131139

132140
sort(data: readonly T[], direction: 1 | -1): readonly T[] {
133141
return sort_internal(data, this.value, this.compare, direction);

src/fava/json_api.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from typing import TYPE_CHECKING
2222

2323
from flask import Blueprint
24-
from flask import get_template_attribute
2524
from flask import jsonify
2625
from flask import request
2726
from flask_babel import gettext
@@ -791,5 +790,5 @@ def get_account_report() -> AccountReportJournal | AccountReportTree:
791790
)
792791
return AccountReportJournal(
793792
charts,
794-
journal=[[serialise(e[0]), e[1], e[2]] for e in journal]
793+
journal=[[serialise(e[0]), e[1], e[2]] for e in journal], # type: ignore[misc]
795794
)

0 commit comments

Comments
 (0)