diff --git a/packages/flat-components/.eslintignore b/packages/flat-components/.eslintignore index 16c6af043cd..c736f1c5f54 100644 --- a/packages/flat-components/.eslintignore +++ b/packages/flat-components/.eslintignore @@ -1,3 +1,5 @@ node_modules/ dist/ public/ +storybook-static/ +.eslintrc.js \ No newline at end of file diff --git a/packages/flat-components/.eslintrc.js b/packages/flat-components/.eslintrc.js index c1e250369c4..ecb3a867b90 100644 --- a/packages/flat-components/.eslintrc.js +++ b/packages/flat-components/.eslintrc.js @@ -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, }, @@ -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: [ diff --git a/packages/flat-components/.storybook/main.js b/packages/flat-components/.storybook/main.js index 043266e4869..afd173d287e 100644 --- a/packages/flat-components/.storybook/main.js +++ b/packages/flat-components/.storybook/main.js @@ -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", @@ -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, diff --git a/packages/flat-components/package.json b/packages/flat-components/package.json index 1bd37390be2..f203592526f 100644 --- a/packages/flat-components/package.json +++ b/packages/flat-components/package.json @@ -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", diff --git a/packages/flat-components/src/components/ClassroomPage/TopBar/TopBarRightBtn/TopBarRightBtn.stories.tsx b/packages/flat-components/src/components/ClassroomPage/TopBar/TopBarRightBtn/TopBarRightBtn.stories.tsx index d0a299aff93..1487735a9eb 100644 --- a/packages/flat-components/src/components/ClassroomPage/TopBar/TopBarRightBtn/TopBarRightBtn.stories.tsx +++ b/packages/flat-components/src/components/ClassroomPage/TopBar/TopBarRightBtn/TopBarRightBtn.stories.tsx @@ -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 = { @@ -15,5 +15,5 @@ export const Overview: Story = args => + icon: , }; diff --git a/packages/flat-components/src/components/ClassroomPage/TopBar/TopBarRoundBtn/TopBarRoundBtn.stories.tsx b/packages/flat-components/src/components/ClassroomPage/TopBar/TopBarRoundBtn/TopBarRoundBtn.stories.tsx index 13cf9cde3e3..7068619b835 100644 --- a/packages/flat-components/src/components/ClassroomPage/TopBar/TopBarRoundBtn/TopBarRoundBtn.stories.tsx +++ b/packages/flat-components/src/components/ClassroomPage/TopBar/TopBarRoundBtn/TopBarRoundBtn.stories.tsx @@ -16,5 +16,5 @@ Overview.args = { dark: faker.random.boolean(), icon: , className: "pa2", - children: "Hello, world!" + children: "Hello, world!", }; diff --git a/packages/flat-components/src/components/CloudStorage/CloudStorageFileTitle/index.tsx b/packages/flat-components/src/components/CloudStorage/CloudStorageFileTitle/index.tsx index 24d0bb79af2..bc2994ae213 100644 --- a/packages/flat-components/src/components/CloudStorage/CloudStorageFileTitle/index.tsx +++ b/packages/flat-components/src/components/CloudStorage/CloudStorageFileTitle/index.tsx @@ -53,8 +53,13 @@ export const CloudStorageFileTitle = React.memo( return ( = ({ case "error": { return ( <> - {t('upload-fail')} + + {t("upload-fail")} +