很多人都在用的是:
{
"brace_style": "none,preserve-inline",
"indent_size": 2,
"indent_char": " ",
"jslint_happy": true,
"unformatted": [""],
"css": {
"indent_size": 2
}
}
会影响到列表和大括号换行的设置最关键的就是
brace_style
。
这里 none 的意思是针对列表和大括号不做处理,保持原样,也就是当:
[
{
"x": "x"
},
{
"x": "x"
}
]
或
[{
"x": "x"
},
{
"x": "x"
}]
均不会处理列表和大括号
[{
之间的换行。
如果设置为 expand ,会自动做换行处理,也就是均变为如下格式:
[
{
"x": "x"
},
{
"x": "x"
}
]
可见默认会换行的体验感是比设定为 none 要好的。
使用 preserve-inline 是为了避免多行的情况,比如:
import { a, b } from c
会格式化成:
import {
a,
b
} from c
使用了 preserve-inline 就不会发生这种情况。
也就是说建议设定为:
另外,可以直接在 settings.json 里配置全局,没有必要每个文件夹都建立
.jsbeautifyrc
文件:
"beautify.config": {
"brace_style": "expand,preserve-inline",
"indent_size": 2,
"indent_char": " ",
"jslint_happy": true,
"unformatted": [""],
"css": {
"indent_size": 2
}
}
附:官方配置说明