[英]VSCode is auto-formatting multiline to one line code
I like auto-formatting code idea very much.我非常喜欢自动格式化代码的想法。 You can use eslint rules to configure code style you like.你可以使用 eslint 规则来配置你喜欢的代码风格。 But some hidden rule makes what I don't like: inlines document destruction props or jsx template element attributes.但是一些隐藏的规则使我不喜欢:内联文档销毁道具或 jsx 模板元素属性。
Example (this is how I want it to be).示例(这就是我想要的样子)。
const {
foo: 1,
bar: 2,
baz: 3,
} = require('qux')
And here is how it is reformatted by VSCode or some its plugin (not sure)这是 VSCode 或它的一些插件重新格式化的方式(不确定)
const { foo: 1, bar: 2, baz: 3 } = require('qux')
It is absolutely OK in case it is reformatted back to multiline when the line lenth exceeds some specified limit.当行长度超过某个指定的限制时,它被重新格式化回多行是绝对可以的。
JSX examples (tried with a new project generated with use of react-create-app
). JSX 示例(尝试使用react-create-app
生成的新项目)。
OK, it would be too long line, thus VSCode re-formats it to multiline好吧,这行太长了,因此 VSCode 将其重新格式化为多行
<a className="App-link" href="https://reactjs.org" target="_blank" rel="noopener noreferrer" >
Line length wouldn't be longer than allowed, but I still love this style线条长度不会超过允许的长度,但我仍然喜欢这种风格
<a className="App-link" href="https://reactjs.org" >
But VSCode/plugin has a different preference and reformats it to但是 VSCode/plugin 有不同的偏好并将其重新格式化为
<a className="App-link" href="https://reactjs.org">
I tried to find a specific eslint rule which would be responsible for this behavior, but with no luck (not found).我试图找到一个特定的 eslint 规则来负责这种行为,但没有运气(未找到)。 I tried to change default vscode formatter from prettier
to null
- no luck.我试图将默认的 vscode 格式化程序从prettier
更改为null
- 不走运。
One more strange thing for me: VSCode doesn't highlights such code snippets which it is going to reformat.对我来说还有一件奇怪的事情:VSCode 没有突出显示将要重新格式化的代码片段。
So how can it be fixed?那么如何修复呢?
UPDATE更新
The only thing I want VSCode to do within such code parts, is just breaking one line to multiline in case the line exceeds eslint
max-len
value.我希望 VSCode 在这些代码部分中做的唯一一件事就是将一行中断到多行,以防该行超过eslint
max-len
值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.