Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
tansongchen committed Jun 27, 2024
1 parent b6db7a2 commit 58d5ad3
Show file tree
Hide file tree
Showing 63 changed files with 214 additions and 272 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
],
"tsdoc/syntax": "warn",
"no-undef": "error",
"no-undefined": "error"
"no-undefined": "off"
}
},
"hintConfig": {
Expand Down
1 change: 0 additions & 1 deletion scripts/analyze.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { readFileSync } from "fs";
import { load } from "js-yaml";
import { examples } from "~/lib";

const estimate = (n: number, k: number) => (n * n) / (2 * k);

Expand Down
3 changes: 1 addition & 2 deletions scripts/recursive.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { readFileSync, writeFileSync } from "fs";
import type { Compound, PrimitiveCharacter } from "~/lib";
import { Character } from "~/lib";

const repertoire = JSON.parse(
readFileSync("public/cache/repertoire.json", "utf-8"),
Expand All @@ -16,7 +15,7 @@ for (const character of repertoire) {
| undefined;
if (!compound) continue;
const children = compound.operandList;
for (const [index, child] of children.entries()) {
for (const child of children.values()) {
descendants.set(child, (descendants.get(child) ?? []).concat(name));
}
}
Expand Down
4 changes: 1 addition & 3 deletions spec/component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ import { describe, expect, it } from "vitest";
import {
classifier,
createConfig,
defaultConfig,
generateSchemes,
getComponentScheme,
listToObject,
makeIntervalSum,
recursiveRenderComponent,
renderRootList,
} from "~/lib";
import type { DerivedComponent, PrimitiveRepertoire } from "~/lib";
import type { DerivedComponent } from "~/lib";
import {
primitiveRepertoire,
repertoire,
Expand Down
2 changes: 1 addition & 1 deletion spec/degenerator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ const hasroot = (a: RenderedGlyph, indices: number[], root: RenderedGlyph) => {
};

describe("degenerate cross tests", () => {
const {,,,,,,,, , ,,,,,,} =
const {,,,,,,,,,,,,,,} =
renderedGlyphs as any;
const han = renderedGlyphs["\ue104"]!;
it("says 天 has 大", () => {
Expand Down
2 changes: 0 additions & 2 deletions spec/element.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ import {
renderName,
renderList,
parseList,
findElement,
CodableObject,
} from "../src/lib/element";

describe("element", () => {
Expand Down
4 changes: 2 additions & 2 deletions spec/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
PrimitiveCharacter,
Repertoire,
} from "~/lib";
import { listToObject, determine, computeComponent } from "~/lib";
import { determine, computeComponent } from "~/lib";

export const primitiveRepertoire = Object.fromEntries(
(rawrepertoire as PrimitiveCharacter[]).map((x) => [
Expand All @@ -17,7 +17,7 @@ export const primitiveRepertoire = Object.fromEntries(
export const repertoire = determine(primitiveRepertoire);
export const computedComponents = Object.fromEntries(
Object.entries(repertoire)
.filter(([k, v]) => v.glyph?.type === "basic_component")
.filter(([_, v]) => v.glyph?.type === "basic_component")
.map(([k, v]) => {
const glyph = (v.glyph as BasicComponent).strokes;
return [k, computeComponent(k, glyph)];
Expand Down
3 changes: 1 addition & 2 deletions spec/selector.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import { describe, expect, it } from "vitest";
import type { Environment, Scheme } from "~/lib";
import { length, bias, order, crossing, attaching, analysis } from "~/lib";
import { length, bias, order, crossing, attaching } from "~/lib";
import { select } from "~/lib";
import { computedComponents, focusAnalysis, repertoire } from "./mock";
import { defaultConfig } from "~/lib";
import { Config } from "~/lib";

const analysisConfig = focusAnalysis(defaultConfig, repertoire);
const {} = computedComponents as any;
Expand Down
4 changes: 2 additions & 2 deletions spec/topology.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect, describe, it } from "vitest";
import type { StrokeRelation, CubicCurve, LinearCurve } from "~/lib";
import { findTopology, curveRelation, renderSVGGlyph } from "~/lib";
import { area, render } from "~/lib";
import { findTopology, curveRelation } from "~/lib";
import { area } from "~/lib";
import type { Draw, Point } from "~/lib";
import { computedGlyphs2 as computedGlyphs } from "./mock";
import { getIntervalPosition, makeCurve } from "~/lib";
Expand Down
8 changes: 1 addition & 7 deletions src/atoms/analysis.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
import type {
Analysis,
Degenerator,
Selector,
SieveName,
Feature,
} from "~/lib";
import type { Analysis, Degenerator, Selector, Feature } from "~/lib";
import { focusAtom } from "jotai-optics";
import { analysisAtom } from "./config";
import { mergeClassifier } from "~/lib";
Expand Down
10 changes: 7 additions & 3 deletions src/atoms/assets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { atomWithStorage } from "jotai/utils";
import type { Dictionary, Distribution, Equivalence, Frequency } from ".";
import type {
CustomElementMap,
Dictionary,
Distribution,
Equivalence,
Frequency,
} from "~/lib";
import { MiniDb } from "jotai-minidb";

const db = new MiniDb<Dictionary>();
Expand All @@ -20,8 +26,6 @@ export const userPairEquivalenceAtom = atomWithStorage<Equivalence | undefined>(
undefined,
);

export type CustomElementMap = Record<string, string[]>;

export const customElementsAtom = atomWithStorage<
Record<string, CustomElementMap>
>("custom_elements", {});
1 change: 0 additions & 1 deletion src/atoms/cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
Thread,
algebraAtom,
analysisAtom,
assetsAtom,
charactersAtom,
dictionaryAtom,
encoderAtom,
Expand Down
12 changes: 1 addition & 11 deletions src/atoms/constants.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { atom } from "jotai";
import type { Dictionary, Distribution, Equivalence, Frequency } from "~/lib";
import {
getDictFromTSV,
getDistributionFromTSV,
Expand Down Expand Up @@ -58,17 +59,6 @@ export const mutateRepertoireAtom = atom(
},
);

interface Loss {
ideal: number;
lt_penalty: number;
gt_penalty: number;
}

export type Dictionary = [string, string][];
export type Frequency = Record<string, number>;
export type Distribution = Record<string, Loss>;
export type Equivalence = Record<string, number>;

export const defaultDictionaryAtom = atom<Promise<Dictionary>>(async () =>
getDictFromTSV(await fetchAsset("dictionary", "txt")),
);
Expand Down
2 changes: 1 addition & 1 deletion src/atoms/data.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { atom, useAtomValue } from "jotai";
import { atom } from "jotai";
import { primitiveRepertoireAtom } from "./constants";
import type {
CharacterSetSpecifier,
Expand Down
1 change: 0 additions & 1 deletion src/atoms/encoder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { focusAtom } from "jotai-optics";
import { encoderAtom } from ".";
import type { ShortCodeRule, WordRule } from "~/lib";
import { ShortCodeScheme } from "~/lib";

export const maxLengthAtom = focusAtom(encoderAtom, (o) =>
o.prop("max_length"),
Expand Down
9 changes: 4 additions & 5 deletions src/atoms/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { Config } from "~/lib";
import { isValidCJKChar, makeWorker } from "~/lib";
import { isValidCJKChar, makeJsWorker, makeWasmWorker } from "~/lib";
import useTitle from "ahooks/es/useTitle";
import init, { validate } from "libchai";
import type { LibchaiOutputEvent } from "~/worker";
Expand All @@ -12,12 +12,11 @@ import { load } from "js-yaml";

export class Thread {
private worker: Worker;
constructor(type: "js" | "wasm") {
const url = type === "js" ? "../jsworker.ts" : undefined;
this.worker = makeWorker(url);
public constructor(type: "js" | "wasm") {
this.worker = type === "js" ? makeJsWorker() : makeWasmWorker();
}

async spawn<R>(func: string, args: any[]): Promise<R> {
public async spawn<R>(func: string, args: any[]): Promise<R> {
return await new Promise((resolve) => {
const channel = new MessageChannel();
channel.port1.onmessage = ({ data }) => {
Expand Down
2 changes: 1 addition & 1 deletion src/atoms/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import type { WritableAtom } from "jotai";
import { useAtom, useAtomValue, useSetAtom } from "jotai";
import { useAtomValue, useSetAtom } from "jotai";

export * from "jotai";
export * from "./constants";
Expand Down
2 changes: 1 addition & 1 deletion src/atoms/optimization.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { focusAtom } from "jotai-optics";
import { atom, optimAtom } from ".";
import { optimAtom } from ".";

export const objectiveAtom = focusAtom(optimAtom, (o) => o.prop("objective"));
objectiveAtom.debugLabel = "optimization.objective";
Expand Down
5 changes: 1 addition & 4 deletions src/components/Action.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import {
Input,
Popconfirm,
Popover,
Space,
} from "antd";
import type { ForwardedRef } from "react";
import { createContext, forwardRef, useContext, useState } from "react";
import { forwardRef, useContext, useState } from "react";
import {
remoteCreate,
remoteCreateWithoutUnicode,
Expand All @@ -22,15 +21,13 @@ import type { Reading } from "~/lib";
import {
chars,
isValidCJKChar,
getDummyBasicComponent,
getDummyCompound,
getDummyDerivedComponent,
} from "~/lib";
import {
useAtomValue,
useSetAtom,
mutateRepertoireAtom,
useAtom,
repertoireAtom,
nextUnicodeAtom,
useAddAtom,
Expand Down
4 changes: 2 additions & 2 deletions src/components/CharacterQuery.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Form, Input } from "antd";
import { Form } from "antd";
import type { CharacterFilter } from "~/lib";
import { Operator, PrimitiveRepertoire, Repertoire, operators } from "~/lib";
import { operators } from "~/lib";
import {
ProFormDigit,
ProFormSelect,
Expand Down
1 change: 0 additions & 1 deletion src/components/CharacterSearch.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { Input } from "antd";
import SearchOutlined from "@ant-design/icons/SearchOutlined";
import { Repertoire } from "~/lib";

interface StrokeSearchProps {
setSequence: (s: string) => void;
Expand Down
6 changes: 2 additions & 4 deletions src/components/CharacterSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ import { displayAtom, sequenceAtom, sortedRepertoireAtom } from "~/atoms";
import { Select } from "./Utils";
import type { SelectProps } from "antd";
import type { Character } from "~/lib";
import { PrimitiveCharacter } from "~/lib";
import type { ProFormSelectProps } from "@ant-design/pro-components";
import { ProFormSelect } from "@ant-design/pro-components";

interface ItemSelectProps extends SelectProps {
customFilter?: (e: [string, Character]) => boolean;
Expand All @@ -22,14 +20,14 @@ export const GlyphSelect = (props: ItemSelectProps & ProFormSelectProps) => {
useEffect(() => {
const initial = char ? [{ value: char, label: display(char) }] : [];
setData(initial);
}, [props.value]);
}, [props.value, char, display]);
const onSearch = (input: string) => {
if (input.length === 0) {
setData([]);
return;
}
const allResults = sortedRepertoire
.filter(props.customFilter ?? ((_) => true))
.filter(customFilter ?? (() => true))
.map(([x]) => ({
value: x,
label: display(x),
Expand Down
12 changes: 8 additions & 4 deletions src/components/CharacterTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import {
import ComponentForm from "./ComponentForm";
import CompoundForm from "./CompoundForm";
import { remoteUpdate } from "~/api";
import { DeleteButton, PlusButton } from "./Utils";
import { DeleteButton } from "./Utils";
import Element from "./Element";
import * as O from "optics-ts/standalone";
import CharacterQuery from "./CharacterQuery";
Expand All @@ -52,9 +52,13 @@ function ReadingList({ readings }: { readings: Reading[] }) {
return (
<Space>
{readings.map((reading, index) => {
const core = <Element key={index}>{reading.pinyin}</Element>;
const core = <Element>{reading.pinyin}</Element>;
if (readings.length === 1) return core;
return <Tooltip title={reading.importance + "%"}>{core}</Tooltip>;
return (
<Tooltip key={index} title={reading.importance + "%"}>
{core}
</Tooltip>
);
})}
</Space>
);
Expand Down Expand Up @@ -379,7 +383,7 @@ export default function CharacterTable() {
<CharacterQuery setFilter={setFilterProps} />
<Flex gap="large" ref={ref2}>
<TagPicker />
<Create onCreate={(char) => {}} ref={ref3} />
<Create onCreate={() => {}} ref={ref3} />
</Flex>
<div ref={ref1}>
<Table<PrimitiveCharacter>
Expand Down
1 change: 0 additions & 1 deletion src/components/Classifier.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import {
customClassifierAtom,
useAddAtom,
useAtomValue,
useSetAtom,
} from "~/atoms";
import { Button, Flex, Space, notification } from "antd";
import Element from "~/components/Element";
Expand Down
10 changes: 5 additions & 5 deletions src/components/ComponentForm.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import type { FormListFieldData } from "antd";
import { Button, Flex, Form, Dropdown, notification } from "antd";
import { EditorColumn, EditorRow, NumberInput } from "./Utils";
import { Flex, Form } from "antd";
import { EditorColumn, EditorRow } from "./Utils";
import type { MutableRefObject, ReactNode } from "react";
import { useRef } from "react";
import type { PrimitiveCharacter, Component, Character } from "~/lib";
import type { Character, Component } from "~/lib";
import type { Feature } from "~/lib";
import { getDummySVGStroke, schema } from "~/lib";
import { getDummyReferenceStroke, isComponent } from "~/lib";
Expand Down Expand Up @@ -183,7 +183,7 @@ export default function ComponentForm({
) : (
<Element type={primary ? "default" : "text"}>{title}</Element>
);
const isValidSource = ([name, _]: [string, Character]) => {
const isValidSource = ([name]: [string, Character]) => {
let component: Component | undefined =
repertoire[name]?.glyphs.find(isComponent);
if (component === undefined) return false;
Expand Down Expand Up @@ -262,7 +262,7 @@ export default function ComponentForm({
: getDummySVGStroke("横")
}
>
{(meta, index) => {
{(meta) => {
return (
<StrokeForm
maxIndex={maxIndex}
Expand Down
4 changes: 2 additions & 2 deletions src/components/CompoundForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { AutoComplete, Button, Flex, Form, Typography } from "antd";
import { AutoComplete, Flex, Form } from "antd";
import type { Compound } from "~/lib";
import { operators } from "~/lib";
import { useWatch } from "antd/es/form/Form";
Expand Down Expand Up @@ -130,7 +130,7 @@ export default function CompoundForm({
allowClear={false}
/>
<StaticList name="operandList" itemRender={InlineRender}>
{(meta, i) => (
{(meta) => (
<Form.Item noStyle {...meta}>
<GlyphSelect style={{ width: "96px" }} disabled={readonly} />
</Form.Item>
Expand Down
2 changes: 1 addition & 1 deletion src/components/ConfigManager.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, Flex, notification } from "antd";
import { Button, Flex } from "antd";
import { configAtom, roundTestConfig, useAtom, validateConfig } from "~/atoms";
import { examples, exportYAML } from "~/lib";

Expand Down
Loading

0 comments on commit 58d5ad3

Please sign in to comment.