From 2308ea9df936f7425530b5686dc53134e7352ec4 Mon Sep 17 00:00:00 2001 From: dappsar Date: Sat, 20 Jul 2024 11:55:28 -0300 Subject: [PATCH 1/4] [feat] :rotating_light: fix linter errors (#377) --- .eslintrc | 174 +++++++++- src/components/CustomImage/CustomImage.jsx | 2 +- src/components/FlipBook/FlipBook.jsx | 13 +- src/components/FlipBook/HtmlFlipBook.jsx | 10 +- src/components/Footer/Footer.jsx | 14 +- src/components/Footer/FooterButtons.jsx | 17 +- .../LanguageSelection/LanguageSelection.jsx | 93 +++--- src/components/Layout/Layout.jsx | 5 +- src/components/Navbar/AccountInfo.jsx | 38 ++- src/components/Navbar/Navbar.jsx | 30 +- src/components/Navbar/NofTown.jsx | 2 +- src/components/Navbar/NotificationInfo.jsx | 10 +- src/components/Navbar/Whitepaper.jsx | 2 +- src/context/GammaDataContext.js | 15 +- src/context/LayoutContext.js | 4 +- src/context/NotificationContext.js | 2 +- src/context/SettingsContext.js | 15 +- src/context/Web3Context.js | 23 +- src/hooks/index.js | 6 +- src/hooks/useGammaDataContext.js | 1 + src/hooks/useLayoutContext.js | 1 + src/hooks/useNotificationContext.js | 1 + src/hooks/useSettingsContext.js | 1 + src/hooks/useWeb3Context.js | 1 + src/pages/_app.jsx | 11 +- src/pages/_offline.jsx | 1 + src/pages/admin.jsx | 5 +- src/pages/alpha.jsx | 1 + src/pages/api/characters.js | 37 ++- src/pages/api/info.js | 14 +- src/pages/api/mail/common.js | 17 +- src/pages/api/mail/e.js | 2 +- src/pages/api/missing.js | 17 +- src/pages/api/newCharacter.js | 3 +- src/pages/api/post.js | 5 +- src/pages/api/rank.js | 20 +- src/pages/api/vote.js | 7 +- src/pages/gamma.jsx | 1 + src/pages/index.jsx | 1 + src/sections/Alpha/AlphaAlbums.jsx | 20 +- src/sections/Alpha/AlphaMain.jsx | 111 +++---- src/sections/Common/Rules.jsx | 5 +- src/sections/Gamma/GammaAlbum.jsx | 17 +- src/sections/Gamma/GammaAlbumInfo.jsx | 16 +- src/sections/Gamma/GammaAlbumPublish.jsx | 37 +-- src/sections/Gamma/GammaCardExchange.jsx | 25 +- src/sections/Gamma/GammaCardInfo.jsx | 34 +- src/sections/Gamma/GammaCardOffers.jsx | 25 +- src/sections/Gamma/GammaMain.jsx | 300 ++++++++---------- src/sections/Gamma/GammaPackOpen.jsx | 107 +++---- src/sections/Gamma/GammaPackOpenCards.jsx | 7 +- src/sections/Gamma/index.jsx | 4 +- src/sections/Main/Main.jsx | 193 ++++++----- src/sections/Offline/OfflineMain.jsx | 2 +- src/services/alpha.js | 37 +-- src/services/gamma.js | 147 +++++---- src/services/handleVersion.js | 3 +- src/services/middleware.js | 37 ++- src/services/offers.js | 9 +- src/utils/alert.js | 8 +- 60 files changed, 926 insertions(+), 840 deletions(-) diff --git a/.eslintrc b/.eslintrc index 30cd6529..a8b484a9 100644 --- a/.eslintrc +++ b/.eslintrc @@ -1,25 +1,177 @@ { + "root": true, "env": { "browser": true, "es2021": true }, + "plugins": [ + "perfectionist", + "unused-imports", + "prettier", + "react", + "@next/eslint-plugin-next" + // "react", + // "@next/eslint-plugin-next" + ], "extends": [ // "eslint:recommended", // "plugin:react/recommended", // "plugin:@next/next/recommended", // "prettier" + "airbnb", + "airbnb/hooks", + "prettier", + "plugin:react/recommended", + "plugin:@next/next/recommended" ], "parserOptions": { - "ecmaFeatures": { + "ecmaVersion": 12, + "sourceType": "module", + "ecmaFeatures": { "jsx": true }, - "ecmaVersion": 12, - "sourceType": "module" }, - "plugins": [ - "react", - // "@next/eslint-plugin-next" - ], + "settings": { + "import/resolver": { + "node": { + "extensions": [".js", ".jsx", ".ts", ".tsx", ".css"] + } + } + }, + "rules": { + "no-alert": 0, + "camelcase": 0, + "no-console": 0, + "no-unused-vars": [ + "off", + { + "ignoreRestSiblings": true + } + ], + "no-param-reassign": 0, + "no-underscore-dangle": 0, + "no-restricted-exports": 0, + "react/no-children-prop": 0, + "consistent-return": 0, + "react/react-in-jsx-scope": 0, + "jsx-a11y/anchor-is-valid": 0, + "react/no-array-index-key": 0, + "no-promise-executor-return": 0, + "react/require-default-props": 0, + "react/jsx-props-no-spreading": 0, + "react/display-name": 0, + "import/prefer-default-export": 0, + "react/function-component-definition": 0, + "jsx-a11y/control-has-associated-label": 0, + "react/forbid-prop-types": 0, + "no-plusplus": 0, + "no-use-before-define": 0, + "react/jsx-no-useless-fragment": [ + 1, + { + "allowExpressions": true + } + ], + "prefer-destructuring": [ + 1, + { + "object": true, + "array": false + } + ], + "react/no-unstable-nested-components": [ + 1, + { + "allowAsProps": true + } + ], + "react/jsx-no-duplicate-props": [ + 1, + { + "ignoreCase": false + } + ], + // unused-imports + // https://www.npmjs.com/package/eslint-plugin-unused-imports + "unused-imports/no-unused-imports": 1, + "unused-imports/no-unused-vars": [ + 0, + { + "vars": "all", + "varsIgnorePattern": "^_", + "args": "after-used", + "argsIgnorePattern": "^_" + } + ], + // perfectionist + // https://eslint-plugin-perfectionist.azat.io/ + "perfectionist/sort-named-imports": [ + 1, + { + "order": "asc", + "type": "line-length" + } + ], + "perfectionist/sort-named-exports": [ + 1, + { + "order": "asc", + "type": "line-length" + } + ], + "perfectionist/sort-exports": [ + 1, + { + "order": "asc", + "type": "line-length" + } + ], + "perfectionist/sort-imports": [ + 1, + { + "order": "asc", + "type": "line-length", + "newlines-between": "always", + "groups": [ + [ + "builtin", + "external" + ], + "custom-context", + "custom-services", + "custom-hooks", + "custom-utils", + "internal", + "custom-components", + "custom-sections", + "custom-styles", + [ + "parent", + "sibling", + "index" + ], + "object", + "unknown" + ], + "custom-groups": { + "value": { + "custom-context": "src/context/**", + "custom-services": "src/services/**", + "custom-hooks": "src/hooks/**", + "custom-utils": "src/utils/**", + "custom-components": "src/components/**", + "custom-sections": "src/sections/**", + "custom-styles": "src/styles/**" + } + }, + "internal-pattern": [ + "src/**" + ] + } + ] + } + + /* "rules": { "arrow-body-style": 1, "react/prop-types": 1, @@ -31,6 +183,12 @@ "@next/next/no-img-element": 0, "react/no-unescaped-entities": 0, "import/no-useless-path-segments": 1, - "no-unused-vars": 0 + "no-unused-vars": [ + 1, + { + "ignoreRestSiblings": false + } + ] } + */ } diff --git a/src/components/CustomImage/CustomImage.jsx b/src/components/CustomImage/CustomImage.jsx index 302cd0f0..a1e111cf 100644 --- a/src/components/CustomImage/CustomImage.jsx +++ b/src/components/CustomImage/CustomImage.jsx @@ -1,5 +1,5 @@ -import React, { useState } from 'react' import PropTypes from 'prop-types' +import React, { useState } from 'react' function CustomImage({ src, alt, className }) { const [error, setError] = useState(false) diff --git a/src/components/FlipBook/FlipBook.jsx b/src/components/FlipBook/FlipBook.jsx index 7ef3dd88..7bc594f9 100644 --- a/src/components/FlipBook/FlipBook.jsx +++ b/src/components/FlipBook/FlipBook.jsx @@ -1,5 +1,6 @@ -import React, { useEffect, useState } from 'react' import PropTypes from 'prop-types' +import React, { useState, useEffect } from 'react' + import HTMLFlipBook from './HtmlFlipBook' import { useLayoutContext } from '../../hooks' @@ -48,8 +49,8 @@ const FlipBook = (props) => { minHeight={350} maxHeight={600} swipeDistance={30} - showPageCorners={true} - autoSize={true} + showPageCorners + autoSize startPage={startPage} ref={bookRef} usePortrait={windowSize.size} @@ -74,12 +75,12 @@ const FlipBook = (props) => { >
{index % 2 === 0 ? ( - {content} + <>{content} ) : ( - + <> {showClose && } {content} - + )}
diff --git a/src/components/FlipBook/HtmlFlipBook.jsx b/src/components/FlipBook/HtmlFlipBook.jsx index 495d0153..e5054c78 100644 --- a/src/components/FlipBook/HtmlFlipBook.jsx +++ b/src/components/FlipBook/HtmlFlipBook.jsx @@ -1,7 +1,7 @@ -import React, { useCallback, useEffect, useImperativeHandle, useRef, useState } from 'react' import PropTypes from 'prop-types' // import { PageFlip } from 'page-flip' import { PageFlip } from 'book-flip' +import React, { useRef, useState, useEffect, useCallback, useImperativeHandle } from 'react' const HTMLFlipBookForward = React.forwardRef((props, ref) => { const htmlElementRef = useRef(null) @@ -17,7 +17,7 @@ const HTMLFlipBookForward = React.forwardRef((props, ref) => { if (pageFlip.current) { pageFlip.current.clear() } - }, []) //eslint-disable-line react-hooks/exhaustive-deps + }, []) // eslint-disable-line react-hooks/exhaustive-deps const removeHandlers = useCallback(() => { const flip = pageFlip.current @@ -29,7 +29,7 @@ const HTMLFlipBookForward = React.forwardRef((props, ref) => { flip.off('init') flip.off('update') } - }, []) //eslint-disable-line react-hooks/exhaustive-deps + }, []) // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { childRef.current = [] @@ -54,7 +54,7 @@ const HTMLFlipBookForward = React.forwardRef((props, ref) => { } } removeHandlers() - }, [props.children]) //eslint-disable-line react-hooks/exhaustive-deps + }, [props.children]) // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { const setHandlers = () => { @@ -98,7 +98,7 @@ const HTMLFlipBookForward = React.forwardRef((props, ref) => { setHandlers() } - }, [pages]) //eslint-disable-line react-hooks/exhaustive-deps + }, [pages]) // eslint-disable-line react-hooks/exhaustive-deps return (
diff --git a/src/components/Footer/Footer.jsx b/src/components/Footer/Footer.jsx index 0fc760cf..57ca0f8a 100644 --- a/src/components/Footer/Footer.jsx +++ b/src/components/Footer/Footer.jsx @@ -1,7 +1,7 @@ import React from 'react' -import { useLayoutContext } from '../../hooks' import FooterButtons from './FooterButtons' +import { useLayoutContext } from '../../hooks' function Footer() { const { mobile, turnNextPage, turnPrevPage } = useLayoutContext() @@ -14,20 +14,14 @@ function Footer() {
{!mobile && ( <> -
- <> -
-
- <> -
+
+
)} {!mobile && ( <> -
- <> -
+

Number One Fan &
diff --git a/src/components/Footer/FooterButtons.jsx b/src/components/Footer/FooterButtons.jsx index 7b260aff..5fd482d2 100644 --- a/src/components/Footer/FooterButtons.jsx +++ b/src/components/Footer/FooterButtons.jsx @@ -1,5 +1,6 @@ import React from 'react' import Link from 'next/link' + import { useLayoutContext } from '../../hooks' function FooterButtons() { @@ -45,9 +46,7 @@ function FooterButtons() { className={ (footerButtonsClasses && footerButtonsClasses[0]) ?? 'footer__buttons__bluebtn_custom' } - > - <> -

+ /> )} {showButtons[1] && buttonFunctions && buttonFunctions[1] && (
- <> -
+ /> )} {showButtons[2] && buttonFunctions && buttonFunctions[2] && (
- <> -
+ /> )} {showButtons[3] && buttonFunctions && buttonFunctions[3] && (
- <> -
+ /> )}
) diff --git a/src/components/LanguageSelection/LanguageSelection.jsx b/src/components/LanguageSelection/LanguageSelection.jsx index c84329fb..d5a9cd44 100644 --- a/src/components/LanguageSelection/LanguageSelection.jsx +++ b/src/components/LanguageSelection/LanguageSelection.jsx @@ -1,5 +1,6 @@ -import React, { useState } from 'react' import Image from 'next/image' +import React, { useState } from 'react' + import { useSettingsContext } from '../../hooks' function LanguageSelection() { @@ -35,52 +36,50 @@ function LanguageSelection() { } return ( - <> -
- - {dropdownOpen && ( -
-
    -
  • - -
  • -
  • - -
  • -
  • - -
  • -
-
- )} -
- +
+ + {dropdownOpen && ( +
+
    +
  • + +
  • +
  • + +
  • +
  • + +
  • +
+
+ )} +
) } diff --git a/src/components/Layout/Layout.jsx b/src/components/Layout/Layout.jsx index 569cbcf4..50ea283c 100644 --- a/src/components/Layout/Layout.jsx +++ b/src/components/Layout/Layout.jsx @@ -1,10 +1,11 @@ import React from 'react' import PropTypes from 'prop-types' -import { useLayoutContext } from '../../hooks' -import Loading from '../Loading' + import NofHead from '../Head' import Navbar from '../Navbar' import Footer from '../Footer' +import Loading from '../Loading' +import { useLayoutContext } from '../../hooks' const Layout = ({ children }) => { const { loading } = useLayoutContext() diff --git a/src/components/Navbar/AccountInfo.jsx b/src/components/Navbar/AccountInfo.jsx index 74ee0b05..4dc58e8d 100644 --- a/src/components/Navbar/AccountInfo.jsx +++ b/src/components/Navbar/AccountInfo.jsx @@ -1,17 +1,17 @@ -import React, { useState, useEffect, useCallback } from 'react' -import PropTypes from 'prop-types' import Link from 'next/link' -import { useTranslation } from 'next-i18next' import Swal from 'sweetalert2' -import { HiOutlineClipboardDocument } from 'react-icons/hi2' +import PropTypes from 'prop-types' +import { useTranslation } from 'next-i18next' import { GoLinkExternal } from 'react-icons/go' +import { HiOutlineClipboardDocument } from 'react-icons/hi2' import { AiOutlineSend, AiOutlineBank } from 'react-icons/ai' +import React, { useState, useEffect, useCallback } from 'react' import { useWeb3Context, useLayoutContext } from '../../hooks' -import { getBalance, getTokenName, transfer, mintDai } from '../../services/dai' -import { emitError, emitInfo, emitSuccess } from '../../utils/alert' -import { checkInputAddress, checkFloatValue1GTValue2 } from '../../utils/InputValidators' import { getAccountAddressText } from '../../utils/stringUtils' +import { emitInfo, emitError, emitSuccess } from '../../utils/alert' +import { mintDai, transfer, getBalance, getTokenName } from '../../services/dai' +import { checkInputAddress, checkFloatValue1GTValue2 } from '../../utils/InputValidators' const AccountInfo = ({ showAccountInfo, setShowAccountInfo }) => { const { t } = useTranslation() @@ -55,11 +55,11 @@ const AccountInfo = ({ showAccountInfo, setShowAccountInfo }) => { useEffect(() => { fetchTokenName() - }, [walletAddress, daiContract, isValidNetwork]) //eslint-disable-line react-hooks/exhaustive-deps + }, [walletAddress, daiContract, isValidNetwork]) // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { fetchBalance() - }, [walletBalance, walletAddress, isValidNetwork]) //eslint-disable-line react-hooks/exhaustive-deps + }, [walletBalance, walletAddress, isValidNetwork]) // eslint-disable-line react-hooks/exhaustive-deps function copyToClipboard(text) { navigator.clipboard.writeText(text) @@ -101,13 +101,11 @@ const AccountInfo = ({ showAccountInfo, setShowAccountInfo }) => { if (isNaN(amount)) { amountInput.classList.add('swal2-inputerror') Swal.showValidationMessage(`${t('amount_invalid')}`) - } else { - if (isNaN(amount)) { - amountInput.classList.add('swal2-inputerror') - Swal.showValidationMessage(`${t('amount_invalid')}`) - } + } else if (isNaN(amount)) { + amountInput.classList.add('swal2-inputerror') + Swal.showValidationMessage(`${t('amount_invalid')}`) } - return { amount: amount } + return { amount } } }) @@ -174,7 +172,7 @@ const AccountInfo = ({ showAccountInfo, setShowAccountInfo }) => { Swal.showValidationMessage(`${t('quantity_invalid')}`) } } - return { wallet: wallet, amount: amount } + return { wallet, amount } } }) @@ -295,22 +293,22 @@ const AccountInfo = ({ showAccountInfo, setShowAccountInfo }) => { return (
{isConnected ? ( - + <>
{isValidNetwork && ( - + <>
-
+ )}

-
+ ) : (
diff --git a/src/components/Navbar/Navbar.jsx b/src/components/Navbar/Navbar.jsx index 97b11f81..0dee931c 100644 --- a/src/components/Navbar/Navbar.jsx +++ b/src/components/Navbar/Navbar.jsx @@ -1,16 +1,16 @@ -import React, { useRef, useEffect, useState } from 'react' import Link from 'next/link' import Image from 'next/image' -import { useTranslation } from 'next-i18next' import { useRouter } from 'next/router' +import { useTranslation } from 'next-i18next' +import React, { useRef, useState, useEffect } from 'react' -import Whitepaper from './Whitepaper.jsx' import NofTown from './NofTown.jsx' +import Whitepaper from './Whitepaper.jsx' import AccountInfo from './AccountInfo.jsx' -import NotificationInfo from './NotificationInfo.jsx' import LanguageSelection from '../LanguageSelection' -import { useLayoutContext, useWeb3Context, useNotificationContext } from '../../hooks' +import NotificationInfo from './NotificationInfo.jsx' import { getProductVersion } from '../../services/handleVersion.js' +import { useWeb3Context, useLayoutContext, useNotificationContext } from '../../hooks' function Navbar() { const { t } = useTranslation() @@ -74,7 +74,7 @@ function Navbar() { useEffect(() => { fetchVersion().then(setProductVersion) - }, [productVersion]) //eslint-disable-line react-hooks/exhaustive-deps + }, [productVersion]) // eslint-disable-line react-hooks/exhaustive-deps useEffect(() => { document.addEventListener('mousedown', handleClickOutside) @@ -97,7 +97,7 @@ function Navbar() { const ButtonNof = () => (
handleAudioClick()} className='navbar__left__nof'> - nof + nof {productVersion}
@@ -115,17 +115,15 @@ function Navbar() { ) const ButtonNotification = () => ( - -
handleNotificationClick()} className='navbar__right__notif'> - {notificationsNbr > 0 &&
{notificationsNbr}
} - coin -
-
+
handleNotificationClick()} className='navbar__right__notif'> + {notificationsNbr > 0 &&
{notificationsNbr}
} + coin +
) const ButtonAccount = () => (
handleAccountClick()} className='navbar__right__account'> - coin + coin
) @@ -136,7 +134,7 @@ function Navbar() {
    -
  • +
  • {isHomePage && } @@ -161,7 +159,7 @@ function Navbar() {
-