prettier 覆盖 eslint array-bracket-spacing 规则
ESlint 在数组括号内添加空格,更漂亮地删除它们。
我使用带有 ESLint 和 Prettier 扩展的 vscodium。 index.js中运行命令
{
"lint": "eslint --fix ./index.js && prettier --write ./index.js"
}
我在 package.json: .eslint.json:
{
"env": {
"browser": true,
"es2021": true
},
"extends": ["prettier"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"no-console": "off",
"array-bracket-spacing": ["error", "always"] // the rule
}
}
:
const myTestFunction = () => {
const [num1] = [1, 3]; // the error
//const [ num1 ] = [ 1, 3 ]; // expected
return console.log(num1);
};
myTestFunction();
ESlint adds spaces inside array brackets, prettier removes them.
I use vscodium with ESLint and Prettier extensions. I run the command in package.json:
{
"lint": "eslint --fix ./index.js && prettier --write ./index.js"
}
.eslint.json:
{
"env": {
"browser": true,
"es2021": true
},
"extends": ["prettier"],
"parserOptions": {
"ecmaVersion": "latest",
"sourceType": "module"
},
"rules": {
"no-console": "off",
"array-bracket-spacing": ["error", "always"] // the rule
}
}
index.js:
const myTestFunction = () => {
const [num1] = [1, 3]; // the error
//const [ num1 ] = [ 1, 3 ]; // expected
return console.log(num1);
};
myTestFunction();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 Prettier 删除了数组括号内的空格,因此可以修改 ESLint 以接受这一点。
可以从 .eslintrc.json 中删除该选项,例如:
Since Prettier removes spacing inside array brackets, ESLint can be modified to accept this.
This option can be deleted from .eslintrc.json, for example: