diff --git a/.eslintrc.json b/.eslintrc.json deleted file mode 100644 index 4d3fedac..00000000 --- a/.eslintrc.json +++ /dev/null @@ -1,49 +0,0 @@ -{ - "extends": ["next/core-web-vitals"], - "rules": { - "unused-imports/no-unused-imports": "error", - "no-empty-function": "error", - "object-shorthand": ["error", "always"], - "quotes": ["error", "single"], - "no-unused-vars": "error", - "semi": ["warn", "always"], - "indent": ["error", 2], - "comma-dangle": ["warn", "always-multiline"], - "prefer-const": "error", - "arrow-parens": ["error", "as-needed"], - "eol-last": ["error", "always"], - "react/display-name": "off", - "react/no-unknown-property": "off", - "react/prop-types": "off", - "jsx-quotes": ["error", "prefer-double"], - "react/self-closing-comp": [ - "error", - { - "component": true, - "html": true - } - ] - }, - "plugins": ["unused-imports"], - "settings": { - "react": { - "version": "detect" - } - }, - "overrides": [ - { - "files": ["src/**/*.js", "src/**/*.jsx"], - "plugins": ["headers"], - "rules": { - "headers/header-format": [ - "error", - { - "source": "string", - "content": "Copyright 2024 OpenBuild\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.", - "trailingNewlines": 2 - } - ] - } - } - ] -} diff --git a/eslint.config.mjs b/eslint.config.mjs new file mode 100644 index 00000000..0b415fae --- /dev/null +++ b/eslint.config.mjs @@ -0,0 +1,103 @@ +// @ts-check +import unusedImports from 'eslint-plugin-unused-imports'; +import pluginNext from '@next/eslint-plugin-next'; +import headers from 'eslint-plugin-headers'; +import globals from 'globals'; +import pluginReact from 'eslint-plugin-react'; +import pluginReactHooks from 'eslint-plugin-react-hooks'; +import gitignore from 'eslint-config-flat-gitignore'; + +export default [ + gitignore(), + { + name: 'eslint/javascript/rules', + languageOptions: { + ecmaVersion: 2022, + globals: { + ...globals.browser, + ...globals.es2021, + ...globals.node, + document: 'readonly', + navigator: 'readonly', + window: 'readonly', + }, + parserOptions: { + ecmaFeatures: { + jsx: true, + }, + ecmaVersion: 2022, + sourceType: 'module', + }, + sourceType: 'module', + }, + linterOptions: { + reportUnusedDisableDirectives: true, + }, + plugins: { + 'unused-imports': unusedImports, + }, + rules: { + 'unused-imports/no-unused-imports': 'warn', + 'unused-imports/no-unused-vars': [ + 'error', + { + args: 'after-used', + argsIgnorePattern: '^_', + vars: 'all', + varsIgnorePattern: '^_', + }, + ], + }, + }, + { + name: 'eslint/react/rules', + files: ['src/**/*.{js,jsx,ts,tsx}'], + settings: { + react: { + version: 'detect', + }, + }, + languageOptions: { + parserOptions: { + sourceType: 'module', + ecmaFeatures: { + jsx: true, + }, + }, + }, + plugins: { + react: pluginReact, + 'react-hooks': pluginReactHooks, + '@next/next': pluginNext, + }, + rules: { + ...pluginReact.configs.recommended.rules, + ...pluginReactHooks.configs.recommended.rules, + + 'react/display-name': 'off', + 'react/prop-types': 'off', + 'react/react-in-jsx-scope': 'off', + + ...pluginNext.configs.recommended.rules, + ...pluginNext.configs['core-web-vitals'].rules, + }, + }, + { + name: 'eslint/headers/rules', + files: ['src/**/*.{js,jsx,ts,tsx}'], + plugins: { + headers, + }, + rules: { + 'headers/header-format': [ + 'error', + { + source: 'string', + content: + 'Copyright 2024 OpenBuild\n\nLicensed under the Apache License, Version 2.0 (the "License");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an "AS IS" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.', + trailingNewlines: 2, + }, + ], + }, + }, +]; diff --git a/package.json b/package.json index 9f530b83..b2ccb4d2 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,7 @@ "analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build", "license": "node .knosys/scripts license add", "doc": "node .knosys/scripts site", - "lint": "eslint src --ext .js,.jsx,.ts,.tsx", + "lint": "eslint .", "prepare": "husky" }, "dependencies": { @@ -63,8 +63,6 @@ "daisyui": "^4.4.23", "dayjs": "^1.11.7", "easymde": "^2.18.0", - "eslint-plugin-react": "^7.31.11", - "eslint-plugin-unused-imports": "^3.0.0", "ethers": "^6.9.0", "file-saver": "^2.0.5", "framer-motion": "^10.16.4", @@ -122,7 +120,10 @@ "@astrojs/tailwind": "5.1.2", "@commitlint/cli": "19.6.1", "@commitlint/config-conventional": "19.6.0", + "@eslint/eslintrc": "^3.2.0", + "@eslint/js": "^9.19.0", "@knosys/sdk": "^0.0.3", + "@next/eslint-plugin-next": "^15.1.6", "@tailwindcss/line-clamp": "0.4.4", "@types/node": "18.11.3", "@types/qs": "^6.9.15", @@ -131,10 +132,15 @@ "@types/sha256": "^0.2.0", "astro": "4.16.7", "autoprefixer": "^10.4.12", - "eslint": "^8.7.0", + "eslint": "^9.19.0", + "eslint-config-flat-gitignore": "^1.0.0", "eslint-config-next": "^13.1.1", "eslint-plugin-headers": "1.2.1", + "eslint-plugin-react": "^7.37.4", + "eslint-plugin-react-hooks": "^5.1.0", "eslint-plugin-tailwindcss": "3.15.1", + "eslint-plugin-unused-imports": "^4.1.4", + "globals": "^15.14.0", "husky": "9.1.7", "ksio": "^0.0.3", "lint-staged": "15.3.0", diff --git a/src/app/(uc)/signin/VerifyCodeLogin.js b/src/app/(uc)/signin/VerifyCodeLogin.js index 26f782c0..c4738504 100644 --- a/src/app/(uc)/signin/VerifyCodeLogin.js +++ b/src/app/(uc)/signin/VerifyCodeLogin.js @@ -52,7 +52,7 @@ export default function VerifyCodeLogin({ register, loginType, email }) { } else { toast.error(res.message); } - } catch (error) { + } catch { toast.error('Failed to send code.'); } finally { setSendLoading(false); diff --git a/src/app/(uc)/signin/page.js b/src/app/(uc)/signin/page.js index 728ab898..6791cbea 100644 --- a/src/app/(uc)/signin/page.js +++ b/src/app/(uc)/signin/page.js @@ -97,7 +97,7 @@ export default function Login() { } else { toast.error(response.message); } - } catch (error) { + } catch { toast.error('Sign in failed. Please try again.'); } finally { setLoading(false); diff --git a/src/app/bounties/Tips.js b/src/app/bounties/Tips.js index dfdc4500..9ffd4ab5 100644 --- a/src/app/bounties/Tips.js +++ b/src/app/bounties/Tips.js @@ -24,7 +24,7 @@ import { useBoundWallet } from '@/hooks/useBoundWallet'; function TipsContainer({children}) { return
- + diff --git a/src/app/bounties/[id]/actions.js b/src/app/bounties/[id]/actions.js index 93019bd1..8b068cd6 100644 --- a/src/app/bounties/[id]/actions.js +++ b/src/app/bounties/[id]/actions.js @@ -27,7 +27,7 @@ export async function applyAction(id, comment) { } else { return res; } - } catch (e) { + } catch { return { message: 'Failed to request' }; } } diff --git a/src/app/learn/[type]/[id]/[chapter_id]/Menu.js b/src/app/learn/[type]/[id]/[chapter_id]/Menu.js index c7facb6f..a53da1b8 100644 --- a/src/app/learn/[type]/[id]/[chapter_id]/Menu.js +++ b/src/app/learn/[type]/[id]/[chapter_id]/Menu.js @@ -14,7 +14,6 @@ * limitations under the License. */ -/* eslint-disable jsx-a11y/anchor-is-valid */ 'use client'; import { useEffect, useState } from 'react'; diff --git a/src/app/learn/[type]/[id]/actions.js b/src/app/learn/[type]/[id]/actions.js index e2e9a173..ba23bbd6 100644 --- a/src/app/learn/[type]/[id]/actions.js +++ b/src/app/learn/[type]/[id]/actions.js @@ -27,7 +27,7 @@ export async function enrollAction(id) { } else { return res; } - } catch (e) { + } catch { return { message: 'Failed to request' }; } } @@ -45,7 +45,7 @@ export async function growPathEnrollAction(id) { } else { return res; } - } catch (e) { + } catch { return { message: 'Failed to request' }; } } diff --git a/src/domain/quiz/views/quiz-question-list/AnswerRecordDrawer.js b/src/domain/quiz/views/quiz-question-list/AnswerRecordDrawer.js index ada0df09..31c7e410 100644 --- a/src/domain/quiz/views/quiz-question-list/AnswerRecordDrawer.js +++ b/src/domain/quiz/views/quiz-question-list/AnswerRecordDrawer.js @@ -45,7 +45,7 @@ function AnswerRecordDrawer({ questions = [], result, submitting, onSubmit, onCh
-