From fe063635300fbbe74e414d364e2c75b2c8783752 Mon Sep 17 00:00:00 2001 From: stacksmash76 <98354295+stacksmash76@users.noreply.github.com> Date: Tue, 8 Feb 2022 18:10:47 +0100 Subject: [PATCH] chore: add eslint and cleanup (#118) * refactor: modified existing react imports to conform with the recommended approach of not using the default export directly, since it will be deprecated in one of the future releases. see https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html for more info. note: react types don't require importing of react. refactor: cleaned up some of the imports * feat: added eslint and fixed all the errors/warning. eslint can now be invoked by running "npm run lint". chore: updated .gitignore not to include unnecessary artefacts. refactor: re-organized some of the imports. * refactor: converted remaining few typed functional components to proper prop argument structure. * fix: fixed small react-query invalidation bug for the FilterDetails component. Co-authored-by: anonymous --- .gitignore | 6 + web/package.json | 71 +++++++++- web/src/App.tsx | 2 +- web/src/api/APIClient.ts | 2 +- web/src/components/inputs/common.tsx | 9 +- web/src/components/inputs/input.tsx | 34 +++-- web/src/components/inputs/input_wide.tsx | 42 ++++-- web/src/components/inputs/select.tsx | 43 +++--- web/src/components/inputs/switch.tsx | 27 ++-- web/src/domain/react-table-config.d.ts | 2 +- web/src/forms/filters/FilterAddForm.tsx | 32 ++--- .../forms/settings/DownloadClientForms.tsx | 8 +- web/src/forms/settings/IndexerForms.tsx | 67 ++++----- web/src/forms/settings/IrcForms.tsx | 31 +++-- web/src/hooks/hooks.ts | 11 +- web/src/index.tsx | 11 +- web/src/reportWebVitals.ts | 2 +- web/src/screens/Dashboard.tsx | 131 ++++++++++-------- web/src/screens/Logs.tsx | 9 +- web/src/screens/Releases.tsx | 120 +++++++++------- web/src/screens/Settings.tsx | 9 +- web/src/screens/auth/logout.tsx | 2 +- web/src/screens/filters/details.tsx | 91 +++++++----- web/src/screens/filters/list.tsx | 17 ++- web/src/screens/settings/Action.tsx | 5 - web/src/screens/settings/DownloadClient.tsx | 3 +- web/src/screens/settings/Indexer.tsx | 7 +- web/src/screens/settings/RegexPlayground.tsx | 2 +- web/src/utils/index.ts | 10 +- 29 files changed, 463 insertions(+), 343 deletions(-) diff --git a/.gitignore b/.gitignore index 5a8c262..45ab3c8 100644 --- a/.gitignore +++ b/.gitignore @@ -20,8 +20,14 @@ Thumbs.db # Other .idea +.yarn node_modules/ web/build bin/ log/ dist/ +# If needed, package-lock.json shall be added +# manually using an explicit git add command. +package-lock.json +# Ditto for yarn, except we're using npm. +yarn.lock diff --git a/web/package.json b/web/package.json index 4863656..cb419eb 100644 --- a/web/package.json +++ b/web/package.json @@ -26,13 +26,9 @@ "start": "react-scripts start", "build": "react-scripts build", "test": "react-scripts test", - "eject": "react-scripts eject" - }, - "eslintConfig": { - "extends": [ - "react-app", - "react-app/jest" - ] + "eject": "react-scripts eject", + "lint": "esw src/ --ext \".ts,.tsx,.js,.jsx\" --color", + "lint:watch": "npm run lint -- --watch" }, "browserslist": { "production": [ @@ -57,9 +53,70 @@ "@types/react-dom": "^17.0.0", "@types/react-router-dom": "^5.1.7", "@types/react-table": "^7.7.7", + "@typescript-eslint/eslint-plugin": "^5.10.2", + "@typescript-eslint/parser": "^5.10.2", "autoprefixer": "^10.4.2", + "eslint": "^8.8.0", + "eslint-plugin-import": "^2.25.4", + "eslint-plugin-react": "^7.28.0", + "eslint-plugin-react-hooks": "^4.3.0", + "eslint-watch": "^8.0.0", "postcss": "^8.4.6", "tailwindcss": "^3.0.18", "typescript": "^4.1.2" + }, + "eslintConfig": { + "root": true, + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:import/errors", + "plugin:import/warnings", + "plugin:@typescript-eslint/eslint-recommended", + "plugin:@typescript-eslint/recommended", + "plugin:react-hooks/recommended" + ], + "plugins": [ + "react", + "@typescript-eslint" + ], + "rules": { + "react/jsx-uses-react": "off", + "react/react-in-jsx-scope": "off", + "@typescript-eslint/explicit-module-boundary-types": "off", + "@typescript-eslint/ban-ts-comment": "off", + "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/no-explicit-any": "off" + }, + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": 11, + "sourceType": "module", + "ecmaFeatures": { + "jsx": true, + "experimentalObjectRestSpread": true + } + }, + "settings": { + "react": { + "version": "detect" + }, + "import/resolver": { + "node": { + "extensions": [ + ".ts", + ".tsx", + ".js", + ".jsx" + ] + } + } + }, + "env": { + "browser": true, + "node": true, + "jquery": false + }, + "globals": {} } } diff --git a/web/src/App.tsx b/web/src/App.tsx index 2118273..6040d10 100644 --- a/web/src/App.tsx +++ b/web/src/App.tsx @@ -39,4 +39,4 @@ export function App() { ) : null} ) -}; \ No newline at end of file +} \ No newline at end of file diff --git a/web/src/api/APIClient.ts b/web/src/api/APIClient.ts index d87efa2..846f3be 100644 --- a/web/src/api/APIClient.ts +++ b/web/src/api/APIClient.ts @@ -1,7 +1,7 @@ import {baseUrl, sseBaseUrl} from "../utils"; function baseClient(endpoint: string, method: string, { body, ...customConfig}: any = {}) { - let baseURL = baseUrl() + const baseURL = baseUrl() const headers = {'content-type': 'application/json'} const config = { diff --git a/web/src/components/inputs/common.tsx b/web/src/components/inputs/common.tsx index df9b992..14db192 100644 --- a/web/src/components/inputs/common.tsx +++ b/web/src/components/inputs/common.tsx @@ -1,4 +1,3 @@ -import React from "react"; import { Field } from "formik"; interface ErrorFieldProps { @@ -7,7 +6,7 @@ interface ErrorFieldProps { subscribe?: any; } -const ErrorField: React.FC = ({ name, classNames }) => ( +const ErrorField = ({ name, classNames }: ErrorFieldProps) => ( {({ meta: { touched, error } }: any) => touched && error ? {error} : null @@ -21,7 +20,11 @@ interface CheckboxFieldProps { sublabel?: string; } -const CheckboxField: React.FC = ({ name, label, sublabel }) => ( +const CheckboxField = ({ + name, + label, + sublabel +}: CheckboxFieldProps) => (
= ({ name, label, placeholder, columns, className, autoComplete }) => ( +export const TextField = ({ + name, + label, + placeholder, + columns, + autoComplete +}: TextFieldProps) => (
= ({ name, label, placeholder, defaultValue, columns, className, autoComplete, help, required }) => { +export const PasswordField = ({ + name, + label, + placeholder, + defaultValue, + columns, + autoComplete, + help, + required +}: PasswordFieldProps) => { const [isVisible, toggleVisibility] = useToggle(false) return ( @@ -113,17 +125,13 @@ interface NumberFieldProps { name: string; label?: string; placeholder?: string; - className?: string; - required?: boolean; } -const NumberField: React.FC = ({ +export const NumberField = ({ name, label, - placeholder, - required, - className, -}) => ( + placeholder +}: NumberFieldProps) => (
); - -export { TextField, PasswordField, NumberField }; diff --git a/web/src/components/inputs/input_wide.tsx b/web/src/components/inputs/input_wide.tsx index 33c9c75..bfda7ca 100644 --- a/web/src/components/inputs/input_wide.tsx +++ b/web/src/components/inputs/input_wide.tsx @@ -1,5 +1,5 @@ -import React from "react"; -import { Field, FieldProps } from "formik"; +import { Field } from "formik"; +import type { FieldProps } from "formik"; import { classNames } from "../../utils"; import { useToggle } from "../../hooks/hooks"; import { EyeIcon, EyeOffIcon } from "@heroicons/react/solid"; @@ -12,12 +12,19 @@ interface TextFieldWideProps { help?: string; placeholder?: string; defaultValue?: string; - className?: string; required?: boolean; hidden?: boolean; } -const TextFieldWide: React.FC = ({ name, label, help, placeholder, defaultValue, required, hidden, className }) => ( +export const TextFieldWide = ({ + name, + label, + help, + placeholder, + defaultValue, + required, + hidden +}: TextFieldWideProps) => (