|
| 1 | +import typescriptEslint from "@typescript-eslint/eslint-plugin"; |
| 2 | +import _import from "eslint-plugin-import"; |
| 3 | +import localRules from "eslint-plugin-local-rules"; |
| 4 | +import { fixupPluginRules, fixupConfigRules } from "@eslint/compat"; |
| 5 | +import globals from "globals"; |
| 6 | +import tsParser from "@typescript-eslint/parser"; |
| 7 | +import reactCompiler from "eslint-plugin-react-compiler"; |
| 8 | +import path from "node:path"; |
| 9 | +import { fileURLToPath } from "node:url"; |
| 10 | +import js from "@eslint/js"; |
| 11 | +import { FlatCompat } from "@eslint/eslintrc"; |
| 12 | + |
| 13 | +const __filename = fileURLToPath(import.meta.url); |
| 14 | +const __dirname = path.dirname(__filename); |
| 15 | +const compat = new FlatCompat({ |
| 16 | + baseDirectory: __dirname, |
| 17 | + recommendedConfig: js.configs.recommended, |
| 18 | + allConfig: js.configs.all, |
| 19 | +}); |
| 20 | + |
| 21 | +export default [ |
| 22 | + { |
| 23 | + plugins: { |
| 24 | + "@typescript-eslint": typescriptEslint, |
| 25 | + import: fixupPluginRules(_import), |
| 26 | + "local-rules": localRules, |
| 27 | + }, |
| 28 | + |
| 29 | + languageOptions: { |
| 30 | + globals: { |
| 31 | + ...globals.browser, |
| 32 | + ...globals.node, |
| 33 | + }, |
| 34 | + |
| 35 | + parser: tsParser, |
| 36 | + ecmaVersion: "latest", |
| 37 | + sourceType: "commonjs", |
| 38 | + }, |
| 39 | + |
| 40 | + settings: { |
| 41 | + "import/parsers": { |
| 42 | + "@typescript-eslint/parser": [".ts", ".tsx"], |
| 43 | + }, |
| 44 | + |
| 45 | + "import/resolver": { |
| 46 | + typescript: { |
| 47 | + alwaysTryTypes: true, |
| 48 | + }, |
| 49 | + }, |
| 50 | + }, |
| 51 | + |
| 52 | + rules: { |
| 53 | + "import/no-unresolved": "error", |
| 54 | + }, |
| 55 | + }, |
| 56 | + ...fixupConfigRules(compat.extends("plugin:react-hooks/recommended")).map( |
| 57 | + (config) => ({ |
| 58 | + ...config, |
| 59 | + files: ["**/*.ts", "**/*.tsx"], |
| 60 | + ignores: ["**/__tests__/**/*.*", "**/*.d.ts"], |
| 61 | + }) |
| 62 | + ), |
| 63 | + { |
| 64 | + files: ["**/*.ts", "**/*.tsx"], |
| 65 | + ignores: ["**/__tests__/**/*.*", "**/*.d.ts"], |
| 66 | + |
| 67 | + plugins: { |
| 68 | + "react-compiler": reactCompiler, |
| 69 | + }, |
| 70 | + |
| 71 | + languageOptions: { |
| 72 | + ecmaVersion: 5, |
| 73 | + sourceType: "script", |
| 74 | + |
| 75 | + parserOptions: { |
| 76 | + project: [ |
| 77 | + "./tsconfig.json", |
| 78 | + "./scripts/codemods/data-masking/tsconfig.json", |
| 79 | + ], |
| 80 | + }, |
| 81 | + }, |
| 82 | + |
| 83 | + rules: { |
| 84 | + "react-compiler/react-compiler": "error", |
| 85 | + |
| 86 | + "@typescript-eslint/consistent-type-imports": [ |
| 87 | + "error", |
| 88 | + { |
| 89 | + prefer: "type-imports", |
| 90 | + disallowTypeAnnotations: false, |
| 91 | + fixStyle: "separate-type-imports", |
| 92 | + }, |
| 93 | + ], |
| 94 | + |
| 95 | + "@typescript-eslint/consistent-type-exports": ["error"], |
| 96 | + "@typescript-eslint/no-import-type-side-effects": "error", |
| 97 | + |
| 98 | + "@typescript-eslint/no-restricted-types": [ |
| 99 | + "error", |
| 100 | + { |
| 101 | + types: { |
| 102 | + GraphQLError: { |
| 103 | + message: "Use GraphQLFormattedError instead", |
| 104 | + fixWith: "GraphQLFormattedError", |
| 105 | + }, |
| 106 | + |
| 107 | + ExecutionResult: { |
| 108 | + message: "Use FormattedExecutionResult instead", |
| 109 | + fixWith: "FormattedExecutionResult", |
| 110 | + }, |
| 111 | + }, |
| 112 | + }, |
| 113 | + ], |
| 114 | + |
| 115 | + "no-restricted-syntax": [ |
| 116 | + "error", |
| 117 | + { |
| 118 | + selector: |
| 119 | + "ImportDeclaration[source.value='react'][importKind!='type'] :matches(ImportSpecifier, ImportDefaultSpecifier)", |
| 120 | + message: |
| 121 | + "Please only use the namespace import syntax (`import * as React from 'react'`) for React imports!", |
| 122 | + }, |
| 123 | + ], |
| 124 | + |
| 125 | + "import/consistent-type-specifier-style": ["error", "prefer-top-level"], |
| 126 | + |
| 127 | + "import/extensions": [ |
| 128 | + "error", |
| 129 | + "always", |
| 130 | + { |
| 131 | + ignorePackages: true, |
| 132 | + checkTypeImports: true, |
| 133 | + }, |
| 134 | + ], |
| 135 | + |
| 136 | + "local-rules/require-using-disposable": "error", |
| 137 | + }, |
| 138 | + }, |
| 139 | + ...compat.extends("plugin:testing-library/react").map((config) => ({ |
| 140 | + ...config, |
| 141 | + |
| 142 | + files: [ |
| 143 | + "**/__tests__/**/*.[jt]s", |
| 144 | + "**/__tests__/**/*.[jt]sx", |
| 145 | + "**/?(*.)+(test).[jt]s", |
| 146 | + "**/?(*.)+(test).[jt]sx", |
| 147 | + ], |
| 148 | + })), |
| 149 | + { |
| 150 | + files: [ |
| 151 | + "**/__tests__/**/*.[jt]s", |
| 152 | + "**/__tests__/**/*.[jt]sx", |
| 153 | + "**/?(*.)+(test).[jt]s", |
| 154 | + "**/?(*.)+(test).[jt]sx", |
| 155 | + ], |
| 156 | + |
| 157 | + languageOptions: { |
| 158 | + ecmaVersion: 5, |
| 159 | + sourceType: "script", |
| 160 | + |
| 161 | + parserOptions: { |
| 162 | + project: "./tsconfig.tests.json", |
| 163 | + }, |
| 164 | + }, |
| 165 | + |
| 166 | + rules: { |
| 167 | + "testing-library/prefer-user-event": "error", |
| 168 | + "testing-library/no-wait-for-multiple-assertions": "off", |
| 169 | + "local-rules/require-using-disposable": "error", |
| 170 | + "local-rules/require-disable-act-environment": "error", |
| 171 | + "local-rules/forbid-act-in-disabled-act-environment": "error", |
| 172 | + "@typescript-eslint/no-floating-promises": "warn", |
| 173 | + }, |
| 174 | + }, |
| 175 | +]; |
0 commit comments