为什么 Prettier 将我的 JSON 对象分成多行?
Why does Prettier break up my JSON object into multiple lines?
Prettier 很棒,但它将我的 javascript 对象分解成多行,如下所示:
<Text
style={
styles.chineseText
}
>
{
this.state
.housePayload
.sitMountain
.chinese
}
</Text>
我希望结果类似于 :
<Text
style={
styles.chineseText
}
>
{ this.state.housePayload.sitMountain.chinese }
</Text>
我怎样才能做到这一点?我当前的配置文件是:
{
"trailingComma": "es5",
"tabs": true,
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
您应该在配置中尝试 printWidth
。默认值为 80
,您可以指定任何适合您的数字。例如:
printWidth: 100
来自Doc
It is a way to say to Prettier roughly how long you’d like lines to
be. Prettier will make both shorter and longer lines, but generally
strive to meet the specified printWidth.
不过还需要注意的是:
Don't try to use printWidth
as if it was ESLint’s max-len
– they’re
not the same. max-len
just says what the maximum allowed line length
is, but not what the generally preferred length is – which is what
printWidth
specifies.
Prettier 很棒,但它将我的 javascript 对象分解成多行,如下所示:
<Text
style={
styles.chineseText
}
>
{
this.state
.housePayload
.sitMountain
.chinese
}
</Text>
我希望结果类似于 :
<Text
style={
styles.chineseText
}
>
{ this.state.housePayload.sitMountain.chinese }
</Text>
我怎样才能做到这一点?我当前的配置文件是:
{
"trailingComma": "es5",
"tabs": true,
"tabWidth": 4,
"semi": false,
"singleQuote": true
}
您应该在配置中尝试 printWidth
。默认值为 80
,您可以指定任何适合您的数字。例如:
printWidth: 100
来自Doc
It is a way to say to Prettier roughly how long you’d like lines to be. Prettier will make both shorter and longer lines, but generally strive to meet the specified printWidth.
不过还需要注意的是:
Don't try to use
printWidth
as if it was ESLint’smax-len
– they’re not the same.max-len
just says what the maximum allowed line length is, but not what the generally preferred length is – which is whatprintWidth
specifies.