index.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308
  1. const { defineConfig } = require('eslint-define-config')
  2. module.exports = defineConfig({
  3. env: {
  4. es6: true,
  5. browser: true,
  6. node: true,
  7. },
  8. plugins: ['@typescript-eslint', 'prettier', 'unicorn'],
  9. extends: [
  10. 'eslint:recommended',
  11. 'plugin:import/recommended',
  12. 'plugin:eslint-comments/recommended',
  13. 'plugin:jsonc/recommended-with-jsonc',
  14. 'plugin:markdown/recommended',
  15. 'plugin:vue/vue3-recommended',
  16. 'plugin:@typescript-eslint/recommended',
  17. 'prettier',
  18. ],
  19. settings: {
  20. 'import/resolver': {
  21. node: { extensions: ['.js', '.mjs', '.ts', '.d.ts', '.tsx'] },
  22. },
  23. },
  24. overrides: [
  25. {
  26. files: ['*.json', '*.json5', '*.jsonc'],
  27. parser: 'jsonc-eslint-parser',
  28. },
  29. {
  30. files: ['*.ts', '*.vue'],
  31. rules: {
  32. 'no-undef': 'off',
  33. },
  34. },
  35. {
  36. files: ['**/__tests__/**'],
  37. rules: {
  38. 'no-console': 'off',
  39. 'vue/one-component-per-file': 'off',
  40. },
  41. },
  42. {
  43. files: ['package.json'],
  44. parser: 'jsonc-eslint-parser',
  45. rules: {
  46. 'jsonc/sort-keys': [
  47. 'error',
  48. {
  49. pathPattern: '^$',
  50. order: [
  51. 'name',
  52. 'version',
  53. 'private',
  54. 'packageManager',
  55. 'description',
  56. 'type',
  57. 'keywords',
  58. 'homepage',
  59. 'bugs',
  60. 'license',
  61. 'author',
  62. 'contributors',
  63. 'funding',
  64. 'files',
  65. 'main',
  66. 'module',
  67. 'exports',
  68. 'unpkg',
  69. 'jsdelivr',
  70. 'browser',
  71. 'bin',
  72. 'man',
  73. 'directories',
  74. 'repository',
  75. 'publishConfig',
  76. 'scripts',
  77. 'peerDependencies',
  78. 'peerDependenciesMeta',
  79. 'optionalDependencies',
  80. 'dependencies',
  81. 'devDependencies',
  82. 'engines',
  83. 'config',
  84. 'overrides',
  85. 'pnpm',
  86. 'husky',
  87. 'lint-staged',
  88. 'eslintConfig',
  89. ],
  90. },
  91. {
  92. pathPattern: '^(?:dev|peer|optional|bundled)?[Dd]ependencies$',
  93. order: { type: 'asc' },
  94. },
  95. ],
  96. },
  97. },
  98. {
  99. files: ['*.d.ts'],
  100. rules: {
  101. 'import/no-duplicates': 'off',
  102. },
  103. },
  104. {
  105. files: ['*.js'],
  106. rules: {
  107. '@typescript-eslint/no-var-requires': 'off',
  108. },
  109. },
  110. {
  111. files: ['*.vue'],
  112. parser: 'vue-eslint-parser',
  113. parserOptions: {
  114. parser: '@typescript-eslint/parser',
  115. extraFileExtensions: ['.vue'],
  116. ecmaVersion: 'latest',
  117. ecmaFeatures: {
  118. jsx: true,
  119. },
  120. },
  121. rules: {
  122. 'no-undef': 'off',
  123. },
  124. },
  125. {
  126. files: ['**/*.md/*.js', '**/*.md/*.ts'],
  127. rules: {
  128. 'no-console': 'off',
  129. 'import/no-unresolved': 'off',
  130. '@typescript-eslint/no-unused-vars': 'off',
  131. },
  132. },
  133. ],
  134. rules: {
  135. // js/ts
  136. camelcase: ['error', { properties: 'never' }],
  137. 'no-console': ['warn', { allow: ['error'] }],
  138. 'no-debugger': 'warn',
  139. 'no-constant-condition': ['error', { checkLoops: false }],
  140. 'no-restricted-syntax': ['error', 'LabeledStatement', 'WithStatement'],
  141. 'no-return-await': 'error',
  142. 'no-var': 'error',
  143. 'no-empty': ['error', { allowEmptyCatch: true }],
  144. 'prefer-const': [
  145. 'warn',
  146. { destructuring: 'all', ignoreReadBeforeAssign: true },
  147. ],
  148. 'prefer-arrow-callback': [
  149. 'error',
  150. { allowNamedFunctions: false, allowUnboundThis: true },
  151. ],
  152. 'object-shorthand': [
  153. 'error',
  154. 'always',
  155. { ignoreConstructors: false, avoidQuotes: true },
  156. ],
  157. 'prefer-rest-params': 'error',
  158. 'prefer-spread': 'error',
  159. 'prefer-template': 'error',
  160. 'no-redeclare': 'off',
  161. '@typescript-eslint/no-redeclare': 'error',
  162. // best-practice
  163. 'array-callback-return': 'error',
  164. 'block-scoped-var': 'error',
  165. 'no-alert': 'warn',
  166. 'no-case-declarations': 'error',
  167. 'no-multi-str': 'error',
  168. 'no-with': 'error',
  169. 'no-void': 'error',
  170. 'sort-imports': [
  171. 'warn',
  172. {
  173. ignoreCase: false,
  174. ignoreDeclarationSort: true,
  175. ignoreMemberSort: false,
  176. memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
  177. allowSeparatedGroups: false,
  178. },
  179. ],
  180. // stylistic-issues
  181. 'prefer-exponentiation-operator': 'error',
  182. // ts
  183. '@typescript-eslint/explicit-module-boundary-types': 'off',
  184. '@typescript-eslint/no-explicit-any': 'off',
  185. '@typescript-eslint/no-non-null-assertion': 'off',
  186. '@typescript-eslint/no-non-null-asserted-optional-chain': 'off',
  187. '@typescript-eslint/consistent-type-imports': [
  188. 'error',
  189. { disallowTypeAnnotations: false },
  190. ],
  191. '@typescript-eslint/ban-ts-comment': ['off', { 'ts-ignore': false }],
  192. // vue
  193. 'vue/no-v-html': 'off',
  194. 'vue/require-default-prop': 'off',
  195. 'vue/require-explicit-emits': 'off',
  196. 'vue/multi-word-component-names': 'off',
  197. 'vue/prefer-import-from-vue': 'off',
  198. 'vue/no-v-text-v-html-on-component': 'off',
  199. 'vue/html-self-closing': [
  200. 'error',
  201. {
  202. html: {
  203. void: 'always',
  204. normal: 'always',
  205. component: 'always',
  206. },
  207. svg: 'always',
  208. math: 'always',
  209. },
  210. ],
  211. // prettier
  212. 'prettier/prettier': 'error',
  213. // import
  214. 'import/first': 'error',
  215. 'import/no-duplicates': 'error',
  216. 'import/order': [
  217. 'error',
  218. {
  219. groups: [
  220. 'builtin',
  221. 'external',
  222. 'internal',
  223. 'parent',
  224. 'sibling',
  225. 'index',
  226. 'object',
  227. 'type',
  228. ],
  229. pathGroups: [
  230. {
  231. pattern: 'vue',
  232. group: 'external',
  233. position: 'before',
  234. },
  235. {
  236. pattern: '@vue/**',
  237. group: 'external',
  238. position: 'before',
  239. },
  240. {
  241. pattern: '@element-plus/**',
  242. group: 'internal',
  243. },
  244. ],
  245. pathGroupsExcludedImportTypes: ['type'],
  246. },
  247. ],
  248. 'import/no-unresolved': 'off',
  249. 'import/namespace': 'off',
  250. 'import/default': 'off',
  251. 'import/no-named-as-default': 'off',
  252. 'import/no-named-as-default-member': 'off',
  253. 'import/named': 'off',
  254. // eslint-plugin-eslint-comments
  255. 'eslint-comments/disable-enable-pair': ['error', { allowWholeFile: true }],
  256. // unicorn
  257. 'unicorn/custom-error-definition': 'error',
  258. 'unicorn/error-message': 'error',
  259. 'unicorn/escape-case': 'error',
  260. 'unicorn/import-index': 'error',
  261. 'unicorn/new-for-builtins': 'error',
  262. 'unicorn/no-array-method-this-argument': 'error',
  263. 'unicorn/no-array-push-push': 'error',
  264. 'unicorn/no-console-spaces': 'error',
  265. 'unicorn/no-for-loop': 'error',
  266. 'unicorn/no-hex-escape': 'error',
  267. 'unicorn/no-instanceof-array': 'error',
  268. 'unicorn/no-invalid-remove-event-listener': 'error',
  269. 'unicorn/no-new-array': 'error',
  270. 'unicorn/no-new-buffer': 'error',
  271. 'unicorn/no-unsafe-regex': 'off',
  272. 'unicorn/number-literal-case': 'error',
  273. 'unicorn/prefer-array-find': 'error',
  274. 'unicorn/prefer-array-flat-map': 'error',
  275. 'unicorn/prefer-array-index-of': 'error',
  276. 'unicorn/prefer-array-some': 'error',
  277. 'unicorn/prefer-date-now': 'error',
  278. 'unicorn/prefer-dom-node-dataset': 'error',
  279. 'unicorn/prefer-includes': 'error',
  280. 'unicorn/prefer-keyboard-event-key': 'error',
  281. 'unicorn/prefer-math-trunc': 'error',
  282. 'unicorn/prefer-modern-dom-apis': 'error',
  283. 'unicorn/prefer-negative-index': 'error',
  284. 'unicorn/prefer-number-properties': 'error',
  285. 'unicorn/prefer-optional-catch-binding': 'error',
  286. 'unicorn/prefer-prototype-methods': 'error',
  287. 'unicorn/prefer-query-selector': 'error',
  288. 'unicorn/prefer-reflect-apply': 'error',
  289. 'unicorn/prefer-string-slice': 'error',
  290. 'unicorn/prefer-string-starts-ends-with': 'error',
  291. 'unicorn/prefer-string-trim-start-end': 'error',
  292. 'unicorn/prefer-type-error': 'error',
  293. 'unicorn/throw-new-error': 'error',
  294. },
  295. })