|
| 1 | +/** @author Ka Pui (August) Cheung */ |
| 2 | + |
| 3 | +import path from "node:path"; |
| 4 | +import { fileURLToPath } from "node:url"; |
| 5 | + |
| 6 | +import docusaurusPlugin from "@docusaurus/eslint-plugin"; |
| 7 | +import { includeIgnoreFile } from "@eslint/compat"; |
| 8 | +import eslintConfigPrettier from "eslint-config-prettier"; |
| 9 | +import importPlugin from "eslint-plugin-import"; |
| 10 | +import jsxA11y from "eslint-plugin-jsx-a11y"; |
| 11 | +import reactPlugin from "eslint-plugin-react"; |
| 12 | +import simpleImportSort from "eslint-plugin-simple-import-sort"; |
| 13 | +import eslintPluginUnicorn from "eslint-plugin-unicorn"; |
| 14 | +import tseslint from "typescript-eslint"; |
| 15 | + |
| 16 | +const __filename = fileURLToPath(import.meta.url); |
| 17 | +const __dirname = path.dirname(__filename); |
| 18 | +const gitignorePath = path.resolve(__dirname, ".gitignore"); |
| 19 | + |
| 20 | +/* eslint-disable @typescript-eslint/no-unsafe-argument */ |
| 21 | +/* eslint-disable @typescript-eslint/no-unsafe-member-access */ |
| 22 | +/** @see https://eslint.org/docs/latest/use/configure/ */ |
| 23 | +const eslintConfig = tseslint.config( |
| 24 | + includeIgnoreFile(gitignorePath), |
| 25 | + |
| 26 | + // eslint-disable-next-line import/no-named-as-default-member |
| 27 | + tseslint.configs.recommendedTypeChecked, |
| 28 | + // eslint-disable-next-line import/no-named-as-default-member |
| 29 | + tseslint.configs.stylisticTypeChecked, |
| 30 | + { |
| 31 | + languageOptions: { |
| 32 | + parserOptions: { |
| 33 | + projectService: { |
| 34 | + allowDefaultProject: ["*.config.js"], |
| 35 | + }, |
| 36 | + tsconfigRootDir: import.meta.dirname, |
| 37 | + }, |
| 38 | + }, |
| 39 | + }, |
| 40 | + |
| 41 | + eslintPluginUnicorn.configs.recommended, |
| 42 | + importPlugin.flatConfigs.recommended, |
| 43 | + importPlugin.flatConfigs.typescript, |
| 44 | + { |
| 45 | + settings: { |
| 46 | + "import/resolver": { |
| 47 | + typescript: true, |
| 48 | + node: true, |
| 49 | + }, |
| 50 | + "import/parsers": { |
| 51 | + "@typescript-eslint/parser": [".ts", ".tsx"], |
| 52 | + }, |
| 53 | + }, |
| 54 | + }, |
| 55 | + { |
| 56 | + plugins: { |
| 57 | + "simple-import-sort": simpleImportSort, |
| 58 | + }, |
| 59 | + rules: { |
| 60 | + "simple-import-sort/imports": "warn", |
| 61 | + "simple-import-sort/exports": "warn", |
| 62 | + }, |
| 63 | + }, |
| 64 | + |
| 65 | + reactPlugin.configs.flat.recommended, |
| 66 | + reactPlugin.configs.flat["jsx-runtime"], |
| 67 | + jsxA11y.flatConfigs.recommended, |
| 68 | + |
| 69 | + { |
| 70 | + rules: { |
| 71 | + "@typescript-eslint/consistent-type-imports": [ |
| 72 | + "warn", |
| 73 | + { |
| 74 | + fixStyle: "inline-type-imports", |
| 75 | + }, |
| 76 | + ], |
| 77 | + "@typescript-eslint/no-non-null-assertion": "error", |
| 78 | + "import/consistent-type-specifier-style": ["warn", "prefer-inline"], |
| 79 | + "import/newline-after-import": "warn", |
| 80 | + "import/no-duplicates": [ |
| 81 | + "error", |
| 82 | + { |
| 83 | + "prefer-inline": true, |
| 84 | + }, |
| 85 | + ], |
| 86 | + "react/jsx-curly-brace-presence": ["warn", "never"], |
| 87 | + "react/jsx-sort-props": [ |
| 88 | + "warn", |
| 89 | + { |
| 90 | + callbacksLast: true, |
| 91 | + multiline: "last", |
| 92 | + reservedFirst: true, |
| 93 | + shorthandFirst: true, |
| 94 | + }, |
| 95 | + ], |
| 96 | + "unicorn/filename-case": [ |
| 97 | + "warn", |
| 98 | + { |
| 99 | + cases: { |
| 100 | + kebabCase: true, |
| 101 | + camelCase: true, |
| 102 | + pascalCase: true, |
| 103 | + }, |
| 104 | + }, |
| 105 | + ], |
| 106 | + "unicorn/no-null": "off", |
| 107 | + "unicorn/prevent-abbreviations": [ |
| 108 | + "warn", |
| 109 | + { |
| 110 | + replacements: { |
| 111 | + args: false, |
| 112 | + dev: false, |
| 113 | + env: false, |
| 114 | + params: false, |
| 115 | + props: false, |
| 116 | + ref: false, |
| 117 | + }, |
| 118 | + }, |
| 119 | + ], |
| 120 | + }, |
| 121 | + }, |
| 122 | + |
| 123 | + { |
| 124 | + plugins: { |
| 125 | + "@docusaurus": docusaurusPlugin, |
| 126 | + }, |
| 127 | + rules: { |
| 128 | + "import/no-unresolved": [ |
| 129 | + "error", |
| 130 | + { ignore: ["^@theme", "^@docusaurus", "^@site"] }, |
| 131 | + ], |
| 132 | + "@docusaurus/string-literal-i18n-messages": "error", |
| 133 | + "@docusaurus/no-html-links": "warn", |
| 134 | + "@docusaurus/prefer-docusaurus-heading": "warn", |
| 135 | + }, |
| 136 | + }, |
| 137 | + |
| 138 | + eslintConfigPrettier, |
| 139 | +); |
| 140 | + |
| 141 | +export default eslintConfig; |
0 commit comments