refactor: migrate eslint

This commit is contained in:
Johnny
2025-04-01 00:04:43 +08:00
parent d649d326ef
commit b770042a8a
18 changed files with 810 additions and 886 deletions

View File

@@ -1,50 +0,0 @@
{
"env": {
"browser": true,
"es2021": true
},
"extends": ["eslint:recommended", "plugin:react/recommended", "plugin:@typescript-eslint/recommended", "plugin:prettier/recommended"],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
},
"ecmaVersion": "latest",
"sourceType": "module"
},
"plugins": ["react", "@typescript-eslint", "prettier"],
"ignorePatterns": ["node_modules", "dist", "public", "src/assets"],
"rules": {
"prettier/prettier": [
"error",
{
"endOfLine": "auto"
}
],
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": ["off"],
"react/react-in-jsx-scope": "off",
"react/jsx-no-target-blank": "off",
"no-restricted-syntax": [
"error",
{
"selector": "VariableDeclarator[init.callee.name='useTranslation'] > ObjectPattern > Property[key.name='t']:not([parent.declarations.0.init.callee.object.name='i18n'])",
"message": "Destructuring 't' from useTranslation is not allowed. Please use the 'useTranslate' hook from '@/utils/i18n'."
}
]
},
"settings": {
"react": {
"version": "detect"
}
},
"overrides": [
{
"files": ["src/utils/i18n.ts"],
"rules": {
"no-restricted-syntax": "off"
}
}
]
}

34
web/eslint.config.mjs Normal file
View File

@@ -0,0 +1,34 @@
import eslint from "@eslint/js";
import eslintPluginPrettierRecommended from "eslint-plugin-prettier/recommended";
import tseslint from "typescript-eslint";
export default [
...tseslint.config(eslint.configs.recommended, tseslint.configs.recommended),
eslintPluginPrettierRecommended,
{
ignores: ["**/dist/**", "**/node_modules/**", "**/proto/**"],
},
{
rules: {
"no-unused-vars": "off",
"@typescript-eslint/no-unused-vars": "error",
"@typescript-eslint/no-explicit-any": ["off"],
"react/react-in-jsx-scope": "off",
"react/jsx-no-target-blank": "off",
"no-restricted-syntax": [
"error",
{
selector:
"VariableDeclarator[init.callee.name='useTranslation'] > ObjectPattern > Property[key.name='t']:not([parent.declarations.0.init.callee.object.name='i18n'])",
message: "Destructuring 't' from useTranslation is not allowed. Please use the 'useTranslate' hook from '@/utils/i18n'.",
},
],
},
},
{
files: ["src/utils/i18n.ts"],
rules: {
"no-restricted-syntax": "off",
},
},
];

View File

@@ -52,6 +52,7 @@
"devDependencies": { "devDependencies": {
"@bufbuild/buf": "^1.50.1", "@bufbuild/buf": "^1.50.1",
"@bufbuild/protobuf": "^2.2.3", "@bufbuild/protobuf": "^2.2.3",
"@eslint/js": "^9.23.0",
"@trivago/prettier-plugin-sort-imports": "^4.3.0", "@trivago/prettier-plugin-sort-imports": "^4.3.0",
"@types/d3": "^7.4.3", "@types/d3": "^7.4.3",
"@types/katex": "^0.16.7", "@types/katex": "^0.16.7",
@@ -63,15 +64,13 @@
"@types/react-dom": "^18.3.5", "@types/react-dom": "^18.3.5",
"@types/textarea-caret": "^3.0.3", "@types/textarea-caret": "^3.0.3",
"@types/uuid": "^10.0.0", "@types/uuid": "^10.0.0",
"@typescript-eslint/eslint-plugin": "^7.18.0",
"@typescript-eslint/parser": "^7.18.0",
"@vitejs/plugin-legacy": "^6.0.2", "@vitejs/plugin-legacy": "^6.0.2",
"@vitejs/plugin-react": "^4.3.4", "@vitejs/plugin-react": "^4.3.4",
"autoprefixer": "^10.4.21", "autoprefixer": "^10.4.21",
"code-inspector-plugin": "^0.18.3", "code-inspector-plugin": "^0.18.3",
"eslint": "^8.57.1", "eslint": "^9.23.0",
"eslint-config-prettier": "^9.1.0", "eslint-config-prettier": "^10.1.1",
"eslint-plugin-prettier": "^5.2.3", "eslint-plugin-prettier": "^5.2.5",
"eslint-plugin-react": "^7.37.4", "eslint-plugin-react": "^7.37.4",
"long": "^5.3.1", "long": "^5.3.1",
"nice-grpc-web": "^3.3.6", "nice-grpc-web": "^3.3.6",
@@ -80,6 +79,7 @@
"protobufjs": "^7.4.0", "protobufjs": "^7.4.0",
"terser": "^5.39.0", "terser": "^5.39.0",
"typescript": "^5.8.2", "typescript": "^5.8.2",
"typescript-eslint": "^8.28.0",
"vite": "^6.2.1" "vite": "^6.2.1"
}, },
"pnpm": { "pnpm": {

584
web/pnpm-lock.yaml generated

File diff suppressed because it is too large Load Diff

View File

@@ -33,7 +33,7 @@ const LocaleSelect: FC<Props> = (props: Props) => {
</Option> </Option>
); );
} }
} catch (error) { } catch {
// do nth // do nth
} }

View File

@@ -77,7 +77,7 @@ const MemoActionMenu = (props: Props) => {
["pinned"], ["pinned"],
); );
} }
} catch (error) { } catch {
// do nth // do nth
} }
}; };
@@ -108,7 +108,7 @@ const MemoActionMenu = (props: Props) => {
} }
if (isInMemoDetailPage) { if (isInMemoDetailPage) {
memo.state === State.ARCHIVED ? navigateTo("/") : navigateTo("/archived"); navigateTo(memo.state === State.ARCHIVED ? "/" : "/archived");
} }
memoUpdatedCallback(); memoUpdatedCallback();
}; };

View File

@@ -45,7 +45,7 @@ const CodeBlock: React.FC<Props> = ({ language, content }: Props) => {
language: formatedLanguage, language: formatedLanguage,
}).value; }).value;
} }
} catch (error) { } catch {
// Skip error and use default highlighted code. // Skip error and use default highlighted code.
} }

View File

@@ -1,8 +1,4 @@
import { BaseProps } from "./types"; const LineBreak = () => {
interface Props extends BaseProps {}
const LineBreak: React.FC<Props> = () => {
return <br />; return <br />;
}; };

View File

@@ -14,7 +14,7 @@ const getFaviconWithGoogleS2 = (url: string) => {
try { try {
const urlObject = new URL(url); const urlObject = new URL(url);
return `https://www.google.com/s2/favicons?sz=128&domain=${urlObject.hostname}`; return `https://www.google.com/s2/favicons?sz=128&domain=${urlObject.hostname}`;
} catch (error) { } catch {
return undefined; return undefined;
} }
}; };

View File

@@ -86,7 +86,11 @@ const TagSuggestions = observer(({ editorRef, editorActions }: Props) => {
const caretCordinates = getCaretCoordinates(editor, index); const caretCordinates = getCaretCoordinates(editor, index);
caretCordinates.top -= editor.scrollTop; caretCordinates.top -= editor.scrollTop;
isActive ? setPosition(caretCordinates) : hide(); if (isActive) {
setPosition(caretCordinates);
} else {
hide();
}
}; };
const listenersAreRegisteredRef = useRef(false); const listenersAreRegisteredRef = useRef(false);

View File

@@ -4,6 +4,7 @@ export interface NodeType {
memo: MemoRelation_Memo; memo: MemoRelation_Memo;
} }
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface LinkType { export interface LinkType {
// ...add more additional properties relevant to the link here. // ...add more additional properties relevant to the link here.
} }

View File

@@ -49,7 +49,7 @@ const ReactionSelector = (props: Props) => {
}); });
} }
await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true }); await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true });
} catch (error) { } catch {
// skip error. // skip error.
} }
setOpen(false); setOpen(false);

View File

@@ -58,7 +58,7 @@ const ReactionView = (props: Props) => {
await memoServiceClient.deleteMemoReaction({ id: reaction.id }); await memoServiceClient.deleteMemoReaction({ id: reaction.id });
} }
} }
} catch (error) { } catch {
// Skip error. // Skip error.
} }
await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true }); await memoStore.getOrFetchMemoByName(memo.name, { skipCache: true });

View File

@@ -9,7 +9,6 @@ const PopoverTrigger = PopoverPrimitive.Trigger;
const PopoverContent = React.forwardRef< const PopoverContent = React.forwardRef<
React.ElementRef<typeof PopoverPrimitive.Content>, React.ElementRef<typeof PopoverPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content> React.ComponentPropsWithoutRef<typeof PopoverPrimitive.Content>
// eslint-disable-next-line react/prop-types
>(({ className, align = "center", sideOffset = 4, ...props }, ref) => ( >(({ className, align = "center", sideOffset = 4, ...props }, ref) => (
<PopoverPrimitive.Portal> <PopoverPrimitive.Portal>
<PopoverPrimitive.Content <PopoverPrimitive.Content

View File

@@ -25,7 +25,7 @@ export const isValidUrl = (url: string): boolean => {
try { try {
new URL(url); new URL(url);
return true; return true;
} catch (err) { } catch {
return false; return false;
} }
}; };