eslint的規則設置

1、eslint 修改- 在.eslintrc.js下添加或者修改規則(rules部分)

'rules': {
  // allow paren-less arrow functions
  'arrow-parens': 0,
  // allow async-await
  'generator-star-spacing': 0,
  // allow debugger during development
  'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0,
  //在此處添加
  'space-before-function-paren': ["error", "never"]
}

2、規則名和屬性解析說明

屬性名 屬性值 描述
array-callback-return "error" Array執行回調函數返回語句
indent ["error", 4, {"SwitchCase": 1}] 縮寫格式的一致性
block-spacing "error" 禁止執行空間內出現'-'
brace-style ["error","1tbs"] 代碼書寫格式驗證
camelcase ["error", { "properties": "never" }] 屬性命名規則可以不使用駝峯命名法
callback-return ["error", ["cb", "callback", "next"]] 回調函數需要return進行返回
comma-spacing "error" 不允許在逗號前面出現空格
comma-style ["error", "last"] 方數組元素、變量聲明等直接需要逗號隔開
consistent-return "error" 保持return返回的一致性
curly ["error", "all"] 函數或者條件判斷時需要統一使用大括號
default-case "error" switch語句中必須有default條件
dot-notation ["error", { "allowKeywords": false }] 不允許關鍵字出現在變量中
eol-last "error" 代碼間間隔出現一行
eqeqeq "error" 消除不安全類型的全等操作
guard-for-in "error" for循環中過濾掉一下不被需要的行爲
key-spacing ["error", { "beforeColon": false, "afterColon": true }] 鍵和值前保留一個空格
keyword-spacing "error" 確保字符前後空格的一致性
lines-around-comment ["error", {
"beforeBlockComment": true,
"afterBlockComment": false,
"beforeLineComment": true,
"afterLineComment": false
}]
註釋前需要空行,註釋後不需要空行
new-cap "error" 構造函數首字母需要大寫
newline-after-var ["error", "never"] var定義後不空行
new-parens "error" 沒有參數時,構造函數也需要添加括號
no-invalid-this "error" 不允許關鍵字this在函數或者類的外面
no-multi-spaces "error" 不允許鍵和值之間存在多個空格
no-redeclare "error" 不允許重複聲明
no-return-assign "error" 不允許在return語句中任務
no-spaced-func "error" 調用函數時,函數名和括號之間不能有空格。
no-trailing-spaces "error" 不允許在語句後存在多餘的空格
semi "error" 語句以分號結尾
semi-spacing "error"
分號前後不能有空格
quotes ["error","double"] 使用雙引號
[space-before-function-paren](http://eslint.org/docs/rules/space-before-function-paren "space-before-function-paren": ["error", "never"] 不允許函數括號之間存在空格
space-in-parens "error" 不允許在括號裏面存在空格
space-infix-ops "error" 插入符合變量之間需要添加一個空格
space-unary-ops ["error", {"words": true, "nonwords": false}] 允許一元運算符操作
spaced-comment "error" 註釋前需要一個空格
yoda ["error", "never"] 條件語句中,變量在賦值語句的前面
no-mixed-requires "error" 不允許混合requires文件
no-new-require "error" 不允許new require出現
no-path-concat "error" 不允許路徑以_鏈接
handle-callback-err ["error", "err"] 處理錯誤的回調函數
semi "error" 語句以分號結尾
semi-spacing "error"
分號前後不能有空格
quotes ["error","double"] 使用雙引號
[space-before-function-paren](http://eslint.org/docs/rules/space-before-function-paren "space-before-function-paren": ["error", "never"] 不允許函數括號之間存在空格
space-in-parens "error" 不允許在括號裏面存在空格
space-infix-ops "error" 插入符合變量之間需要添加一個空格
space-unary-ops ["error", {"words": true, "nonwords": false}] 允許一元運算符操作
spaced-comment "error" 註釋前需要一個空格
yoda ["error", "never"] 條件語句中,變量在賦值語句的前面
no-mixed-requires "error" 不允許混合requires文件
no-new-require "error" 不允許new require出現
no-path-concat "error" 不允許路徑以_鏈接
handle-callback-err ["error", "err"] 處理錯誤的回調函數

更多、更新用法可以前往官網:http://eslint.cn/docs/rules/
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章