From 956d7b34fff6c9cfe8662447a7f2f0486c2e914b Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Fri, 3 Mar 2023 23:56:31 +0200 Subject: [PATCH] fix eslint errors --- .eslintrc.json | 38 +++++++++++++++++++ package-lock.json | 28 ++++++++++++++ package.json | 1 + src/components/App.js | 14 ++++++- src/components/common/PageTitle.js | 7 +++- src/components/common/inputs/PasswordField.js | 5 +++ .../login/components/LoginContainer.js | 2 +- src/features/machines/components/Machine.js | 12 ++++++ src/providers/ApplicationStateProvider.js | 5 +++ src/providers/ToastProvider.js | 5 +++ 10 files changed, 113 insertions(+), 4 deletions(-) create mode 100644 .eslintrc.json diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..90f072a --- /dev/null +++ b/.eslintrc.json @@ -0,0 +1,38 @@ +{ + "env": { + "browser": true, + "es6": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:jest/recommended" + ], + "parser": "@babel/eslint-parser", + "parserOptions": { + "requireConfigFile": false, + "babelOptions": { + "presets": ["@babel/preset-react"] + }, + "ecmaFeatures": { + "experimentalObjectRestSpread": true, + "jsx": true + }, + "sourceType": "module" + }, + "plugins": ["react", "react-hooks", "jest"], + "ignorePatterns": ["**/public"], + "rules": { + "indent": 0, + "linebreak-style": 0, + "quotes": 0, + "semi": 0, + "no-console": 0, + "no-debugger": "warn", + "react/display-name": "off", + "react-hooks/rules-of-hooks": "error", + "react-hooks/exhaustive-deps": "warn", + "no-unused-vars": [1, { "args": "after-used", "argsIgnorePattern": "^_" }] + } +} diff --git a/package-lock.json b/package-lock.json index 959f689..51203e1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -73,6 +73,25 @@ } } }, + "@babel/eslint-parser": { + "version": "7.19.1", + "resolved": "https://registry.npmjs.org/@babel/eslint-parser/-/eslint-parser-7.19.1.tgz", + "integrity": "sha512-AqNf2QWt1rtu2/1rLswy6CDP7H9Oh3mMhk177Y67Rg8d7RD9WfOLLv8CGn6tisFvS2htm86yIe1yLF6I1UDaGQ==", + "dev": true, + "requires": { + "@nicolo-ribaudo/eslint-scope-5-internals": "5.1.1-v1", + "eslint-visitor-keys": "^2.1.0", + "semver": "^6.3.0" + }, + "dependencies": { + "semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "dev": true + } + } + }, "@babel/generator": { "version": "7.20.7", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.20.7.tgz", @@ -2314,6 +2333,15 @@ "@types/whatwg-streams": "^0.0.7" } }, + "@nicolo-ribaudo/eslint-scope-5-internals": { + "version": "5.1.1-v1", + "resolved": "https://registry.npmjs.org/@nicolo-ribaudo/eslint-scope-5-internals/-/eslint-scope-5-internals-5.1.1-v1.tgz", + "integrity": "sha512-54/JRvkLIzzDWshCWfuhadfrfZVPiElY8Fcgmg1HroEly/EDSszzhBAsarCux+D/kOslTRquNzuyGSmUSTTHGg==", + "dev": true, + "requires": { + "eslint-scope": "5.1.1" + } + }, "@nodelib/fs.scandir": { "version": "2.1.5", "resolved": "https://registry.npmjs.org/@nodelib/fs.scandir/-/fs.scandir-2.1.5.tgz", diff --git a/package.json b/package.json index c83c918..794478f 100644 --- a/package.json +++ b/package.json @@ -31,6 +31,7 @@ "react-toastify": "^6.2.0" }, "devDependencies": { + "@babel/eslint-parser": "^7.16.5", "@testing-library/jest-dom": "^5.11.6", "@testing-library/react": "^11.2.2", "@testing-library/user-event": "^12.5.0", diff --git a/src/components/App.js b/src/components/App.js index 2ca86d7..0935b4d 100644 --- a/src/components/App.js +++ b/src/components/App.js @@ -1,4 +1,5 @@ import React from "react"; +import PropTypes from "prop-types"; import Layout from "./Layout"; import { BrowserRouter, Switch, Redirect, Route } from "react-router-dom"; import { useTuitioToken } from "@flare/tuitio-client-react"; @@ -28,6 +29,11 @@ const PrivateRoute = ({ component, ...rest }) => { ); }; +PrivateRoute.propTypes = { + component: PropTypes.node.isRequired, + location: PropTypes.string +}; + const PublicRoute = ({ component, ...rest }) => { const { valid } = useTuitioToken(); return ( @@ -48,7 +54,11 @@ const PublicRoute = ({ component, ...rest }) => { ); }; -const AppWrapper = () => { +PublicRoute.propTypes = { + component: PropTypes.node.isRequired +}; + +const App = () => { return ( @@ -59,4 +69,4 @@ const AppWrapper = () => { ); }; -export default AppWrapper; +export default App; diff --git a/src/components/common/PageTitle.js b/src/components/common/PageTitle.js index c428197..474242e 100644 --- a/src/components/common/PageTitle.js +++ b/src/components/common/PageTitle.js @@ -1,4 +1,5 @@ import React from "react"; +import PropTypes from "prop-types"; import { makeStyles } from "@material-ui/core/styles"; import { Typography } from "@material-ui/core"; @@ -13,7 +14,7 @@ const useStyles = makeStyles(theme => ({ })); const PageTitle = ({ text }) => { - var classes = useStyles(); + const classes = useStyles(); return (
@@ -24,4 +25,8 @@ const PageTitle = ({ text }) => { ); }; +PageTitle.propTypes = { + text: PropTypes.string.isRequired +}; + export default PageTitle; diff --git a/src/components/common/inputs/PasswordField.js b/src/components/common/inputs/PasswordField.js index 5ad0449..e94c1b3 100644 --- a/src/components/common/inputs/PasswordField.js +++ b/src/components/common/inputs/PasswordField.js @@ -1,4 +1,5 @@ import React, { useState } from "react"; +import PropTypes from "prop-types"; import { InputAdornment, TextField, @@ -53,4 +54,8 @@ const PasswordField = ({ label, ...rest }) => { ); }; +PasswordField.propTypes = { + label: PropTypes.string +}; + export default PasswordField; diff --git a/src/features/login/components/LoginContainer.js b/src/features/login/components/LoginContainer.js index 5909658..d14e5c7 100644 --- a/src/features/login/components/LoginContainer.js +++ b/src/features/login/components/LoginContainer.js @@ -14,7 +14,7 @@ const LoginContainer = () => { const { error } = useToast(); const { t } = useTranslation(); const { login, logout } = useTuitioClient({ - onLoginFailed: response => error(t("Login.IncorrectCredentials")), + onLoginFailed: () => error(t("Login.IncorrectCredentials")), onLoginError: err => error(err.message) }); const { valid: tokenIsValid } = useTuitioToken(); diff --git a/src/features/machines/components/Machine.js b/src/features/machines/components/Machine.js index 946adac..4e8b22d 100644 --- a/src/features/machines/components/Machine.js +++ b/src/features/machines/components/Machine.js @@ -41,6 +41,18 @@ const ActionButton = React.forwardRef((props, _ref) => { ); }); +ActionButton.propTypes = { + machine: PropTypes.shape({ + machineId: PropTypes.number.isRequired + }).isRequired, + action: PropTypes.shape({ + code: PropTypes.string.isRequired, + tooltip: PropTypes.string.isRequired, + system: PropTypes.bool.isRequired, + effect: PropTypes.func.isRequired + }).isRequired +}; + const Machine = ({ machine, actions, diff --git a/src/providers/ApplicationStateProvider.js b/src/providers/ApplicationStateProvider.js index 44ee81f..9c27ec0 100644 --- a/src/providers/ApplicationStateProvider.js +++ b/src/providers/ApplicationStateProvider.js @@ -1,4 +1,5 @@ import React, { useReducer, useMemo } from "react"; +import PropTypes from "prop-types"; import { ApplicationStateContext, ApplicationDispatchContext @@ -25,4 +26,8 @@ const ApplicationStateProvider = ({ children }) => { ); }; +ApplicationStateProvider.propTypes = { + children: PropTypes.node.isRequired +}; + export default ApplicationStateProvider; diff --git a/src/providers/ToastProvider.js b/src/providers/ToastProvider.js index 1a3a836..9213665 100644 --- a/src/providers/ToastProvider.js +++ b/src/providers/ToastProvider.js @@ -1,4 +1,5 @@ import React from "react"; +import PropTypes from "prop-types"; import { ToastContainer, Slide } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; @@ -23,4 +24,8 @@ const ToastProvider = ({ children }) => { ); }; +ToastProvider.propTypes = { + children: PropTypes.node.isRequired +}; + export default ToastProvider;