From 2b9bc9fb08dec5a50f840f492d828d463a44affa Mon Sep 17 00:00:00 2001 From: Tudor Stanciu Date: Wed, 14 Dec 2022 19:12:26 +0200 Subject: [PATCH] Added eslint and prop-types --- .eslintrc.json | 38 +++++++++++++++++++ package-lock.json | 25 ++++++++++++ package.json | 2 + src/contexts/LayoutContext.js | 5 +++ src/contexts/ToastContext.js | 5 +++ src/contexts/UserContext.js | 5 +++ .../components/ResourcePreviewComponent.js | 3 ++ .../resources/list/components/ActionButton.js | 6 +++ .../list/components/SecondaryActionsGroup.js | 6 +++ 9 files changed, 95 insertions(+) create mode 100644 .eslintrc.json create mode 100644 src/features/resources/edit/components/ResourcePreviewComponent.js diff --git a/.eslintrc.json b/.eslintrc.json new file mode 100644 index 0000000..b66f29c --- /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", "src/components/*", "src/pages/*"], + "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 33d5b8d..5faf282 100644 --- a/package-lock.json +++ b/package-lock.json @@ -47,6 +47,23 @@ } } }, + "@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==", + "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==" + } + } + }, "@babel/generator": { "version": "7.14.5", "resolved": "https://registry.npmjs.org/@babel/generator/-/generator-7.14.5.tgz", @@ -2367,6 +2384,14 @@ "resolved": "https://registry.npmjs.org/@mdi/react/-/react-1.4.0.tgz", "integrity": "sha512-OUH9RhfDJPhybQL3owwrSDIXz2yVKXg5lYeOZjyRCiT9wqywNK0FeYyDByOwNIZnnIQoQYmuSrMv+pOX0Uqkmw==" }, + "@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==", + "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 7930fe5..16fa346 100644 --- a/package.json +++ b/package.json @@ -26,6 +26,7 @@ "@material-ui/styles": "^4.11.3", "@mdi/js": "^5.9.55", "@mdi/react": "^1.4.0", + "@babel/eslint-parser": "^7.16.5", "apexcharts": "^3.24.0", "axios": "^0.19.2", "classnames": "^2.2.6", @@ -35,6 +36,7 @@ "i18next-http-backend": "^1.0.10", "moment": "^2.29.4", "mui-datatables": "^3.7.4", + "prop-types": "15.7.2", "react": "^16.14.0", "react-apexcharts": "^1.3.7", "react-dom": "^16.14.0", diff --git a/src/contexts/LayoutContext.js b/src/contexts/LayoutContext.js index 04a77d2..854e497 100644 --- a/src/contexts/LayoutContext.js +++ b/src/contexts/LayoutContext.js @@ -1,4 +1,5 @@ import React from "react"; +import PropTypes from "prop-types"; var LayoutStateContext = React.createContext(); var LayoutDispatchContext = React.createContext(); @@ -26,6 +27,10 @@ function LayoutProvider({ children }) { ); } +LayoutProvider.propTypes = { + children: PropTypes.node +}; + function useLayoutState() { var context = React.useContext(LayoutStateContext); if (context === undefined) { diff --git a/src/contexts/ToastContext.js b/src/contexts/ToastContext.js index 7fa4bd5..0442085 100644 --- a/src/contexts/ToastContext.js +++ b/src/contexts/ToastContext.js @@ -1,4 +1,5 @@ import React, { useReducer, useMemo, useCallback } from "react"; +import PropTypes from "prop-types"; import { toast } from "react-toastify"; import useStyles from "../components/Toast/styles"; import ToastContainer from "../components/Toast/ToastContainer"; @@ -137,6 +138,10 @@ const ToastProvider = ({ children }) => { ); }; +ToastProvider.propTypes = { + children: PropTypes.node +}; + const useToast = () => { const context = React.useContext(ToastDispatchContext); if (context === undefined) { diff --git a/src/contexts/UserContext.js b/src/contexts/UserContext.js index ac0bab0..47940f1 100644 --- a/src/contexts/UserContext.js +++ b/src/contexts/UserContext.js @@ -1,4 +1,5 @@ import React from "react"; +import PropTypes from "prop-types"; import { authenticate, invalidate, validateToken } from "../utils/identity"; var UserStateContext = React.createContext(); @@ -38,6 +39,10 @@ function UserProvider({ children }) { ); } +UserProvider.propTypes = { + children: PropTypes.node +}; + function useUserState() { var context = React.useContext(UserStateContext); if (context === undefined) { diff --git a/src/features/resources/edit/components/ResourcePreviewComponent.js b/src/features/resources/edit/components/ResourcePreviewComponent.js new file mode 100644 index 0000000..79329a3 --- /dev/null +++ b/src/features/resources/edit/components/ResourcePreviewComponent.js @@ -0,0 +1,3 @@ +const ResourcePreviewComponent = () => {}; + +export default ResourcePreviewComponent; diff --git a/src/features/resources/list/components/ActionButton.js b/src/features/resources/list/components/ActionButton.js index 89d2321..6c3b34d 100644 --- a/src/features/resources/list/components/ActionButton.js +++ b/src/features/resources/list/components/ActionButton.js @@ -1,4 +1,5 @@ import React, { forwardRef } from "react"; +import PropTypes from "prop-types"; import { IconButton, Tooltip } from "@material-ui/core"; const ActionButton = forwardRef((props, _ref) => { @@ -21,4 +22,9 @@ const ActionButton = forwardRef((props, _ref) => { ); }); +ActionButton.propTypes = { + action: PropTypes.object.isRequired, + resource: PropTypes.object.isRequired +}; + export default ActionButton; diff --git a/src/features/resources/list/components/SecondaryActionsGroup.js b/src/features/resources/list/components/SecondaryActionsGroup.js index 57848f2..110f359 100644 --- a/src/features/resources/list/components/SecondaryActionsGroup.js +++ b/src/features/resources/list/components/SecondaryActionsGroup.js @@ -1,4 +1,5 @@ import React, { useState } from "react"; +import PropTypes from "prop-types"; import { Menu } from "@material-ui/core"; import ActionButton from "./ActionButton"; import { MoreHorizOutlined } from "@material-ui/icons"; @@ -40,4 +41,9 @@ const SecondaryActionsGroup = ({ resource, actions }) => { ); }; +SecondaryActionsGroup.propTypes = { + resource: PropTypes.object.isRequired, + actions: PropTypes.array.isRequired +}; + export default SecondaryActionsGroup;