参考 Google Style

    1. {
    2. "env": {
    3. "browser": true,
    4. "node": true,
    5. "es6": true,
    6. "jquery": true,
    7. "commonjs": true,
    8. "phantomjs": true,
    9. "mocha": true
    10. },
    11. "parser": "babel-eslint",
    12. "parserOptions": {
    13. "ecmaFeatures": {
    14. "jsx": true
    15. }
    16. },
    17. "rules": {
    18. // 不可省略分号
    19. "semi": [2, "always"],
    20. // 控制逗号在行尾出现还是在行首出现 (逗号放在行尾)
    21. "comma-style": [1, "last"],
    22. // 单引号 '优于双引号"
    23. "quotes": [2, "single"],
    24. // 对象属性声明的冒号:后,加空格
    25. "key-spacing": [2],
    26. // 控制逗号前后的空格
    27. "comma-spacing": [2, {
    28. "before": false,
    29. "after": true
    30. }],
    31. // 条件语句if、else、switch...后,加空格
    32. "keyword-spacing": [2, {
    33. "before": true,
    34. "after": true
    35. }],
    36. // 开始大括号前,加空格
    37. "space-before-blocks": [2, "always"],
    38. // 文件末尾强制换行; 为了兼容解析js文件的地方
    39. "eol-last": 2,
    40. // 规则配置
    41. "no-extra-semi": 1,
    42. "no-constant-condition": 2,
    43. "no-extra-boolean-cast": 2,
    44. "use-isnan": 2,
    45. "no-undef-init": 2,
    46. "camelcase": 2,
    47. "no-mixed-spaces-and-tabs": 2,
    48. "no-const-assign": 2,
    49. "no-func-assign": 2,
    50. "no-else-return": 1,
    51. "no-obj-calls": 2,
    52. "valid-typeof": 2,
    53. "no-unused-vars": 1,
    54. "object-curly-spacing": 1,
    55. "block-spacing": 1,
    56. "comma-dangle": 0,
    57. "array-bracket-spacing": 1,
    58. "space-before-function-paren": ["error", {
    59. "named": "never",
    60. "asyncArrow": "always",
    61. "anonymous": "always"
    62. }],
    63. "no-extra-bind": 1,
    64. "no-var": "error",
    65. "arrow-spacing": ["error", {
    66. "before": true,
    67. "after": true
    68. }],
    69. "arrow-body-style": ["error", "as-needed"],
    70. "no-empty-function": ["error", {
    71. "allow": ["arrowFunctions", "constructors"]
    72. }]
    73. },
    74. "settings": {
    75. // 如果通过webpack配置忽略了js文件后缀,在正常情况下eslint会因为找不到文件而报错。因此需要在settings里配置可省略的后缀名
    76. "import/resolver": {
    77. "node": {
    78. "extensions": [".coffee", ".js", ".jsx"]
    79. }
    80. },
    81. // 哪些import是不去检查的
    82. // node_modules为默认值
    83. // 还可以配置带有指定文件后缀不检查,如\.coffee$
    84. "import/ignore": ["node_modules"]
    85. }
    86. }