为什么这会触发 eslint 中的逗号悬挂规则?

Why does this trigger comma-dangle rule in eslint?

这在我看来是正确的,但为什么 eslint 显示违反规则,在最后一个 属性 "credentials" 末尾缺少尾随逗号 comma-dangle

  dispatch({
    type: LOGIN_USER,
    payload: credentials
  });

.eslintrc

{
  "extends": "airbnb",
  "globals": {
    "__DEV__": true
  },
  "rules": {
    "react/jsx-quotes": 0,
    "jsx-quotes": [2, "prefer-double"]
  }
}

基于 airbnb 配置,规则设置如下 comma-dangle: [2, "always-multiline"].

据此,expected代码为

  dispatch({
    type: LOGIN_USER,
    payload: credentials,
  });

它期望在结尾有一个 ,

有关规则的更多信息:http://eslint.org/docs/rules/comma-dangle

使用下面的规则来避免它

rules: {
    'comma-dangle': ['error', 'never']
  }

//或

 "comma-dangle": ["error", {
        "arrays": "never",
        "objects": "never",
        "imports": "never",
        "exports": "never",
        "functions": "never"
    }]

参考:https://eslint.org/docs/rules/comma-dangle

我使用以下组合(这对我有用)

[1] .eslintrc.json

"rules": {        
        "comma-dangle": [2, "always-multiline"]         
    }

[2] JsPrettier |更漂亮

"trailingComma": "all"

结果

dispatch({
  type: LOGIN_USER,
  payload: credentials,
});