为什么这会触发 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,
});
它期望在结尾有一个 ,
。
使用下面的规则来避免它
rules: {
'comma-dangle': ['error', 'never']
}
//或
"comma-dangle": ["error", {
"arrays": "never",
"objects": "never",
"imports": "never",
"exports": "never",
"functions": "never"
}]
我使用以下组合(这对我有用)
[1] .eslintrc.json
"rules": {
"comma-dangle": [2, "always-multiline"]
}
[2] JsPrettier |更漂亮
"trailingComma": "all"
结果
dispatch({
type: LOGIN_USER,
payload: credentials,
});
这在我看来是正确的,但为什么 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,
});
它期望在结尾有一个 ,
。
使用下面的规则来避免它
rules: {
'comma-dangle': ['error', 'never']
}
//或
"comma-dangle": ["error", {
"arrays": "never",
"objects": "never",
"imports": "never",
"exports": "never",
"functions": "never"
}]
我使用以下组合(这对我有用)
[1] .eslintrc.json
"rules": {
"comma-dangle": [2, "always-multiline"]
}
[2] JsPrettier |更漂亮
"trailingComma": "all"
结果
dispatch({
type: LOGIN_USER,
payload: credentials,
});