.eslintrc.json 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. {
  2. "env": {
  3. "browser": false,
  4. "es6": true,
  5. "node": true
  6. },
  7. "parser": "@typescript-eslint/parser",
  8. "parserOptions": {
  9. "project": "tsconfig.json",
  10. "sourceType": "module",
  11. "ecmaVersion": 2020
  12. },
  13. "plugins": ["@typescript-eslint", "prettier", "import"],
  14. "extends": [
  15. "prettier",
  16. "plugin:@typescript-eslint/recommended",
  17. "plugin:import/recommended",
  18. "plugin:import/typescript"
  19. // Uncomment the following lines to enable the recommended rules for type checking.
  20. // "plugin:@typescript-eslint/recommended-requiring-type-checking",
  21. ],
  22. "rules": {
  23. // The following rule is enabled only to supplement the inline suppression
  24. // examples, and because it is not a recommended rule, you should either
  25. // disable it, or understand what it enforces.
  26. // https://typescript-eslint.io/rules/explicit-function-return-type/
  27. // see prettier setting in ./.prettierrc
  28. "prettier/prettier": [
  29. "error",
  30. {},
  31. {
  32. "usePrettierrc": true
  33. }
  34. ],
  35. "@typescript-eslint/no-inferrable-types": 0,
  36. "@typescript-eslint/no-unused-vars": 2,
  37. "@typescript-eslint/no-var-requires": 0,
  38. "@typescript-eslint/no-explicit-any": 0,
  39. // disable error for unused vars
  40. "no-unused-vars": 0,
  41. // Import 规则:禁止在 import 语句中使用文件扩展名
  42. "import/extensions": [
  43. "error",
  44. "ignorePackages",
  45. {
  46. "js": "never",
  47. "jsx": "never",
  48. "ts": "never",
  49. "tsx": "never"
  50. }
  51. ],
  52. // 确保 import 路径存在且正确
  53. "import/no-unresolved": "error",
  54. // 禁止重复导入
  55. "import/no-duplicates": "error",
  56. // import 语句排序
  57. "import/order": [
  58. "error",
  59. {
  60. "groups": [
  61. "builtin",
  62. "external",
  63. "internal",
  64. "parent",
  65. "sibling",
  66. "index"
  67. ],
  68. "newlines-between": "always",
  69. "alphabetize": {
  70. "order": "asc",
  71. "caseInsensitive": true
  72. }
  73. }
  74. ]
  75. },
  76. "settings": {
  77. "import/resolver": {
  78. "typescript": {
  79. "alwaysTryTypes": true,
  80. "project": "./tsconfig.json"
  81. },
  82. "node": {
  83. "extensions": [".js", ".jsx", ".ts", ".tsx"]
  84. }
  85. },
  86. "import/parsers": {
  87. "@typescript-eslint/parser": [".ts", ".tsx"]
  88. }
  89. }
  90. }