|
| 1 | +import js from "@eslint/js"; |
| 2 | +import { FlatCompat } from "@eslint/eslintrc"; |
| 3 | +import prettierPlugin from "eslint-plugin-prettier"; |
| 4 | + |
| 5 | +const compat = new FlatCompat({ |
| 6 | + baseDirectory: import.meta.dirname, |
| 7 | + recommendedConfig: js.configs.recommended, |
| 8 | +}); |
| 9 | + |
| 10 | +const eslintConfig = [ |
| 11 | + // Base JavaScript recommendations |
| 12 | + js.configs.recommended, |
| 13 | + |
| 14 | + ...compat.config({ |
| 15 | + extends: ["next/core-web-vitals", "next/typescript"], |
| 16 | + }), |
| 17 | + |
| 18 | + { |
| 19 | + files: ["**/*.{js,jsx,ts,tsx}"], |
| 20 | + plugins: { |
| 21 | + prettier: prettierPlugin, |
| 22 | + }, |
| 23 | + rules: { |
| 24 | + "prettier/prettier": [ |
| 25 | + "error", |
| 26 | + { |
| 27 | + tabWidth: 2, |
| 28 | + semi: true, |
| 29 | + endOfLine: "auto", |
| 30 | + singleQuote: false, |
| 31 | + trailingComma: "es5", |
| 32 | + }, |
| 33 | + ], |
| 34 | + "@typescript-eslint/ban-types": "off", |
| 35 | + "@typescript-eslint/no-namespace": "off", |
| 36 | + "array-callback-return": "error", |
| 37 | + eqeqeq: "error", |
| 38 | + "no-alert": "error", |
| 39 | + "no-return-assign": "error", |
| 40 | + "no-restricted-syntax": [ |
| 41 | + "error", |
| 42 | + { |
| 43 | + selector: |
| 44 | + "CallExpression[callee.property.name=required][callee.object.callee.property.name=nullable]", |
| 45 | + message: |
| 46 | + ".nullable() should be after .required() for correct validation and type inference. Example: id: yup.string().required().nullable()", |
| 47 | + }, |
| 48 | + { |
| 49 | + selector: |
| 50 | + "CallExpression[callee.name=watch], MemberExpression[object.name=methods][property.name=watch]", |
| 51 | + message: |
| 52 | + '"watch" re-render the whole form component. Use hook "useWatch" instead.', |
| 53 | + }, |
| 54 | + { |
| 55 | + selector: |
| 56 | + "VariableDeclarator > ObjectPattern > Property[key.name=formState]", |
| 57 | + message: |
| 58 | + '"formState" re-render the whole form component. Use hook "useFormState" instead.', |
| 59 | + }, |
| 60 | + { |
| 61 | + selector: "MemberExpression[object.name=React][property.name=/^use/]", |
| 62 | + message: |
| 63 | + 'Use hooks without "React" prefix. For avoid using both import styles. Example: "useEffect" instead of "React.useEffect".', |
| 64 | + }, |
| 65 | + { |
| 66 | + selector: |
| 67 | + "ConditionalExpression[consequent.type=Literal][consequent.value=true][alternate.type=Literal][alternate.value=false]", |
| 68 | + message: |
| 69 | + 'Do not use "condition ? true : false". Simplify "someVariable === 42 ? true : false " to "someVariable === 42"', |
| 70 | + }, |
| 71 | + ], |
| 72 | + "no-restricted-imports": [ |
| 73 | + "error", |
| 74 | + { |
| 75 | + paths: [ |
| 76 | + { |
| 77 | + name: "@mui/material", |
| 78 | + message: |
| 79 | + "Please use \"import ComponentName from '@mui/material/ComponentName'\" instead.", |
| 80 | + }, |
| 81 | + { |
| 82 | + name: "@mui/icons-material", |
| 83 | + message: |
| 84 | + "Please use \"import IconName from '@mui/icons-material/IconName'\" instead.", |
| 85 | + }, |
| 86 | + { |
| 87 | + name: "next/link", |
| 88 | + message: |
| 89 | + 'Please use "import Link from "@/components/link"" instead. This is need for "leave page" logic', |
| 90 | + }, |
| 91 | + ], |
| 92 | + }, |
| 93 | + ], |
| 94 | + }, |
| 95 | + }, |
| 96 | + { |
| 97 | + ignores: [ |
| 98 | + "node_modules/**", |
| 99 | + ".next/**", |
| 100 | + "out/**", |
| 101 | + "build/**", |
| 102 | + "dist/**", |
| 103 | + "playwright-report/**", |
| 104 | + "test-results/**", |
| 105 | + "*.config.js", |
| 106 | + "*.config.mjs", |
| 107 | + "next-env.d.ts", |
| 108 | + ], |
| 109 | + }, |
| 110 | +]; |
| 111 | + |
| 112 | +export default eslintConfig; |
0 commit comments