|
| 1 | +import js from "@eslint/js"; |
| 2 | +import importPlugin from "eslint-plugin-import"; |
| 3 | +import jestPlugin from "eslint-plugin-jest"; |
| 4 | +import jestDomPlugin from "eslint-plugin-jest-dom"; |
| 5 | +import reactPlugin from "eslint-plugin-react"; |
| 6 | +import reactHooksPlugin from "eslint-plugin-react-hooks"; |
| 7 | +import testingLibraryPlugin from "eslint-plugin-testing-library"; |
| 8 | +import { defineConfig } from "eslint/config"; |
| 9 | +import tseslint from "typescript-eslint"; |
| 10 | + |
| 11 | +export default defineConfig([ |
| 12 | + { |
| 13 | + name: "global ignores", |
| 14 | + ignores: ["dist"], |
| 15 | + }, |
| 16 | + { |
| 17 | + files: [`**/*.{js,cjs,mjs,ts,tsx,mts}`], |
| 18 | + }, |
| 19 | + js.configs.recommended, |
| 20 | + tseslint.configs.recommended, |
| 21 | + reactPlugin.configs.flat.recommended, |
| 22 | + reactHooksPlugin.configs.flat.recommended, |
| 23 | + { |
| 24 | + plugins: { |
| 25 | + import: importPlugin, |
| 26 | + }, |
| 27 | + }, |
| 28 | + { |
| 29 | + languageOptions: { |
| 30 | + parserOptions: { |
| 31 | + project: ["./tsconfig-eslint.json"], |
| 32 | + }, |
| 33 | + }, |
| 34 | + settings: { |
| 35 | + react: { |
| 36 | + version: "detect", |
| 37 | + }, |
| 38 | + }, |
| 39 | + }, |
| 40 | + { |
| 41 | + rules: { |
| 42 | + complexity: "error", |
| 43 | + curly: "error", |
| 44 | + eqeqeq: ["error", "smart"], |
| 45 | + "no-alert": "error", |
| 46 | + "no-console": "error", |
| 47 | + "no-prototype-builtins": "off", |
| 48 | + "no-unused-vars": "off", |
| 49 | + "no-process-env": "error", |
| 50 | + |
| 51 | + /* typescript-eslint rules */ |
| 52 | + "@typescript-eslint/adjacent-overload-signatures": "off", |
| 53 | + "@typescript-eslint/no-restricted-types": [ |
| 54 | + "error", |
| 55 | + { |
| 56 | + types: { |
| 57 | + IStringTMap: "Prefer Record<string, T>", |
| 58 | + }, |
| 59 | + }, |
| 60 | + ], |
| 61 | + "@typescript-eslint/camelcase": "off", |
| 62 | + "@typescript-eslint/explicit-function-return-type": "off", |
| 63 | + "@typescript-eslint/explicit-member-accessibility": [ |
| 64 | + "error", |
| 65 | + { |
| 66 | + accessibility: "no-public", |
| 67 | + overrides: { parameterProperties: "explicit" }, |
| 68 | + }, |
| 69 | + ], |
| 70 | + "@typescript-eslint/explicit-module-boundary-types": "off", |
| 71 | + "@typescript-eslint/interface-name-prefix": "off", |
| 72 | + "@typescript-eslint/no-empty-function": "off", |
| 73 | + "@typescript-eslint/no-explicit-any": "off", |
| 74 | + "@typescript-eslint/no-inferrable-types": "off", |
| 75 | + "@typescript-eslint/no-namespace": "off", |
| 76 | + "@typescript-eslint/no-non-null-assertion": "off", |
| 77 | + "@typescript-eslint/only-throw-error": "error", |
| 78 | + "@typescript-eslint/no-use-before-define": "off", |
| 79 | + "@typescript-eslint/no-unused-expressions": [ |
| 80 | + "error", |
| 81 | + { |
| 82 | + allowShortCircuit: true, |
| 83 | + allowTernary: true, |
| 84 | + allowTaggedTemplates: true, |
| 85 | + enforceForJSX: true, |
| 86 | + }, |
| 87 | + ], |
| 88 | + "@typescript-eslint/no-unused-vars": [ |
| 89 | + "error", |
| 90 | + { |
| 91 | + argsIgnorePattern: "^_", |
| 92 | + ignoreRestSiblings: true, |
| 93 | + }, |
| 94 | + ], |
| 95 | + "@typescript-eslint/no-var-requires": "off", |
| 96 | + |
| 97 | + /* react rules */ |
| 98 | + "react/display-name": "off", |
| 99 | + "react/jsx-curly-brace-presence": ["error", { props: "never" }], |
| 100 | + "react/no-deprecated": "warn", |
| 101 | + "react/no-unescaped-entities": ["error", { forbid: [">", "}"] }], |
| 102 | + "react/prop-types": "off", |
| 103 | + "react/no-danger": "error", |
| 104 | + "react/self-closing-comp": "error", |
| 105 | + "react/function-component-definition": [ |
| 106 | + "error", |
| 107 | + { |
| 108 | + namedComponents: "arrow-function", |
| 109 | + }, |
| 110 | + ], |
| 111 | + |
| 112 | + /* import rules */ |
| 113 | + "import/no-unassigned-import": "error", |
| 114 | + "import/order": "off", // Use prettier for import order formatting |
| 115 | + }, |
| 116 | + }, |
| 117 | + { |
| 118 | + files: ["**/?(*.)+(test).ts?(x)"], |
| 119 | + extends: [ |
| 120 | + jestPlugin.configs["flat/recommended"], |
| 121 | + jestPlugin.configs["flat/style"], |
| 122 | + ], |
| 123 | + rules: { |
| 124 | + "jest/expect-expect": [ |
| 125 | + "warn", |
| 126 | + { |
| 127 | + assertFunctionNames: ["expect*"], |
| 128 | + additionalTestBlockFunctions: [], |
| 129 | + }, |
| 130 | + ], |
| 131 | + "jest/no-standalone-expect": [ |
| 132 | + "error", |
| 133 | + { additionalTestBlockFunctions: ["afterEach"] }, |
| 134 | + ], |
| 135 | + }, |
| 136 | + }, |
| 137 | + { |
| 138 | + files: ["test/**/*"], |
| 139 | + languageOptions: { |
| 140 | + globals: jestPlugin.environments.globals.globals, |
| 141 | + }, |
| 142 | + rules: { |
| 143 | + "no-undef": "off", |
| 144 | + "@typescript-eslint/no-unused-expressions": "off", |
| 145 | + "react/jsx-curly-brace-presence": "off", |
| 146 | + }, |
| 147 | + }, |
| 148 | + { |
| 149 | + files: ["**/?(*.)+(test).tsx"], |
| 150 | + extends: [ |
| 151 | + testingLibraryPlugin.configs["flat/react"], |
| 152 | + jestDomPlugin.configs["flat/recommended"], |
| 153 | + ], |
| 154 | + rules: { |
| 155 | + "testing-library/prefer-user-event": "error", |
| 156 | + }, |
| 157 | + }, |
| 158 | + { |
| 159 | + files: ["src/mjml/*"], |
| 160 | + rules: { |
| 161 | + "react/function-component-definition": "off", |
| 162 | + }, |
| 163 | + }, |
| 164 | +]); |
0 commit comments