gpt4 book ai didi

visual-studio-code - 如何在 VSCode 中从 "format on save"中排除一个特定文件?

转载 作者:行者123 更新时间:2023-12-05 06:47:46 26 4
gpt4 key购买 nike

a question about suppressing editor.formatOnSave for specific file extensions (languages)但我有一个不同的问题:如何在我的工作区中为一个特定文件抑制此功能?

我想以某种方式在存储库 中抑制它,在注释中使用配置或提示等,这样我就可以防止任何人不小心做错了。我不能告诉我 20 多岁的队友总是“不格式化就保存”,我自己也不能一直记住这一点。

我有一个 ./vscode/settings.json 文件,其中包含:

"editor.formatOnSave": true,

它对我工作区中的所有文件都非常有效。但是,我想为我的 app-routing.module.ts 文件(它是一个 Angular 项目)抑制它,因为那里的自动格式化对可读性的伤害大于它的帮助。

如何为一个特定文件禁用 editor.formatOnSave

当我或同事使用“保存”(CTRL + S 在 Windows 上)或“全部保存”(CTRL + K, S 在 Windows 上)时自动格式化不应为该文件触发


我尝试过的:

  • 检查所有答案 in the related question (例如 [javascript]": { "editor.formatOnSave": false }
  • 在子文件夹中有一个 .vscode/settings.json 文件夹,但是 that's not supported
  • 在我的文件中包含 /* eslint-disable prettier/prettier */(AFAIK prettier 是我的 TypeScript 文件格式化程序),然后通读 this open prettier issue on GitHub
  • 创建一个.prettierignore 文件并添加我的文件

这些都不起作用。

最佳答案

只需将您的文件保存为:

  • ControlK 然后 S 在 Linux 和 Windows 上
  • ⌘ 命令K 然后 S 在 Mac 上

关于visual-studio-code - 如何在 VSCode 中从 "format on save"中排除一个特定文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66967959/

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