简体   繁体   English

为什么 Prettier 将我的 JSON object 分成多行?

[英]Why does Prettier break up my JSON object into multiple lines?

Prettier is great, but it breaks up my javascript object into multiple lines, like so: Prettier 很棒,但它将我的 javascript object 分成多行,如下所示:

<Text
    style={
        styles.chineseText
    }
>
    {
        this.state
            .housePayload
            .sitMountain
            .chinese
    }
</Text>

I'd like the result to be something along the lines of:我希望结果类似于:

<Text
    style={
        styles.chineseText
    }
>
    { this.state.housePayload.sitMountain.chinese }
</Text>

How can I make this happen?我怎样才能做到这一点? My current config file is:我当前的配置文件是:

{
    "trailingComma": "es5",
    "tabs": true,
    "tabWidth": 4,
    "semi": false,
    "singleQuote": true
}

You should try printWidth in the config.您应该在配置中尝试printWidth The default is 80 and you can specify any number that suits you.默认值为80 ,您可以指定任何适合您的数字。 For eg:例如:

printWidth: 100

From the Doc文档

It is a way to say to Prettier roughly how long you'd like lines to be.这是一种大致告诉 Prettier 你希望线条有多长的方式。 Prettier will make both shorter and longer lines, but generally strive to meet the specified printWidth. Prettier 将制作更短和更长的线条,但通常会努力满足指定的 printWidth。

It's also important to note though:但同样重要的是要注意:

Don't try to use printWidth as if it was ESLint's max-len – they're not the same.不要尝试像使用printWidthmax-len一样使用 printWidth——它们不一样。 max-len just says what the maximum allowed line length is, but not what the generally preferred length is – which is what printWidth specifies. max-len只是说最大允许的行长度是多少,但不是通常首选的长度是多少——这是printWidth指定的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM