我想更漂亮地关闭规则,在该规则中添加内联注释。我的ESLint规则no-inline-comments
被设置为off或warn,因此可以正常工作。事实证明,Prettier仍然想换行和内联注释:
我在VSCode中进行了设置,其中ESLint正在处理JS的漂亮语言,而Prettier扩展名正在处理所有其他语言。我还使用了airbnb-base
。这是我相关的配置:
.eslintrc.json
:
{
"extends": ["airbnb-base", "plugin:prettier/recommended"],
"rules": {
"no-console": 0,
"no-plusplus": 0,
"no-inline-comments": "off",
"no-undef": "warn",
"no-use-before-define": "warn",
"no-restricted-syntax": [
"warn",
{
"selector": "ForOfStatement",
"message": "frowned upon using For...Of"
}
]
// "line-comment-position": ["warn", { "position": "above" }]
},
"env": {
"browser": true,
"webextensions": true
}
}
VSCode settings.json
:
// all auto-save configs
"editor.formatOnSave": true,
// turn off for native beautifyjs
"[javascript]": {
"editor.formatOnSave": false
},
"eslint.autoFixOnSave": true,
"eslint.alwaysShowStatus": true,
"prettier.disableLanguages": ["js"],
"prettier.trailingComma": "es5"
}
我知道您可以在要忽略的内容上方执行// eslint-disable-next-line prettier/prettier
,但是我显然不想每次都设置该值。您可以在上面的图片中看到它的注释。
通常,将注释放在自己的行而不是行尾时,可获得最佳结果。将
// eslint-disable-next-line
优先于// eslint-disable-line
。
https://prettier.io/docs/en/rationale.html#comments
我不确定这在这种情况下是否有用?
我和几个人交谈过,可能甚至不可能吗?不过,这是某处的规则,应该可以忽略。如果还有其他我可以提供的信息。注意:虽然可以通过ESLint配置文件将选项传递给Prettier,但不建议这样做,因为
prettier-atom
和prettier-vscode
这样的编辑器扩展名将读为.prettierrc
,但会赢得不会从ESLint中读取设置,这可能会导致不一致的体验。