所以我在VSCode中使用Prettier和ESLint,每次格式化代码时,我的if语句和字符串文字中都会出现令人讨厌的新行。 我想禁用这两种方法,以查看如何编写它们,以避免最终导致多行混乱。
我尝试了所有似乎与之相关的ESLint规则:
"rules": {
"no-console": "off",
"no-debugger": "off",
"no-unused-vars": ["error", { "args": "none" }],
"eslint brace-style": [ "error", "1tbs", {"allowSingleLine": true}],
"object-property-newline": ["error", { "allowAllPropertiesOnSameLine": true}],
"array-bracket-newline": ["error", "never"],
"array-element-newline": ["error", "never"],
"function-paren-newline": ["error", "never"],
"object-curly-newline": ["error", "never"]
},
但是格式化总是会产生这种情况:
if (
confirm(
`Are you sure you want to delete the task "${
this.tasks[tid].name
}"?`
)
)
this.$delete(this.tasks, tid)
代替:
if (confirm(`Are you sure you want to delete the task "${this.tasks[tid].name}"?`))
this.$delete(this.tasks, tid)
或至少:
if (
confirm(`Are you sure you want to delete the task "${this.tasks[tid].name}"?`)
)
this.$delete(this.tasks, tid)
任何人都知道如何更改它?
在有人指出明显之处之前,我了解到它在某些方面可能看起来更好,但由于间距太大,简单的功能真的很长。尤其是字符串文字分隔。