【问题标题】:how can I use --dry-run option in clang-format?如何以 clang 格式使用 --dry-run 选项?
【发布时间】:2021-02-20 17:22:54
【问题描述】:

我的操作系统是 ubuntu 16.04,我想使用 clang-format 中包含的 --dry-run 选项。 但是当我在终端上写 clang-format --help 时,它没有 --dry-run 选项。 我猜这是因为版本。当我写sudo apt-get install clang-format 时,我向我展示了安装clang-format-3.8。 所以我想知道

  1. clang-format 没有--dry-run 选项的原因是因为版本? 2-1。如果第一个问题是肯定的,有什么方法可以安装超过 10 的 clang 格式版本? 2-2。如果第一个问题是否定的,我该如何使用 --dry-run 选项?

【问题讨论】:

    标签: clang clang-format


    【解决方案1】:

    clang-format 没有 --dry-run 选项的原因是版本原因?

    是的,--dry-run 已添加 in Nov 2019 当 Clang 10.0.0 出来的时候。

    如果第一个问题是肯定的,有什么方法可以安装 超过 10 的 clang 格式版本

    您可以将 Ubuntu 安装升级为 clang-format 10 是available in newer systems 或手动构建它,但现在是最简单和最喜欢的方式 是跑官方Ubuntu docker image

    $ docker run -it ubuntu
    root@502d5d8cfb26:/# head -n2 /etc/os-release 
    NAME="Ubuntu"
    VERSION="20.04.1 LTS (Focal Fossa)"
    root@502d5d8cfb26:/# apt-get update
    root@502d5d8cfb26:/# apt-get -y install clang-format
    root@502d5d8cfb26:/# clang-format --version
    clang-format version 10.0.0-4ubuntu1
    root@502d5d8cfb26:/# clang-format --help | grep -- '--dry-run'
      --dry-run                  - If set, do not actually make the formatting changes
      --ferror-limit=<uint>      - Set the maximum number of clang-format errors to emit before stopping (0 = no limit). Used only with --dry-run or -n
      -n                         - Alias for --dry-run
    

    【讨论】:

    • 哇!多谢。实际上我在Windows上安装了它。但我会尝试你的建议,非常感谢。如果你知道詹金斯,你能回答我的另一个问题吗?如果可以的话,我真的很感激
    • 哇.. 非常感谢!!实际上我安装在 Windows 上,但我会尝试你的建议。如果您了解詹金斯,您能帮我解决另一个问题吗?我真的是新 jenkins 和 clang-format,所以我真的很困惑.. stackoverflow.com/questions/66299757/…
    • 在 StackOverflow 上,您接受答案表示感谢。见What should I do when someone answers my question?
    猜你喜欢
    • 2010-10-04
    • 2021-01-24
    • 2013-06-17
    • 2014-05-29
    • 1970-01-01
    • 1970-01-01
    • 2016-12-28
    • 2018-07-28
    相关资源
    最近更新 更多