【问题标题】:Prettier or VSCode formatting with unwanted behavior. Adding {' '}带有不需要的行为的更漂亮或 VSCode 格式。添加 {' '}
【发布时间】:2020-06-26 17:27:23
【问题描述】:

我对 prettier 有疑问。代码会以不想要的方式格式化。

我该如何解决这个问题?

我检查了更漂亮的文档并尝试通过设置配置。 在将格式应用于 图 A 后,会出现不需要的格式行为,其中会添加 {' '} 大括号,其中包含单引号空格。见图B

<h1 className='title'>
     Read <Link href="/posts/first-post"><a>this page!</a></Link>
</h1>

Read{' '}
   <Link href='/posts/first-post'>
     <a>this page!</a>
   </Link>

【问题讨论】:

  • 你能说说你在处理什么类型的文件(语言/框架)

标签: visual-studio-code format prettier


【解决方案1】:

这就是 JSX 中空格的工作原理。看到这个问题:Best practice when adding whitespace in JSX

如果 Prettier 拆分行而不在大括号中添加空格,则代码的输出将更改:Readt̲h̲i̲s̲ 而不是 Read t̲h̲i̲s̲

【讨论】:

    猜你喜欢
    • 2021-08-14
    • 2020-04-24
    • 1970-01-01
    • 2020-08-10
    • 1970-01-01
    • 2020-03-30
    • 2023-03-12
    • 2020-09-15
    • 2018-12-01
    相关资源
    最近更新 更多