gpt4 book ai didi

javascript - 如何防止 Visual Studio Code 将链式函数推到新行?

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:10:24 24 4
gpt4 key购买 nike

如何防止 Visual Studio Code 将链式 JavaScript 函数推送到新行,如下面的 GIF 所示:

如您所见,它使代码极难查看并将简单的 if checkin 扩展到多行。我正在使用名为 Prettier - Code Formatter 的扩展,我查看了首选项并发现了以下内容:

// Format a file on save. A formatter must be available, the file must not be 
//auto-saved, and editor must not be shutting down.
"editor.formatOnSave": false

当您点击保存时,它会完全停止格式化。我查看了其他选项,但找不到此设置。

上面的过程有名字吗?

我怎样才能保留 formatOnSave 但阻止它按原样格式化?

最佳答案

这似乎是不可配置的(不确定是否可以配置),这是来自 issue 的 Github 帖子的直接副本:

The suggested behavior of this feature has been:

  • Wrap after hitting the line length limit
  • Wrap after 3 chained methods
  • Wrap after a configurable number of chained methods
  • Wrap when one of two conditions is met:
    • The line length limit is reached
    • The user opts into it by manually inserting a newline, like object literals

The initial implementation was (1).

The current implementation is (2).

(3) is unlikely to happen since prettier tries to avoid configuration.

The consensus is against (4) due to wanting to minimize user input influence in prettier's output.

I think the current implementation (2) makes sense in the majority of cases, but I find myself wanting (4) often enough that I no longer use prettier for JS.

基于此,目前没有办法修改此行为,也没有任何计划(截至撰写本文时)。

绝对不是我想要的答案,但这是给出的答案。

关于javascript - 如何防止 Visual Studio Code 将链式函数推到新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49755460/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com