.eslintrc.js 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. module.exports = {
  2. // 如果想要在不同的目录中使用不同的 .eslintrc, 就需要在该目录中添加如下的配置项:
  3. // 告诉eslint找.eslintrc配置文件不能往父级查找
  4. // root: true,
  5. // 此项是用来提供插件的,插件名称省略了eslint-plugin-,下面这个配置是用来规范vue的
  6. // plugins: ['vue'],
  7. extends: [
  8. // add more generic rulesets here, such as:
  9. 'eslint:recommended', // eslint推荐规则预设
  10. 'plugin:vue/vue3-recommended', // eslint-plugin-vue推荐的适用于vue3的规则预设
  11. ],
  12. parser: 'vue-eslint-parser',
  13. // 自定义 parser
  14. parserOptions: {
  15. parser: '@babel/eslint-parser',
  16. sourceType: 'module',
  17. },
  18. env: {
  19. browser: true,
  20. node: true,
  21. es6: true,
  22. jquery: true,
  23. },
  24. rules: {
  25. // override/add rules settings here, such as:
  26. 'vue/no-unused-vars': 'error',
  27. // 此规则禁用不必要的分号。
  28. 'no-extra-semi': 'off',
  29. // 该规则强制使用一致的分号
  30. semi: ['error', 'always', { 'omitLastInOneLineBlock': false }],
  31. "vue/multi-word-component-names": ["error", {
  32. "ignores": ["Date"] // 允许特定单单词名称
  33. }],
  34. // 该规则强制使用一致的反勾号、双引号或单引号。
  35. quotes: ['error', 'single'],
  36. // 该规则旨在强制使用一致的缩进风格。默认是 4个空格。
  37. indent: ['error', 2],
  38. // 该规则旨在通过限制代码行的长度来提高代码的可读性和可维护性。
  39. // 一行的长度为行中的 Unicode 字符的数量。
  40. 'max-len': ['error', { code: 185 }],
  41. // 这个规则强制在对象和数组字面量中使用一致的拖尾逗号。
  42. // "always-multiline" 当最后一个元素或属性与闭括号 ] 或 } 在 不同的行时,要求使用拖尾逗号;当在 同一行时,禁止使用拖尾逗号。
  43. 'comma-dangle': ['error', 'always-multiline'],
  44. // 该规则强制箭头函数单个参数是否要使用圆括号括起来
  45. // "as-needed":在可以省略括号的地方强制不使用括号
  46. 'arrow-parens': ['error', 'as-needed'],
  47. // 此规则在单行元素的内容之前和之后强制换行。
  48. 'vue/singleline-html-element-content-newline': 'off',
  49. // 限制每行最多能写多少个属性
  50. 'vue/max-attributes-per-line': 'off',
  51. // 标签自闭合相关设置
  52. 'vue/html-self-closing': [
  53. 'warn',
  54. {
  55. html: {
  56. void: 'always',
  57. normal: 'always',
  58. component: 'always',
  59. },
  60. },
  61. ],
  62. 'no-unused-vars': [0, {
  63. // function 参数未使用不检查
  64. 'args': 'none',
  65. }],
  66. 'vue/v-on-event-hyphenation': ['warn', 'always', {
  67. 'autofix': true,
  68. 'ignore': [],
  69. }],
  70. 'comma-style': [2, 'last'],
  71. },
  72. 'globals':{
  73. 'document': true,
  74. 'localStorage': true,
  75. 'window': true,
  76. 'BootstrapDialog': true,
  77. 'REMOTE_DEV_PORT': true
  78. },
  79. };