[英]ESLint RC rule not working, while rule comment works and other rules do
When I use this comment with the following code, it reformats the code:当我将此注释与以下代码一起使用时,它会重新格式化代码:
/*eslint object-property-newline: "error"*/
const obj1 = { foo: 'foo', bar: 'bar', baz: 'baz' };
However, when I add this line to my ESLint RC file instead, it doesn't reformat, while other rules seems to apply.但是,当我将此行添加到我的 ESLint RC 文件时,它不会重新格式化,而其他规则似乎适用。
rules: {
'object-property-newline': 'error',
'other rules': 'warn',
// ...
}
Does anyone have an idea?有人有想法吗?
Edit - For example, this rule does apply:编辑 - 例如,此规则确实适用:
'object-curly-newline': ["error", "always"],
If I add this code:如果我添加此代码:
var x = { xs: 1, xy: 2, greg: 3 };
And save the file, it changes to:并保存文件,它更改为:
const x = {
xs: 1, xy: 2, greg: 3,
};
But I want every object property on a new line, which I hope to achieve with 'object-property-newline': 'error',
.但我希望每个 object 属性都在一个新行上,我希望通过
'object-property-newline': 'error',
来实现。
https://eslint.org/docs/rules/object-property-newline https://eslint.org/docs/rules/object-property-newline
I found out that adding allowAllPropertiesOnSameLine
and setting it to false
is necessary, even though I thought that would be the default option.我发现添加
allowAllPropertiesOnSameLine
并将其设置为false
是必要的,即使我认为这将是默认选项。
'object-property-newline': ["error", { "allowAllPropertiesOnSameLine": false }],
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.