.eslintrc.cjs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. module.exports = {
  2. env: {
  3. browser: true,
  4. es2021: true,
  5. node: true,
  6. },
  7. extends: [
  8. 'eslint:recommended',
  9. 'plugin:@typescript-eslint/recommended',
  10. 'plugin:vue/vue3-essential',
  11. // eslint-plugin-import 插件, @see https://www.npmjs.com/package/eslint-plugin-import
  12. 'plugin:import/recommended',
  13. // eslint-config-airbnb-base 插件 已经改用 eslint-config-standard 插件
  14. 'standard',
  15. // 1. 接入 prettier 的规则
  16. 'prettier',
  17. 'plugin:prettier/recommended',
  18. './.eslintrc-auto-import.json',
  19. ],
  20. overrides: [
  21. {
  22. env: {
  23. node: true,
  24. },
  25. files: ['.eslintrc.{js,cjs}'],
  26. parserOptions: {
  27. sourceType: 'script',
  28. },
  29. },
  30. ],
  31. parserOptions: {
  32. ecmaVersion: 'latest',
  33. parser: '@typescript-eslint/parser',
  34. sourceType: 'module',
  35. },
  36. plugins: [
  37. '@typescript-eslint',
  38. 'vue',
  39. // 2. 加入 prettier 的 eslint 插件
  40. 'prettier',
  41. // eslint-import-resolver-typescript 插件,@see https://www.npmjs.com/package/eslint-import-resolver-typescript
  42. 'import',
  43. ],
  44. rules: {
  45. // 3. 注意要加上这一句,开启 prettier 自动修复的功能
  46. 'prettier/prettier': 'error',
  47. // turn on errors for missing imports
  48. 'import/no-unresolved': 'off',
  49. // 对后缀的检测,否则 import 一个ts文件也会报错,需要手动添加'.ts', 增加了下面的配置后就不用了
  50. 'import/extensions': [
  51. 'error',
  52. 'ignorePackages',
  53. { js: 'never', jsx: 'never', ts: 'never', tsx: 'never' },
  54. ],
  55. // 只允许1个默认导出,关闭,否则不能随意export xxx
  56. 'import/prefer-default-export': ['off'],
  57. 'no-console': ['off'],
  58. // 'no-unused-vars': ['off'],
  59. // '@typescript-eslint/no-unused-vars': ['off'],
  60. // 解决vite.config.ts报错问题
  61. 'import/no-extraneous-dependencies': 'off',
  62. 'no-plusplus': 'off',
  63. 'no-shadow': 'off',
  64. 'vue/multi-word-component-names': 'off',
  65. '@typescript-eslint/no-explicit-any': 'off',
  66. 'no-underscore-dangle': 'off',
  67. 'no-use-before-define': 'off',
  68. 'no-undef': 'off',
  69. 'no-unused-vars': 'off',
  70. 'no-param-reassign': 'off',
  71. '@typescript-eslint/no-unused-vars': 'off',
  72. // 避免 `eslint` 对于 `typescript` 函数重载的误报
  73. 'no-redeclare': 'off',
  74. '@typescript-eslint/no-redeclare': 'error',
  75. },
  76. // eslint-import-resolver-typescript 插件,@see https://www.npmjs.com/package/eslint-import-resolver-typescript
  77. settings: {
  78. 'import/parsers': {
  79. '@typescript-eslint/parser': ['.ts', '.tsx'],
  80. },
  81. 'import/resolver': {
  82. typescript: {},
  83. },
  84. },
  85. globals: {
  86. $t: true,
  87. uni: true,
  88. UniApp: true,
  89. wx: true,
  90. WechatMiniprogram: true,
  91. getCurrentPages: true,
  92. UniHelper: true,
  93. Page: true,
  94. App: true,
  95. NodeJS: true,
  96. },
  97. }