Svelte for VS代码:如何避免格式化属性中的双引号?
我正在使用 vs code for vs code 扩展。
当前格式化时,它删除了HTML属性中的双引号
示例:
export let altText;
<img src="test.jpg" alt="{altText}" />
格式化时,它将其变成类似的东西
export let altText;
<img src="test.jpg" alt={altText} />
,这是完全有效的。但是,我想将报价保留在属性中。有什么办法做到这一点吗?
I'm using Svelte for VS Code extension.
Currently when formatting it removes double quotes in HTML attributes
Example:
export let altText;
<img src="test.jpg" alt="{altText}" />
when formatted it turns it into something like this
export let altText;
<img src="test.jpg" alt={altText} />
Which is totally valid. However, I want to keep the quotes in the attributes. Is there any way to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
扩展名使用 Prettier (这很烦人)。您可以通过添加
.prettierrc
并设置quoteprops
选项“ preserve”
。编辑:对此进行了测试,目前是 not 尊重的。
Svelte的插件具有设置a 严格模式 ,要么通过VS设置:
或通过
.prettierrc
(如果存在文件,则忽略VS设置):将保留引号,但也会杀死速记,因此
这
The extension uses Prettier (which is annoying). You might be able to configure this by adding a
.prettierrc
and setting thequoteProps
option to"preserve"
.Edit: Tested this, and it is currently not respected.
The plugin for Svelte has an option for setting a strict mode, either via the VS settings:
Or via the
.prettierrc
(the VS setting is ignored if the file exists):This will preserve the quotes but also kill shorthands, so e.g. from
To