.eslintrc.js 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. module.exports = {
  2. //此项是用来告诉eslint找当前配置文件不能往父级查找
  3. root: true,
  4. //此项是用来指定eslint解析器的,解析器必须符合规则,babel-eslint解析器是对babel解析器的包装使其与ESLint解析
  5. //此项是用来指定javaScript语言类型和风格,sourceType用来指定js导入的方式,默认是script,此处设置为module,指某块导入方式
  6. parserOptions: {
  7. parser: "babel-eslint",
  8. sourceType: "module"
  9. },
  10. //此项指定环境的全局变量,下面的配置指定为浏览器环境
  11. env: {
  12. browser: true,
  13. node: true
  14. },
  15. // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
  16. extends: ["eslint:recommended", "plugin:vue/essential"],
  17. // required to lint *.vue files
  18. // 此项是用来提供插件的,插件名称省略了eslint-plugin-,下面这个配置是用来规范html的
  19. plugins: ["vue", "prettier"],
  20. // add your custom rules here
  21. // 下面这些rules是用来设置从插件来的规范代码的规则,使用必须去掉前缀eslint-plugin-
  22. // 主要有如下的设置规则,可以设置字符串也可以设置数字,两者效果一致
  23. // "off" -> 0 关闭规则
  24. // "warn" -> 1 开启警告规则
  25. // "error" -> 2 开启错误规则
  26. // 了解了上面这些,下面这些代码相信也看的明白了
  27. rules: {
  28. "require-jsdoc": 1,
  29. "valid-jsdoc": 1,
  30. // allow async-await
  31. "generator-star-spacing": "off",
  32. // allow debugger during development
  33. "no-debugger": process.env.NODE_ENV === "production" ? 2 : 0,
  34. "no-console": process.env.NODE_ENV === "production" ? 0 : 0,
  35. // js语句结尾必须使用分号
  36. semi: ["off", "always"],
  37. // 三等号
  38. eqeqeq: 0,
  39. // 强制在注释中 // 或 /* 使用一致的空格
  40. "spaced-comment": 0,
  41. // 关键字后面使用一致的空格
  42. "keyword-spacing": 0,
  43. // 强制在 function的左括号之前使用一致的空格
  44. "space-before-function-paren": 0,
  45. // 禁止出现未使用过的变量
  46. // 'no-unused-vars': 0,
  47. // 要求或禁止末尾逗号
  48. "comma-dangle": 0,
  49. "valid-jsdoc": 0,
  50. // 未使用变量
  51. "no-unused-vars": [1, {
  52. "vars": "all",
  53. "args": "after-used"
  54. }],
  55. // export | require 格式
  56. "require-jsdoc": [0, {
  57. "require": {
  58. "FunctionDeclaration": true,
  59. "MethodDefinition": false,
  60. "ClassDeclaration": false,
  61. "ArrowFunctionExpression": false
  62. }
  63. }]
  64. }
  65. };