.eslintrc.js 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. module.exports = {
  2. //此项是用来告诉eslint找当前配置文件不能往父级查找
  3. root: true,
  4. //此项是用来指定eslint解析器的,解析器必须符合规则,babel-eslint解析器是对babel解析器的包装使其与ESLint解析
  5. parser: 'babel-eslint',
  6. //此项是用来指定javaScript语言类型和风格,sourceType用来指定js导入的方式,默认是script,此处设置为module,指某块导入方式
  7. parserOptions: {
  8. sourceType: 'module'
  9. },
  10. //此项指定环境的全局变量,下面的配置指定为浏览器环境
  11. env: {
  12. browser: true,
  13. },
  14. // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
  15. // 此项是用来配置标准的js风格,就是说写代码的时候要规范的写,如果你使用vs-code我觉得应该可以避免出错
  16. extends: 'standard',
  17. // required to lint *.vue files
  18. // 此项是用来提供插件的,插件名称省略了eslint-plugin-,下面这个配置是用来规范html的
  19. plugins: [
  20. 'html'
  21. ],
  22. // add your custom rules here
  23. // 下面这些rules是用来设置从插件来的规范代码的规则,使用必须去掉前缀eslint-plugin-
  24. // 主要有如下的设置规则,可以设置字符串也可以设置数字,两者效果一致
  25. // "off" -> 0 关闭规则
  26. // "warn" -> 1 开启警告规则
  27. //"error" -> 2 开启错误规则
  28. // 了解了上面这些,下面这些代码相信也看的明白了
  29. rules: {
  30. "indent":["off",2],
  31. "no-console": "error", // 禁止console
  32. "no-alert": "error", // 禁止alert,conirm等
  33. "no-debugger": "error", // 禁止debugger
  34. "semi": 0, // 禁止分号
  35. "no-tabs": "error", // 禁止使用tab
  36. "no-unreachable": "error", // 当有不能执行到的代码时
  37. "eol-last": "error", // 文件末尾强制换行
  38. "no-new": "error", // 禁止在使用new构造一个实例后不赋值
  39. "quotes": "error", // 引号类型 `` "" ''
  40. "no-unused-vars": 0, // 不能有声明后未被使用的变量
  41. "no-trailing-spaces": "error", // 一行结束后面不要有空格
  42. "space-before-function-paren": 0, // 函数定义时括号前面要不要有空格
  43. "no-undef": "error", // 不能有未定义的变量,定义之前必须有var或者let
  44. "curly": ["error", "all"], // 必须使用 if(){} 中的{}
  45. 'arrow-parens': "error", // 箭头函数的参数要有()包裹
  46. 'generator-star-spacing': "error", // allow async-await
  47. "space-before-function-paren": 0, // 禁止函数名前有空格,如function Test (aaa,bbb)
  48. "space-in-parens": 0, // 禁止圆括号有空格,如Test( 2, 3 )
  49. "space-infix-ops": 0, //在操作符旁边必须有空格, 如 a + b而不是a+b
  50. "space-before-blocks": 0, // 语句块之前必须有空格 如 ) {}
  51. "spaced-comment":0, // 注释前必须有空格
  52. "arrow-body-style": ["error", "always"], // 要求箭头函数必须有大括号 如 a => {}
  53. "arrow-parens": ["error", "always"], //要求箭头函数的参数必有用括弧包住,如(a) =>{}
  54. "arrow-spacing": ["error", { "before": true, "after": true }], // 定义箭头函数的箭头前后都必须有空格
  55. "no-const-assign": "error", // 禁止修改const变量
  56. "template-curly-spacing": ["error", "never"], // 禁止末班字符串中的{}中的变量出现空格,如以下错误`${ a }`
  57. "no-multi-spaces": 0, // 禁止多个空格,只有一个空格的地方必须只有一个
  58. "no-whitespace-before-property": 0, // 禁止属性前有空格,如obj. a
  59. "keyword-spacing":0,//关键字前后必须有空格 如 } else {
  60. "no-useless-escape": 0,// 禁止不必要的转义字符
  61. },
  62. }