eslint.config.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. import { defineConfig } from '@soybeanjs/eslint-config';
  2. import simpleImportSort from 'eslint-plugin-simple-import-sort';
  3. export default defineConfig(
  4. { vue: true, unocss: true },
  5. {
  6. plugins: {
  7. 'simple-import-sort': simpleImportSort,
  8. },
  9. rules: {
  10. // 禁止声明未使用的变量
  11. 'no-unused-vars': 'warn',
  12. // 禁止使用 var 关键字
  13. 'no-var': 'error',
  14. // 推荐使用 const 关键字
  15. 'prefer-const': 'error',
  16. // 箭头函数参数括号风格
  17. 'arrow-parens': ['error', 'as-needed'],
  18. // 强制使用分号
  19. semi: ['error', 'always'],
  20. // 强制使用单引号
  21. quotes: ['error', 'single'],
  22. // 禁止末尾逗号
  23. 'comma-dangle': ['error', 'never'],
  24. // 对象字面量的大括号间距
  25. 'object-curly-spacing': ['error', 'always'],
  26. // 大括号内的空格
  27. 'space-in-parens': ['error', 'never'],
  28. // 对象键与值之间的空格
  29. 'key-spacing': 'error',
  30. // 函数前括号前的空格
  31. 'space-before-function-paren': [
  32. 'error',
  33. {
  34. anonymous: 'never',
  35. named: 'never',
  36. asyncArrow: 'always',
  37. },
  38. ],
  39. // 最大行长度
  40. 'max-len': [
  41. 'error',
  42. {
  43. code: 120,
  44. ignoreComments: true,
  45. ignoreUrls: true,
  46. ignoreStrings: true,
  47. ignoreTemplateLiterals: true,
  48. ignoreRegExpLiterals: true,
  49. },
  50. ],
  51. // Vue 特定规则
  52. // HTML 缩进
  53. 'vue/html-indent': [
  54. 'error',
  55. 2,
  56. {
  57. attribute: 1,
  58. baseIndent: 1,
  59. closeBracket: 0,
  60. alignAttributesVertically: true,
  61. ignores: [],
  62. },
  63. ],
  64. // 每行的最大属性数量
  65. 'vue/max-attributes-per-line': [
  66. 'error',
  67. {
  68. singleline: 3,
  69. multiline: {
  70. max: 1,
  71. allowFirstLine: false,
  72. },
  73. },
  74. ],
  75. // 单行 HTML 元素的内容必须在新的一行
  76. 'vue/singleline-html-element-content-newline': [
  77. 'error',
  78. {
  79. ignoreWhenNoAttributes: true,
  80. ignores: ['img'],
  81. },
  82. ],
  83. 'vue/multi-word-component-names': [
  84. 'warn',
  85. {
  86. ignores: ['index', 'App', 'Register', '[id]', '[url]'],
  87. },
  88. ],
  89. 'vue/component-name-in-template-casing': [
  90. 'warn',
  91. 'PascalCase',
  92. {
  93. registeredComponentsOnly: false,
  94. ignores: ['/^icon-/'],
  95. },
  96. ],
  97. 'vue/no-static-inline-styles': [
  98. 'error',
  99. {
  100. allowBinding: true,
  101. },
  102. ],
  103. 'vue/no-v-html': 'off',
  104. 'unocss/order-attributify': 'off',
  105. 'simple-import-sort/imports': 'error',
  106. 'simple-import-sort/exports': 'error',
  107. 'no-use-before-define': 'off',
  108. '@typescript-eslint/no-use-before-define': 'off',
  109. },
  110. },
  111. );