Add react lint support

This commit is contained in:
2026-02-18 14:58:41 +08:00
parent 32169a819e
commit dc097031ed
7 changed files with 1119 additions and 11 deletions

View File

@@ -1,16 +1,37 @@
import { defineConfig } from "eslint/config";
import eslint from '@eslint/js';
import tseslint from 'typescript-eslint';
import reactLint from 'eslint-plugin-react';
export default defineConfig([
eslint.configs.recommended,
...tseslint.configs.recommended,
{
plugins: {
react: reactLint,
},
rules: reactLint.configs.recommended.rules,
languageOptions: {
parserOptions: reactLint.configs.recommended.parserOptions,
},
settings: {
react: {
version: "detect",
}
}
},
{
rules: {
'@typescript-eslint/no-unused-vars': ['warn', {
varsIgnorePattern: '^_',
argsIgnorePattern: '^_',
}],
'react/react-in-jsx-scope': 'off',
'react/jsx-boolean-value': 'error',
'react/jsx-curly-brace-presence': ['error', {
props: 'never',
children: 'never',
}]
}
},
{

View File

@@ -11,6 +11,7 @@
"esbuild": "^0.27.3",
"esbuild-plugin-eslint": "^0.3.12",
"eslint": "9",
"eslint-plugin-react": "^7.37.5",
"pocketbase": "^0.26.8",
"react": "^19.2.4",
"react-dom": "^19.2.4",
@@ -22,7 +23,8 @@
"scripts": {
"build": "node build.js --dev",
"builddbg": "node build.js --dev --debug",
"buildrel": "node build.js"
"buildrel": "node build.js",
"lint": "eslint src"
},
"type": "module"
}

View File

@@ -8,5 +8,5 @@ export type AlertWarnProps = {
};
export default function AlertWarn({ title = "警告", content, onClose, okText = "好的" }: AlertWarnProps) {
return <Modal title={title} open={true} onOk={onClose} onCancel={onClose} okText={okText} cancelButtonProps={{ style: { display: "none" } }}>{content}</Modal>
return <Modal title={title} open onOk={onClose} onCancel={onClose} okText={okText} cancelButtonProps={{ style: { display: "none" } }}>{content}</Modal>
}

View File

@@ -11,7 +11,7 @@ async function make_storage_persist() {
}
}
async function save_data<T>(db: IDBDatabase, storeName: string, data: T, key?: IDBValidKey) {
function save_data<T>(db: IDBDatabase, storeName: string, data: T, key?: IDBValidKey) {
return new Promise<IDBValidKey>((resolve, reject) => {
const tx = db.transaction(storeName, 'readwrite');
const store = tx.objectStore(storeName);
@@ -28,7 +28,7 @@ async function save_data<T>(db: IDBDatabase, storeName: string, data: T, key?: I
type QdChapterKey = [number, number, number];
type QdChapterHashKey = [number, number, string];
async function get_data<T>(db: IDBDatabase, storeName: string, key: IDBValidKey | IDBKeyRange, index?: string): Promise<T | undefined> {
function get_data<T>(db: IDBDatabase, storeName: string, key: IDBValidKey | IDBKeyRange, index?: string): Promise<T | undefined> {
return new Promise<T | undefined>((resolve, reject) => {
const tx = db.transaction(storeName, 'readonly');
const store = tx.objectStore(storeName);
@@ -47,7 +47,7 @@ type GetAllOptions = {
count?: number;
}
async function get_datas<T>(db: IDBDatabase, storeName: string, key?: IDBValidKey | IDBKeyRange, options?: GetAllOptions): Promise<T[]> {
function get_datas<T>(db: IDBDatabase, storeName: string, key?: IDBValidKey | IDBKeyRange, options?: GetAllOptions): Promise<T[]> {
return new Promise<T[]>((resolve, reject) => {
const tx = db.transaction(storeName, 'readonly');
const store = tx.objectStore(storeName);
@@ -61,7 +61,7 @@ async function get_datas<T>(db: IDBDatabase, storeName: string, key?: IDBValidKe
});
}
async function get_data_with_convert<T, U>(db: IDBDatabase, storeName: string, convert: (key: IDBValidKey, data: T, list: U[]) => Promise<void> | void , key?: IDBValidKey | IDBKeyRange, index?: string): Promise<U[]> {
function get_data_with_convert<T, U>(db: IDBDatabase, storeName: string, convert: (key: IDBValidKey, data: T, list: U[]) => Promise<void> | void , key?: IDBValidKey | IDBKeyRange, index?: string): Promise<U[]> {
return new Promise<U[]>((resolve, reject) => {
const list: U[] = [];
const tx = db.transaction(storeName, 'readonly');
@@ -92,7 +92,7 @@ async function get_data_with_convert<T, U>(db: IDBDatabase, storeName: string, c
});
}
async function get_keys<K extends IDBValidKey = IDBValidKey>(db: IDBDatabase, storeName: string, query?: IDBValidKey | IDBKeyRange, options?: GetAllOptions): Promise<K[]> {
function get_keys<K extends IDBValidKey = IDBValidKey>(db: IDBDatabase, storeName: string, query?: IDBValidKey | IDBKeyRange, options?: GetAllOptions): Promise<K[]> {
return new Promise<K[]>((resolve, reject) => {
const tx = db.transaction(storeName, 'readonly');
const store = tx.objectStore(storeName);
@@ -106,7 +106,7 @@ async function get_keys<K extends IDBValidKey = IDBValidKey>(db: IDBDatabase, st
});
}
async function get_count(db: IDBDatabase, storeName: string, key?: IDBValidKey | IDBKeyRange, index?: string): Promise<number> {
function get_count(db: IDBDatabase, storeName: string, key?: IDBValidKey | IDBKeyRange, index?: string): Promise<number> {
return new Promise<number>((resolve, reject) => {
const tx = db.transaction(storeName, 'readonly');
const store = tx.objectStore(storeName);

View File

@@ -62,7 +62,7 @@ export default function BookIndex() {
</Flex>
<Affix offsetTop={10}>
<Flex justify="flex-end" className={styles.affix}>
<Switch checked={bookStatus.showSavedOnly} onChange={setShowSavedOnly} checkedChildren={"仅显示已保存章节"} unCheckedChildren={"显示所有章节"} />
<Switch checked={bookStatus.showSavedOnly} onChange={setShowSavedOnly} checkedChildren="仅显示已保存章节" unCheckedChildren="显示所有章节" />
</Flex>
</Affix>
{bookStatus.showSavedOnly && err && <Result status="error" title="加载章节列表失败" subTitle={err} extra={<Button type="primary" onClick={handle}></Button>} />}

View File

@@ -51,7 +51,7 @@ export default function Books() {
pageSizeOptions={[10, 20, 50, 100]}
onChange={(page, pageSize) => { setPage(page); setPageSize(pageSize); setSearchParams({ page: String(page), pageSize: String(pageSize) }); }}
showTotal={(total, range) => `${total} 条,当前显示 ${range[0]} - ${range[1]}`}
showSizeChanger={true}
showSizeChanger
/>
</Affix>)}
{!pageData && !err && <Skeleton active />}

1087
yarn.lock
View File

File diff suppressed because it is too large Load Diff