JavaScript 逗号表达式换行格式化问题

24 天前
 1140601003
var l,
        a,
        p,
        c,
        _,
        e,
        y,
        n 。
这种 JavaScript 的换行的逗号表达式,用什么工具去格式化变到一行呢
972 次点击
所在节点    程序员
17 条回复
murmur
24 天前
有 sourcemap 就直接还原,没有接反编译的活就自己干,现在调试工具单步调试不受逗号影响,是可以正确走下去的
murmur
24 天前
哦看错了,webstorm 里,js 的格式 换行与大括号-变量声明-不换行
NoManPlay
24 天前
prettier 设置
printWidth: 100, // 自动换行长度
1140601003
24 天前
@murmur 嗯嗯,我想的是变成一行,毕竟看的麻烦
1140601003
24 天前
@NoManPlay 这个我试过了,不太行。。
1140601003
24 天前
@murmur 有没有更加方便的工具哦。
1140601003
24 天前
更加轻量化的工具哦
NoManPlay
24 天前
@1140601003 #7 prettier 已经内置 vscode 了,看下你的配置
retanoj
24 天前
IDE 正则替换 (以下内容需要去掉左右方括号,注意 replace 里逗号后面有空格
find: [,\n\s+]
replace: [, ]
Xinu
24 天前
@1140601003 试试程序员利器 utools
qwq11
24 天前
npx prettier . -w
1140601003
24 天前
@NoManPlay 我回去发发
1140601003
24 天前
这俩个都不行
```json
{
"trailingComma": "all",
"printWidth": 120
}
```

```json
{
"trailingComma": "es5",
"printWidth": 120
}
```
1140601003
24 天前
@qwq11 不行
1140601003
24 天前
@retanoj 可以,还有没有更好的方法呢
angrylid
24 天前
感觉这是个 X-Y 问题,变量名单字母是 webpack 之类打包以后的代码吗?
jqtmviyu
24 天前
Prettier

"prettier.printWidth": 100, // 设置 prettier 单行输出(不折行)的(最大)长度
"prettier.proseWrap": "preserve", // 使用默认的折行标准

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/1035028

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX