对象中最后一行后的尾随逗号 [英] Trailing comma after last line in object

查看:28
本文介绍了对象中最后一行后的尾随逗号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 VS Code 中使用 Prettier.我注意到在保存时使用格式时,Prettier 每次都会在对象的最后一行添加尾随逗号.

例如,假设我有一个这样的 JS 对象:

obj = {你好你好',世界:'世界'}

Prettier 把它变成这样:

obj = {你好你好',世界:'世界',}

<块引用>

注意 'world'

后面的逗号

在设置中没有找到解决这个问题的选项.

解决方案

您可以更新 .prettierrc.json 并设置选项 trailingCommanone 像:

<代码>{"trailingComma" : "无",...}

I'm using Prettier in VS Code. I noticed that when using format on save, Prettier adds trailing commas on the last line of an object every time.

For example, let's say I had a JS object like this:

obj = {
 hello: 'hello',
 world: 'world'
}

Prettier turns it into this:

obj = {
 hello: 'hello',
 world: 'world',
}

Notice the extra comma after 'world'

Didn't find in the settings an option to fix this.

解决方案

You can update .prettierrc.json and set option trailingComma to none like:

{
  "trailingComma" : "none",
  ...
}

这篇关于对象中最后一行后的尾随逗号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆