vue.ts 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. import type { Linter } from 'eslint';
  2. import { interopDefault } from '../util';
  3. export async function vue(): Promise<Linter.Config[]> {
  4. const [pluginVue, parserVue, parserTs] = await Promise.all([
  5. // @ts-expect-error missing types
  6. interopDefault(import('eslint-plugin-vue')),
  7. interopDefault(import('vue-eslint-parser')),
  8. // @ts-expect-error missing types
  9. interopDefault(import('@typescript-eslint/parser')),
  10. ] as const);
  11. return [
  12. {
  13. files: ['**/*.vue'],
  14. languageOptions: {
  15. globals: {
  16. // TODO: 等待插件正式支持后删除
  17. defineModel: true,
  18. },
  19. parser: parserVue,
  20. parserOptions: {
  21. ecmaFeatures: {
  22. jsx: true,
  23. },
  24. extraFileExtensions: ['.vue'],
  25. parser: parserTs,
  26. sourceType: 'module',
  27. },
  28. },
  29. plugins: {
  30. vue: pluginVue,
  31. },
  32. processor: pluginVue.processors['.vue'],
  33. rules: {
  34. ...pluginVue.configs.base.rules,
  35. ...pluginVue.configs['vue3-essential'].rules,
  36. ...pluginVue.configs['vue3-strongly-recommended'].rules,
  37. ...pluginVue.configs['vue3-recommended'].rules,
  38. 'vue/attribute-hyphenation': [
  39. 'error',
  40. 'always',
  41. {
  42. ignore: [],
  43. },
  44. ],
  45. 'vue/attributes-order': 'off',
  46. 'vue/block-order': [
  47. 'error',
  48. {
  49. order: ['script', 'template', 'style'],
  50. },
  51. ],
  52. 'vue/component-name-in-template-casing': ['error', 'PascalCase'],
  53. 'vue/component-options-name-casing': ['error', 'PascalCase'],
  54. 'vue/custom-event-name-casing': ['error', 'camelCase'],
  55. 'vue/define-macros-order': [
  56. 'error',
  57. {
  58. order: [
  59. 'defineOptions',
  60. 'defineProps',
  61. 'defineEmits',
  62. 'defineSlots',
  63. ],
  64. },
  65. ],
  66. 'vue/dot-location': ['error', 'property'],
  67. 'vue/dot-notation': ['error', { allowKeywords: true }],
  68. 'vue/eqeqeq': ['error', 'smart'],
  69. 'vue/html-closing-bracket-newline': 'error',
  70. 'vue/html-indent': 'off',
  71. // 'vue/html-indent': ['error', 2],
  72. 'vue/html-quotes': ['error', 'double'],
  73. 'vue/html-self-closing': [
  74. 'error',
  75. {
  76. html: {
  77. component: 'always',
  78. normal: 'never',
  79. void: 'always',
  80. },
  81. math: 'always',
  82. svg: 'always',
  83. },
  84. ],
  85. 'vue/max-attributes-per-line': 'off',
  86. 'vue/multi-word-component-names': 'off',
  87. 'vue/multiline-html-element-content-newline': 'error',
  88. 'vue/no-empty-pattern': 'error',
  89. 'vue/no-extra-parens': ['error', 'functions'],
  90. 'vue/no-irregular-whitespace': 'error',
  91. 'vue/no-loss-of-precision': 'error',
  92. 'vue/no-reserved-component-names': 'off',
  93. 'vue/no-restricted-syntax': [
  94. 'error',
  95. 'DebuggerStatement',
  96. 'LabeledStatement',
  97. 'WithStatement',
  98. ],
  99. 'vue/no-restricted-v-bind': ['error', '/^v-/'],
  100. 'vue/no-sparse-arrays': 'error',
  101. 'vue/no-unused-refs': 'error',
  102. 'vue/no-useless-v-bind': 'error',
  103. 'vue/object-shorthand': [
  104. 'error',
  105. 'always',
  106. {
  107. avoidQuotes: true,
  108. ignoreConstructors: false,
  109. },
  110. ],
  111. 'vue/one-component-per-file': 'error',
  112. 'vue/prefer-import-from-vue': 'error',
  113. 'vue/prefer-separate-static-class': 'error',
  114. 'vue/prefer-template': 'error',
  115. 'vue/prop-name-casing': ['error', 'camelCase'],
  116. 'vue/require-default-prop': 'error',
  117. 'vue/require-explicit-emits': 'error',
  118. 'vue/require-prop-types': 'off',
  119. 'vue/script-setup-uses-vars': 'error',
  120. 'vue/singleline-html-element-content-newline': 'off',
  121. 'vue/space-infix-ops': 'error',
  122. 'vue/space-unary-ops': ['error', { nonwords: false, words: true }],
  123. 'vue/v-on-event-hyphenation': [
  124. 'error',
  125. 'always',
  126. {
  127. autofix: true,
  128. ignore: [],
  129. },
  130. ],
  131. },
  132. },
  133. ];
  134. }