CLANG 格式不对主文件进行排序
clang-format not sorting main file
我对我的.clang-format
文件有以下定义:
---
BasedOnStyle: LLVM
AccessModifierOffset: -4
AlignAfterOpenBracket: Align
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignConsecutiveMacros: false
AlignEscapedNewlines: Left
AlignOperands: true
AlignTrailingComments: false
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: true
AllowShortCaseLabelsOnASingleLine: false
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: true
AllowShortLambdasOnASingleLine: Inline
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: MultiLine
BinPackArguments: true
BinPackParameters: false
BreakBeforeBinaryOperators: None
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: true
BeforeElse: true
IndentBraces: false
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
BreakBeforeTernaryOperators: false
BreakConstructorInitializers: AfterColon
BreakConstructorInitializersBeforeComma: false
BreakInheritanceList: AfterColon
BreakStringLiterals: true
ColumnLimit: 0
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: true
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: true
DeriveLineEnding: false
DerivePointerAlignment: false
FixNamespaceComments: true
IncludeBlocks: Regroup
IncludeCategories:
- Regex: '^<'
Priority: -1
- Regex: '^"(gtest|gmock)/'
Priority: 1
- Regex: '^"boost/'
Priority: 2
# Other rules ...
- Regex: '^"tools/'
Priority: 14
- Regex: '^"[w]+/'
Priority: 15
- Regex: '.*'
Priority: 16
IndentCaseLabels: true
IndentGotoLabels: false
IndentPPDirectives: None
IndentWidth: 4
IndentWrappedFunctionNames: false
KeepEmptyLinesAtTheStartOfBlocks: true
Language: Cpp
MaxEmptyLinesToKeep: 1
NamespaceIndentation: All
PointerAlignment: Left
ReflowComments: true
SortIncludes: true
SortUsingDeclarations: true
SpaceAfterCStyleCast: true
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: true
SpaceBeforeAssignmentOperators: true
SpaceBeforeCpp11BracedList: true
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 1
SpacesInAngles: false
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Cpp11
TabWidth: 4
UseTab: Never
...
头文件的排序效果很好,除了文件到主包含映射。主文件按规则 16 排序,因此始终出现在末尾。
我尝试删除包含文件的排序(即注释掉参数IncludeBlocks
和IncludeCategories
,但它仍然不起作用。我认为由于回退样式是LLVM,因此它至少在这种情况下可以工作。
如果我不使用我的文件,而是在命令行中指定-style=llvm
,则主文件的排序有效。
我在 Debian 10 上使用 VS Code 1.45.1,扩展名为xaver
的 Clang-Format。可执行文件clang-format
版本为 10.0.0。
有人有什么建议吗?
-
您的
.clang-format
文件缺少IncludeIsMainRegex
设置。通常我希望它默认为合理的设置,并且一切都会正常工作。但是考虑到你的问题,你应该确保它没有设置在某个地方(也许你正在使用与你想象的不同.clang-format
文件?或者你的clang-format
可执行文件以某种方式被修改了?(。默认设置为
IncludeIsMainRegex: '(Test)?$'
。其他合理的值可能是'([-_](test|unittest))?$'
(与预定义的Google和Chromium样式使用的值相匹配(,'$'
(表示没有额外的文件名后缀(或''
(表示任何文件名后缀(。有关详细信息,请参阅文档。 -
当
xaver
的Clang-Format
扩展名运行clang-format
可执行文件时,它是否在命令行上提供文件名?或者,也许,它将文件流式传输到stdin
?如果是后者,那么clang-format
将不知道文件名,因此无法检测到哪个包含文件是"主"包含文件。可以处理的一种方法是使用-assume-filename
命令行选项(在此处记录(,但当然这取决于扩展。 -
最后,请记住,"主"包含文件按优先级排序
0
。您的IncludeCategories
设置包含所有以 开头的包含文件<
按优先级-1
排序,因此它们将在"主"包含文件之前排序。
- 如何使用 samtools C API 构建一个简单的主.cpp文件
- 如何正确定义C++类析构函数并将其链接到主文件?
- 链接外部C++外部C++ 在主文件中?
- 为什么我的主文件.cpp不打印头文件中的任何内容
- 重定向输入和输出时如何处理主文件I/O?
- 当我从头文件和实现文件调用我的函数到我的主文件时,我没有得到任何输出
- 在排序文本文件中实现二叉搜索?
- 如何将 Cython 生成的模块从 python 导入到 C/C++ 主文件?(C/C++编程)
- 标题和INT主文件
- 关于 Linux .so 文件无法链接到主文件.cpp文件
- 如何在单个 Visual Studio 2010 项目中执行多个主文件
- 在C++中使用结构的头文件、初始化文件和主文件
- 从文件中读取矩阵,将其提供给主文件
- 如何使用 C++ 读取 NTFS 主文件表
- 按行解析和排序 csv 文件
- 排序大文件的时间优于0(n log n)
- 如何在单独的cpp文件中通过头文件调用函数到主文件
- c++就地排序索引文件(使用堆排序)
- 将程序拆分为头文件和主文件
- 我的主C++文件中的文本(在尚未执行的代码中)如何显示在字符串中?