V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
1140601003
V2EX  ›  程序员

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

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

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

    "prettier.printWidth": 100, // 设置 prettier 单行输出(不折行)的(最大)长度
    "prettier.proseWrap": "preserve", // 使用默认的折行标准
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   823 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 22:29 · PVG 06:29 · LAX 15:29 · JFK 18:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.