【问题标题】:EditorConfig - Convert tabs to spaces in SQL files transparentlyEditorConfig - 透明地将 SQL 文件中的制表符转换为空格
【发布时间】:2022-07-06 05:12:45
【问题描述】:

我正在处理的项目中有一组.sql 脚本,其中当前包含用于缩进的制表符和空格的组合。我想找到一种自动透明将这些制表符转换为空格文件保存的方法。如果自动格式化在 VS Code 和 Visual Studio 中都能正常工作,那就太好了。

我尝试过这样的 EditorConfig (.editorconfig) 文件:

root = true

# Enforce 4 space indenting and NO tabs in SQL script files
[*.sql]
end_of_line = crlf
indent_size = 4
indent_style = space

但它似乎不起作用。即使我在 VS Code 或 Visual Studio 中尝试手动“格式化文档”选项,也没有任何反应。我也尝试设置 Prettier VS Code 扩展,但我也无法让它工作。

首先,这是否可以使用 EditorConfig,如果不能,我该如何实现?

【问题讨论】:

    标签: sql visual-studio visual-studio-code format editorconfig


    【解决方案1】:

    您有几个选项,“最佳”选项取决于您要使用的 SQL 方言。

    1. RedGate SQL Toolbelt 和 SQL Toolbelt Essentials 包含 RedGate SQL Prompt 的命令行版本,它将为您格式化代码。有关使用 SqlPrompt.Format.CommandLine.exe 的说明,请参阅:https://documentation.red-gate.com/sp/features-available-only-in-sql-toolbelt-essentials-and-sql-toolbelt/bulk-operations/bulk-operations-via-the-command-line
    2. vscode-sql-formatter 插件,处理以下方言选项:
      1. sql:标准 SQL。 默认为 sql。
      2. n1ql:沙发底座 N1QL
      3. db2:IBM DB2
      4. pl/sql:Oracle PL/SQL)。

    SQL Server Management Studio 不支持 .editorconfig,Microsoft Azure Data Studio 支持 .editorconfig 的唯一功能请求已被 Microsoft 关闭,称其优先级太低,以至于他们甚至都懒得审核。我认为透明度很好,因为他们对客户非常诚实,提供免费的 SQL 格式化工具不是他们的优先事项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2014-01-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-11
      • 2014-01-07
      相关资源
      最近更新 更多