|
| 1 | +import { FlatCompat } from "@eslint/eslintrc"; |
| 2 | +import eslint from "@eslint/js"; |
| 3 | +import perfectionisteslint from "eslint-plugin-perfectionist"; |
| 4 | +import globals from "globals"; |
| 5 | +import tseslint from "typescript-eslint"; |
| 6 | + |
| 7 | +const compat = new FlatCompat({ |
| 8 | + baseDirectory: import.meta.dirname, |
| 9 | +}); |
| 10 | + |
| 11 | +export default tseslint.config( |
| 12 | + // Use recommended eslint rules |
| 13 | + eslint.configs.recommended, |
| 14 | + |
| 15 | + // Use recommended type-checked typescript-eslint rules |
| 16 | + tseslint.configs.recommendedTypeChecked, |
| 17 | + |
| 18 | + // Use stylistic type-checked typescript-eslint rules |
| 19 | + tseslint.configs.stylisticTypeChecked, |
| 20 | + |
| 21 | + // Use recommended Docusaurus rules |
| 22 | + ...compat.extends("plugin:@docusaurus/recommended"), |
| 23 | + |
| 24 | + // Use recommended perfectionist rules |
| 25 | + perfectionisteslint.configs["recommended-alphabetical"], |
| 26 | + |
| 27 | + // Custom configuration |
| 28 | + { |
| 29 | + languageOptions: { |
| 30 | + globals: { |
| 31 | + // Support browser globals |
| 32 | + ...globals.browser, |
| 33 | + |
| 34 | + // Support ES2023 globals |
| 35 | + ...globals.es2023, |
| 36 | + |
| 37 | + // Support node globals |
| 38 | + ...globals.node, |
| 39 | + }, |
| 40 | + |
| 41 | + parserOptions: { |
| 42 | + // Use project service to build type information |
| 43 | + // Needed for type-aware linting |
| 44 | + projectService: true, |
| 45 | + |
| 46 | + // Allow ES2022 syntax |
| 47 | + sourceType: "module", |
| 48 | + |
| 49 | + // Set the root directory of the project |
| 50 | + // Needed for type-aware linting |
| 51 | + tsconfigRootDir: import.meta.dirname, |
| 52 | + }, |
| 53 | + }, |
| 54 | + |
| 55 | + rules: { |
| 56 | + // Use objects instead of records for empty types |
| 57 | + "@typescript-eslint/consistent-indexed-object-style": [ |
| 58 | + "error", |
| 59 | + "index-signature", |
| 60 | + ], |
| 61 | + |
| 62 | + // Use types instead of interfaces |
| 63 | + "@typescript-eslint/consistent-type-definitions": ["error", "type"], |
| 64 | + |
| 65 | + // Allow promises in callbacks |
| 66 | + "@typescript-eslint/no-misused-promises": [ |
| 67 | + "error", |
| 68 | + { |
| 69 | + checksVoidReturn: false, |
| 70 | + }, |
| 71 | + ], |
| 72 | + |
| 73 | + // Allow nullish coalescing operator for primitive types |
| 74 | + "@typescript-eslint/prefer-nullish-coalescing": [ |
| 75 | + "error", |
| 76 | + { |
| 77 | + ignorePrimitives: true, |
| 78 | + }, |
| 79 | + ], |
| 80 | + |
| 81 | + // Allow async functions without await |
| 82 | + "@typescript-eslint/require-await": "off", |
| 83 | + |
| 84 | + // Skip checking whether static methods are bound |
| 85 | + "@typescript-eslint/unbound-method": [ |
| 86 | + "error", |
| 87 | + { |
| 88 | + ignoreStatic: true, |
| 89 | + }, |
| 90 | + ], |
| 91 | + |
| 92 | + // Allow anonymous default exports |
| 93 | + "import/no-anonymous-default-export": "off", |
| 94 | + |
| 95 | + // Allow empty block statements |
| 96 | + "no-empty": "off", |
| 97 | + |
| 98 | + // Allow empty destructuring patterns |
| 99 | + "no-empty-pattern": "off", |
| 100 | + |
| 101 | + // Don't sort module members |
| 102 | + "perfectionist/sort-modules": "off", |
| 103 | + }, |
| 104 | + }, |
| 105 | +); |
0 commit comments