首页 > 解决方案 > Clang-format 不使用 .clang-format 文件 ubuntu(无错误)

问题描述

我的.clang-format项目目录中有一个 .cpp 文件和构建目录。从我的终端我 cd 进入我的项目文件夹并运行clang-format -style=file -i *.cpp. 这是我的.clang-format文件。

Language: Cpp
ColumnLimit: 0
BreakBeforeBraces: GNU
BreakConstructorInitializers: AfterColon
Cpp11BracedListStyle: true
IndentCaseLabels: true
NamespaceIndentation: All
IndentWidth: 4
TabWidth: 4
UseTab: Never
DerivePointerAlignment: false
PointerAlignment: Left
IncludeBlocks: Regroup

我正在通过更改来测试功能BreakBeforeBraces,但没有任何变化。它似乎正在使用后备格式。这是怎么回事?有没有办法查看clang-format实际在做什么?

标签: c++clangclang-format

解决方案


使用 时-style=file,每个输入文件的 clang-format 将尝试查找位于输入文件最近的父目录中的 .clang-format 文件。使用标准输入时,从当前目录开始搜索。

您可以使用下面的命令查看运行目录中使用的实际配置

clang-format -style=file -dump-config

推荐阅读