Skip to content

Commit

Permalink
fix: lint
Browse files Browse the repository at this point in the history
  • Loading branch information
greenhat616 committed Dec 1, 2023
1 parent 419efc3 commit 98a647d
Show file tree
Hide file tree
Showing 24 changed files with 164 additions and 128 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ dist-ssr
update.json
scripts/_env.sh
.vscode

.eslintcache
.stylelintcache
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"web:serve": "vite preview",
"lint": "run-s lint:*",
"lint:prettier": "prettier --check .",
"lint:eslint": "eslint --ext .ts,.tsx,.js,.jsx .",
"lint:eslint": "eslint --cache .",
"lint:ts": "tsc --noEmit",
"lint:backend": "cargo clippy --manifest-path ./backend/Cargo.toml --all-targets --all-features -- -D warnings",
"lint:backend": "cargo clippy --manifest-path ./backend/Cargo.toml --all-targets --all-features",
"fmt": "run-p fmt:*",
"fmt:backend": "cargo fmt --manifest-path ./backend/Cargo.toml --all",
"fmt:prettier": "prettier --write .",
Expand Down
2 changes: 1 addition & 1 deletion scripts/check.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ function clashRs(): BinInfo {
async function getLatestVersion() {
try {
const response = await fetch(VERSION_URL, { method: "GET" });
let v = await response.text();
const v = await response.text();
META_VERSION = v.trim();
console.log(`Latest release version: ${META_VERSION}`);
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion scripts/updater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ async function resolveUpdater() {
});

// delete the old assets
for (let asset of updateRelease.assets) {
for (const asset of updateRelease.assets) {
if (asset.name === UPDATE_JSON_FILE) {
await github.rest.repos.deleteReleaseAsset({
...options,
Expand Down
8 changes: 4 additions & 4 deletions src/components/base/base-dialog.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ReactNode } from "react";
import { LoadingButton } from "@mui/lab";
import {
Button,
Dialog,
Expand All @@ -8,7 +8,7 @@ import {
type SxProps,
type Theme,
} from "@mui/material";
import { LoadingButton } from "@mui/lab";
import { ReactNode } from "react";

interface Props {
title: ReactNode;
Expand All @@ -31,7 +31,7 @@ export interface DialogRef {
close: () => void;
}

export const BaseDialog: React.FC<Props> = (props) => {
export function BaseDialog(props: Props) {
const {
open,
title,
Expand Down Expand Up @@ -71,4 +71,4 @@ export const BaseDialog: React.FC<Props> = (props) => {
)}
</Dialog>
);
};
}
8 changes: 4 additions & 4 deletions src/components/base/base-notice.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createRoot } from "react-dom/client";
import { ReactNode, useState } from "react";
import { CheckCircleRounded, Close, ErrorRounded } from "@mui/icons-material";
import { Box, IconButton, Slide, Snackbar, Typography } from "@mui/material";
import { Close, CheckCircleRounded, ErrorRounded } from "@mui/icons-material";
import { ReactNode, useState } from "react";
import { createRoot } from "react-dom/client";

interface InnerProps {
type: string;
Expand Down Expand Up @@ -68,7 +68,7 @@ interface NoticeInstance {

let parent: HTMLDivElement = null!;

// @ts-ignore
// @ts-expect-error 90 行动态添加了 info、error、success 属性
export const Notice: NoticeInstance = (props) => {
if (!parent) {
parent = document.createElement("div");
Expand Down
12 changes: 7 additions & 5 deletions src/components/connection/connection-detail.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import dayjs from "dayjs";
import { forwardRef, useImperativeHandle, useState } from "react";
import { useLockFn } from "ahooks";
import { Box, Button, Snackbar } from "@mui/material";
import { deleteConnection } from "@/services/api";
import { truncateStr } from "@/utils/truncate-str";
import parseTraffic from "@/utils/parse-traffic";
import { truncateStr } from "@/utils/truncate-str";
import { Box, Button, Snackbar } from "@mui/material";
import { useLockFn } from "ahooks";
import dayjs from "dayjs";
import { forwardRef, useImperativeHandle, useState } from "react";

export interface ConnectionDetailRef {
open: (detail: IConnectionsItem) => void;
Expand Down Expand Up @@ -40,6 +40,8 @@ export const ConnectionDetail = forwardRef<ConnectionDetailRef>(
},
);

ConnectionDetail.displayName = "ConnectionDetail";

interface InnerProps {
data: IConnectionsItem;
onClose?: () => void;
Expand Down
4 changes: 3 additions & 1 deletion src/components/layout/traffic-graph.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";
import { useTheme } from "@mui/material";
import { forwardRef, useEffect, useImperativeHandle, useRef } from "react";

const maxPoint = 30;

Expand Down Expand Up @@ -193,3 +193,5 @@ export const TrafficGraph = forwardRef<TrafficRef>((props, ref) => {

return <canvas ref={canvasRef} style={{ width: "100%", height: "100%" }} />;
});

TrafficGraph.displayName = "TrafficGraph";
30 changes: 16 additions & 14 deletions src/components/profile/profile-viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import {
forwardRef,
useEffect,
useImperativeHandle,
useRef,
useState,
} from "react";
import { useLockFn } from "ahooks";
import { useTranslation } from "react-i18next";
import { useForm, Controller } from "react-hook-form";
import { BaseDialog } from "@/components/base";
import { useNotification } from "@/hooks/use-notification";
import { createProfile, patchProfile } from "@/services/cmds";
import {
Box,
FormControl,
Expand All @@ -16,14 +9,21 @@ import {
MenuItem,
Select,
Switch,
styled,
TextField,
styled,
} from "@mui/material";
import { createProfile, patchProfile } from "@/services/cmds";
import { BaseDialog } from "@/components/base";
import { version } from "@root/package.json";
import { useLockFn } from "ahooks";
import {
forwardRef,
useEffect,
useImperativeHandle,
useRef,
useState,
} from "react";
import { Controller, useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { FileInput } from "./file-input";
import { useNotification } from "@/hooks/use-notification";

interface Props {
onChange: () => void;
Expand Down Expand Up @@ -277,6 +277,8 @@ export const ProfileViewer = forwardRef<ProfileViewerRef, Props>(
},
);

ProfileViewer.displayName = "ProfileViewer";

const StyledBox = styled(Box)(() => ({
margin: "8px 0 8px 8px",
display: "flex",
Expand Down
26 changes: 13 additions & 13 deletions src/components/proxy/proxy-head.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import { Box, IconButton, TextField, SxProps } from "@mui/material";
import { useVerge } from "@/hooks/use-verge";
import delayManager from "@/services/delay";
import {
AccessTimeRounded,
FilterAltOffRounded,
FilterAltRounded,
MyLocationRounded,
NetworkCheckRounded,
FilterAltRounded,
FilterAltOffRounded,
VisibilityRounded,
VisibilityOffRounded,
WifiTetheringRounded,
WifiTetheringOffRounded,
SortByAlphaRounded,
SortRounded,
VisibilityOffRounded,
VisibilityRounded,
WifiTetheringOffRounded,
WifiTetheringRounded,
} from "@mui/icons-material";
import { useVerge } from "@/hooks/use-verge";
import type { HeadState } from "./use-head-state";
import { Box, IconButton, SxProps, TextField } from "@mui/material";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";
import type { ProxySortType } from "./use-filter-sort";
import delayManager from "@/services/delay";
import type { HeadState } from "./use-head-state";

interface Props {
sx?: SxProps;
Expand Down Expand Up @@ -45,7 +45,7 @@ export const ProxyHead = (props: Props) => {
const { verge } = useVerge();

useEffect(() => {
delayManager.setUrl(groupName, testUrl || verge?.default_latency_test!);
delayManager.setUrl(groupName, testUrl || verge!.default_latency_test!);
}, [groupName, testUrl, verge?.default_latency_test]);

return (
Expand Down
2 changes: 2 additions & 0 deletions src/components/setting/mods/clash-core-viewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,5 @@ export const ClashCoreViewer = forwardRef<DialogRef>((props, ref) => {
</BaseDialog>
);
});

ClashCoreViewer.displayName = "ClashCoreViewer";
20 changes: 11 additions & 9 deletions src/components/setting/mods/clash-field-viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import useSWR from "swr";
import { forwardRef, useImperativeHandle, useState } from "react";
import { useTranslation } from "react-i18next";
import { Checkbox, Divider, Stack, Tooltip, Typography } from "@mui/material";
import { InfoRounded } from "@mui/icons-material";
import { BaseDialog, DialogRef } from "@/components/base";
import { useNotification } from "@/hooks/use-notification";
import { useProfiles } from "@/hooks/use-profiles";
import { getRuntimeExists } from "@/services/cmds";
import {
HANDLE_FIELDS,
DEFAULT_FIELDS,
HANDLE_FIELDS,
OTHERS_FIELDS,
} from "@/utils/clash-fields";
import { BaseDialog, DialogRef } from "@/components/base";
import { useProfiles } from "@/hooks/use-profiles";
import { useNotification } from "@/hooks/use-notification";
import { InfoRounded } from "@mui/icons-material";
import { Checkbox, Divider, Stack, Tooltip, Typography } from "@mui/material";
import { forwardRef, useImperativeHandle, useState } from "react";
import { useTranslation } from "react-i18next";
import useSWR from "swr";

const otherFields = [...OTHERS_FIELDS];
const handleFields = [...HANDLE_FIELDS, ...DEFAULT_FIELDS];
Expand Down Expand Up @@ -114,6 +114,8 @@ export const ClashFieldViewer = forwardRef<DialogRef>((props, ref) => {
);
});

ClashFieldViewer.displayName = "ClashFieldViewer";

function WarnIcon() {
return (
<Tooltip title="The field exists in the config but not enabled.">
Expand Down
14 changes: 8 additions & 6 deletions src/components/setting/mods/clash-port-viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { forwardRef, useImperativeHandle, useState } from "react";
import { useTranslation } from "react-i18next";
import { useLockFn } from "ahooks";
import { List, ListItem, ListItemText, TextField } from "@mui/material";
import { useClashInfo } from "@/hooks/use-clash";
import { BaseDialog, DialogRef } from "@/components/base";
import { useVerge } from "@/hooks/use-verge";
import { useClashInfo } from "@/hooks/use-clash";
import { useNotification } from "@/hooks/use-notification";
import { useVerge } from "@/hooks/use-verge";
import { List, ListItem, ListItemText, TextField } from "@mui/material";
import { useLockFn } from "ahooks";
import { forwardRef, useImperativeHandle, useState } from "react";
import { useTranslation } from "react-i18next";

export const ClashPortViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -69,3 +69,5 @@ export const ClashPortViewer = forwardRef<DialogRef>((props, ref) => {
</BaseDialog>
);
});

ClashPortViewer.displayName = "ClashPortViewer";
12 changes: 7 additions & 5 deletions src/components/setting/mods/config-viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
import { BaseDialog, DialogRef } from "@/components/base";
import { getRuntimeYaml } from "@/services/cmds";
import { atomThemeMode } from "@/services/states";
import { Chip } from "@mui/material";
import { editor } from "monaco-editor/esm/vs/editor/editor.api";
import {
forwardRef,
useEffect,
Expand All @@ -7,11 +12,6 @@ import {
} from "react";
import { useTranslation } from "react-i18next";
import { useRecoilValue } from "recoil";
import { Chip } from "@mui/material";
import { atomThemeMode } from "@/services/states";
import { getRuntimeYaml } from "@/services/cmds";
import { BaseDialog, DialogRef } from "@/components/base";
import { editor } from "monaco-editor/esm/vs/editor/editor.api";

import "monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution.js";
import "monaco-editor/esm/vs/basic-languages/yaml/yaml.contribution.js";
Expand Down Expand Up @@ -74,3 +74,5 @@ export const ConfigViewer = forwardRef<DialogRef>((props, ref) => {
</BaseDialog>
);
});

ConfigViewer.displayName = "ConfigViewer";
12 changes: 7 additions & 5 deletions src/components/setting/mods/controller-viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { forwardRef, useImperativeHandle, useState } from "react";
import { useLockFn } from "ahooks";
import { useTranslation } from "react-i18next";
import { List, ListItem, ListItemText, TextField } from "@mui/material";
import { useClashInfo } from "@/hooks/use-clash";
import { BaseDialog, DialogRef } from "@/components/base";
import { useClashInfo } from "@/hooks/use-clash";
import { useNotification } from "@/hooks/use-notification";
import { List, ListItem, ListItemText, TextField } from "@mui/material";
import { useLockFn } from "ahooks";
import { forwardRef, useImperativeHandle, useState } from "react";
import { useTranslation } from "react-i18next";

export const ControllerViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -73,3 +73,5 @@ export const ControllerViewer = forwardRef<DialogRef>((props, ref) => {
</BaseDialog>
);
});

ControllerViewer.displayName = "ControllerViewer";
12 changes: 7 additions & 5 deletions src/components/setting/mods/hotkey-viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BaseDialog, DialogRef } from "@/components/base";
import { useNotification } from "@/hooks/use-notification";
import { useVerge } from "@/hooks/use-verge";
import { Typography, styled } from "@mui/material";
import { useLockFn } from "ahooks";
import { forwardRef, useImperativeHandle, useState } from "react";
import { useTranslation } from "react-i18next";
import { useLockFn } from "ahooks";
import { styled, Typography } from "@mui/material";
import { useVerge } from "@/hooks/use-verge";
import { BaseDialog, DialogRef } from "@/components/base";
import { HotkeyInput } from "./hotkey-input";
import { useNotification } from "@/hooks/use-notification";

const ItemWrapper = styled("div")`
display: flex;
Expand Down Expand Up @@ -105,3 +105,5 @@ export const HotkeyViewer = forwardRef<DialogRef>((props, ref) => {
</BaseDialog>
);
});

HotkeyViewer.displayName = "HotkeyViewer";
12 changes: 7 additions & 5 deletions src/components/setting/mods/layout-viewer.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { BaseDialog, DialogRef } from "@/components/base";
import { useNotification } from "@/hooks/use-notification";
import { useVerge } from "@/hooks/use-verge";
import { List, Switch } from "@mui/material";
import { forwardRef, useImperativeHandle, useState } from "react";
import { useTranslation } from "react-i18next";
import { List, Switch } from "@mui/material";
import { useVerge } from "@/hooks/use-verge";
import { BaseDialog, DialogRef } from "@/components/base";
import { SettingItem } from "./setting-comp";
import { GuardState } from "./guard-state";
import { useNotification } from "@/hooks/use-notification";
import { SettingItem } from "./setting-comp";

export const LayoutViewer = forwardRef<DialogRef>((props, ref) => {
const { t } = useTranslation();
Expand Down Expand Up @@ -79,3 +79,5 @@ export const LayoutViewer = forwardRef<DialogRef>((props, ref) => {
</BaseDialog>
);
});

LayoutViewer.displayName = "LayoutViewer";
Loading

0 comments on commit 98a647d

Please sign in to comment.