Skip to content

Commit

Permalink
fix(eslint,flat-components): eslint invalid and rule too weak (#858)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackHole1 authored Aug 11, 2021
1 parent d833d18 commit 94977c5
Show file tree
Hide file tree
Showing 26 changed files with 225 additions and 81 deletions.
2 changes: 2 additions & 0 deletions packages/flat-components/.eslintignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
node_modules/
dist/
public/
storybook-static/
.eslintrc.js
59 changes: 57 additions & 2 deletions packages/flat-components/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
module.exports = {
parser: "@typescript-eslint/parser",
extends: [
"eslint:recommended",
"plugin:react/recommended",
"plugin:@typescript-eslint/recommended",
"plugin:@typescript-eslint/recommended-requiring-type-checking",
"react-app",
"plugin:jsx-a11y/recommended",
"plugin:@netless/recommended",
"plugin:prettier/recommended",
],
plugins: ["jsx-a11y", "react", "prettier"],
plugins: ["jsx-a11y", "react", "@netless", "prettier", "@typescript-eslint"],
parserOptions: {
ecmaVersion: 2018,
sourceType: "module",
project: "tsconfig.json",
tsconfigRootDir: __dirname,
ecmaFeatures: {
jsx: true,
},
Expand Down Expand Up @@ -205,6 +210,56 @@ module.exports = {
"@typescript-eslint/no-redeclare": "off",
"no-use-before-define": "off",
"@typescript-eslint/explicit-function-return-type": "off",
"@typescript-eslint/array-type": [
"error",
{
default: "array-simple",
readonly: "array-simple",
},
],
"@typescript-eslint/consistent-type-assertions": "error",
"@typescript-eslint/explicit-member-accessibility": [
"error",
{
accessibility: "explicit",
overrides: {
accessors: "explicit",
constructors: "explicit",
},
},
],
"@typescript-eslint/member-delimiter-style": [
"error",
{
multiline: {
delimiter: "semi",
requireLast: true,
},
singleline: {
delimiter: "semi",
requireLast: false,
},
},
],
"@typescript-eslint/no-unused-expressions": "error",
"@typescript-eslint/prefer-namespace-keyword": "error",
"@typescript-eslint/quotes": ["error", "double"],
"@typescript-eslint/semi": ["error", "always"],
"@typescript-eslint/type-annotation-spacing": "error",
"@typescript-eslint/explicit-module-boundary-types": "off",
"@typescript-eslint/ban-ts-comment": "off",
"@typescript-eslint/no-unsafe-call": "off",
"@typescript-eslint/no-unsafe-return": "off",
"@typescript-eslint/no-explicit-any": "off",
"@typescript-eslint/ban-types": "off",
"@typescript-eslint/unbound-method": "off",
"@typescript-eslint/no-unsafe-assignment": "off",
"@typescript-eslint/no-unsafe-member-access": "off",
"prettier/prettier": "error",
"@typescript-eslint/restrict-template-expressions": "off",
"@typescript-eslint/no-misused-promises": "off",
"@typescript-eslint/no-non-null-assertion": "off",
"@typescript-eslint/no-var-requires": "off",
},

overrides: [
Expand Down
21 changes: 21 additions & 0 deletions packages/flat-components/.storybook/main.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
const path = require("path");
const ForkTsCheckerWebpackPlugin = require("fork-ts-checker-webpack-plugin");
const ESLintPlugin = require("eslint-webpack-plugin");

module.exports = {
stories: [
"../src/**/*.stories.mdx",
Expand All @@ -17,6 +21,23 @@ module.exports = {
webpackFinal: async config => {
setupUrlLoader(config);

config.plugins.push(
new ESLintPlugin({
fix: true,
extensions: ["ts", "tsx"],
}),
new ForkTsCheckerWebpackPlugin({
typescript: {
configFile: path.resolve(__dirname, "..", "tsconfig.json"),
diagnosticOptions: {
semantic: true,
syntactic: true,
declaration: true,
},
},
}),
);

config.module.rules.unshift({
test: /\.(sass|scss)(\?.*)?$/i,
sideEffects: true,
Expand Down
3 changes: 2 additions & 1 deletion packages/flat-components/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@
"eslint-plugin-prettier": "^3.1.4",
"eslint-plugin-react": "^7.20.6",
"eslint-plugin-react-app": "^6.2.2",
"eslint-webpack-plugin": "^3.0.1",
"faker": "^5.4.0",
"flat-types": "^0.1.0",
"fork-ts-checker-webpack-plugin": "^6.0.4",
"fork-ts-checker-webpack-plugin": "^6.3.2",
"i18next": "^20.3.1",
"i18next-browser-languagedetector": "^6.0.1",
"less": "^3.12.2",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Meta, Story } from "@storybook/react";
import React from "react";
import { TopBarRightBtn, TopBarRightBtnProps } from ".";
import faker from "faker"
import faker from "faker";
import { UserAddOutlined } from "@ant-design/icons";

const storyMeta: Meta = {
Expand All @@ -15,5 +15,5 @@ export const Overview: Story<TopBarRightBtnProps> = args => <TopBarRightBtn {...
Overview.args = {
title: "Hello, world",
disabled: faker.random.boolean(),
icon: <UserAddOutlined />
icon: <UserAddOutlined />,
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ Overview.args = {
dark: faker.random.boolean(),
icon: <UserAddOutlined />,
className: "pa2",
children: "Hello, world!"
children: "Hello, world!",
};
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,13 @@ export const CloudStorageFileTitle = React.memo<CloudStorageFileTitleProps>(

return (
<span
title={`${isConvertError ? t('transcoding-failure') : isConverting ? t('transcoding-in-progress') : ""
}${fileName}`}
title={`${
isConvertError
? t("transcoding-failure")
: isConverting
? t("transcoding-in-progress")
: ""
}${fileName}`}
{...restProps}
className={classNames(restProps.className, "cloud-storage-file-title", {
"is-convert-ready": !isConverting && !isConvertError,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export const CloudStorageUploadItem: React.FC<CloudStorageUploadItemProps> = ({
case "error": {
return (
<>
<span className="cloud-storage-upload-status is-error">{t('upload-fail')}</span>
<span className="cloud-storage-upload-status is-error">
{t("upload-fail")}
</span>
<Button
className="cloud-storage-upload-status-btn"
shape="circle"
Expand All @@ -79,7 +81,9 @@ export const CloudStorageUploadItem: React.FC<CloudStorageUploadItemProps> = ({
case "success": {
return (
<>
<span className="cloud-storage-upload-status is-success">{t('upload-success')}</span>
<span className="cloud-storage-upload-status is-success">
{t("upload-success")}
</span>
<div className="cloud-storage-upload-status-btn">
<img width={22} height={22} src={checkSVG} aria-hidden />
</div>
Expand All @@ -89,7 +93,7 @@ export const CloudStorageUploadItem: React.FC<CloudStorageUploadItemProps> = ({
default: {
return (
<>
<span className="cloud-storage-upload-status">{t('pending-upload')}</span>
<span className="cloud-storage-upload-status">{t("pending-upload")}</span>
<Button
className="cloud-storage-upload-status-btn"
shape="circle"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ export const CloudStorageUploadTitle = React.memo<CloudStorageUploadTitleProps>(
/>
)}
<h1 className="cloud-storage-upload-title-content">
{finishWithError ? t('upload-exception') : isFinish ? t('upload-completed') : t('transfer-list')}
{finishWithError
? t("upload-exception")
: isFinish
? t("upload-completed")
: t("transfer-list")}
</h1>
{!isFinish && !finishWithError && total && !Number.isNaN(finished) && (
<span className="cloud-storage-upload-title-count">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function renderBeginTimePicker(

function validateTime(): RuleObject {
return {
validator: async (_, value: Date) => {
validator: (_, value: Date): void => {
if (isBefore(value, getRoughNow())) {
throw new Error(t("begin-time-cannot-be-in-the-past"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export function renderEndTimePicker(

function validateTime(): RuleObject {
return {
validator: async (_, value: Date) => {
validator: (_, value: Date): void => {
const beginTime: EditRoomFormValues["beginTime"] = form.getFieldValue("beginTime");
const compareTime = addMinutes(beginTime, MIN_CLASS_DURATION);
if (isBefore(value, compareTime)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ export const renderPeriodicForm = (t: TFunction<string>, lang: string) =>

function validatePeriodicEndTime(): RuleObject {
return {
validator: async (_, value: Date) => {
validator: (_, value: Date): void => {
const {
periodic,
beginTime,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,9 @@ export interface RoomListItemButton<T extends string> {
text: string;
disabled?: boolean;
}
export type RoomListItemButtons<T extends string> = (
| RoomListItemButton<T>
| RoomListItemButton<T>[]
)[];
export type RoomListItemButtons<T extends string> = Array<
RoomListItemButton<T> | Array<RoomListItemButton<T>>
>;

export interface RoomListItemProps<T extends string> {
title: string;
Expand Down Expand Up @@ -121,7 +120,7 @@ function renderButtons<T extends string>(
}

function renderSubMenu<T extends string>(
buttons: RoomListItemButton<T>[],
buttons: Array<RoomListItemButton<T>>,
overlayClassName?: string,
onClickMenu?: (key: T) => void,
): React.ReactNode {
Expand Down Expand Up @@ -186,10 +185,10 @@ export interface RoomListProps<T extends string> {
/** will be hidden on mobile */
title?: string;
/** will be title on mobile */
filters?: {
filters?: Array<{
title: string;
key: T;
}[];
}>;
activeTab?: T;
onTabActive?: (key: T) => void;
style?: React.CSSProperties;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ Overview.args = {
baseUrl: "https://flat-web.whiteboard.agora.io/join/34513345f235",
userName: "Flat",
onCopy: () => {
message.success("复制成功");
void message.success("复制成功");
},
// eslint-disable-next-line @typescript-eslint/no-empty-function
onCancel: () => {},
};
8 changes: 4 additions & 4 deletions packages/flat-components/src/components/InviteModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ export const InviteModal: React.FC<InviteModalProps> = ({
return "";
}

const formatBeginTime = completeTimeFormat(beginTime!);
const formatBeginTime = completeTimeFormat(beginTime);
const formatEndTime =
differenceInCalendarDays(beginTime!, endTime!) !== 0
? completeTimeFormat(endTime!)
: onlySuffixTimeFormat(endTime!);
differenceInCalendarDays(beginTime, endTime) !== 0
? completeTimeFormat(endTime)
: onlySuffixTimeFormat(endTime);

return `${formatBeginTime}~${formatEndTime}`;
}, [beginTime, endTime]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ export const LoginContent: React.FC<LoginContentProps> = ({ onLogin, privacyURL,
<LoginChannel
onLogin={loginChannel => {
if (!isChecked) {
message.info(t("agree-terms"));
void message.info(t("agree-terms"));
} else {
setInPageLogin(onLogin(loginChannel));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface LoginPanelProps {
serviceURL?: string;
}

export const LoginPanel: React.FC<LoginPanelProps> = (props) => {
export const LoginPanel: React.FC<LoginPanelProps> = props => {
return (
<div className="login-panel-container">
<div className="login-panel-cover">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const MoreMenu: React.FC<MoreMenuProps> = ({
userName={userName}
onCopy={text => {
onCopyInvitation(text);
message.success(t("copy-success"));
void message.success(t("copy-success"));
setInviteRoomVisible(false);
}}
onCancel={() => setInviteRoomVisible(false)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { CancelPeriodicRoomModal } from "./CancelPeriodicRoomModal";
import { useTranslation } from "react-i18next";

export interface PeriodicRoomPanelProps {
rooms: (RoomInfo | undefined)[];
rooms: Array<RoomInfo | undefined>;
userName: string;
isCreator: boolean;
inviteBaseUrl: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ Overview.args = {
isCreator: true,
periodicUUID: "periodicUUID",
isPeriodicDetailsPage: true,
// eslint-disable-next-line @typescript-eslint/no-empty-function
onCancel: () => {},
// eslint-disable-next-line @typescript-eslint/no-empty-function
onCancelRoom: () => {},
};
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const RoomDetailFooter = observer<RoomDetailFooterProps>(function RoomDet
userName={userName}
onCopy={text => {
onCopyInvitation(text);
message.success(t("copy-success"));
void message.success(t("copy-success"));
hideInviteModal();
}}
onCancel={hideInviteModal}
Expand Down
Loading

0 comments on commit 94977c5

Please sign in to comment.