Visual studio 2015 如何使铿锵格式的Visual Studio 2015扩展名不与if语句放在同一行上

Visual studio 2015 如何使铿锵格式的Visual Studio 2015扩展名不与if语句放在同一行上,visual-studio-2015,clang-format,Visual Studio 2015,Clang Format,在我看来,对于大括号是可选的任何语言,将大括号放在if语句的同一行都是不可取的。请考虑以下内容: if (VeryLongConditionThatIsWiderThanScreen) { // Thousands of lines of badly indented code. // You cannot rely on indentation to tell you were the block ends. } 如果大括号位于If语句的末尾,我必须搜索并按end键来确定代码块的结束位置。我

在我看来,对于大括号是可选的任何语言,将大括号放在if语句的同一行都是不可取的。请考虑以下内容:

if (VeryLongConditionThatIsWiderThanScreen) {
// Thousands of lines of badly indented code.
// You cannot rely on indentation to tell you were the block ends.
}
如果大括号位于If语句的末尾,我必须搜索并按end键来确定代码块的结束位置。我讨厌那样做。我是一个视力很差的打猎和啄食打字员,我需要付出相当大的努力才能找到结束键,这样我才能找到代码块的结束位置

我尝试使用ClangFormat格式,使用ClangFormat Visual Studio 2015扩展,但我坚持认为它不会将大括号与if放在同一行上。所有内置样式都可以。我在上阅读了文档,并编写了以下.clang格式的文件

---
Language: Cpp
BasedOnStyle: WebKit
AlignAfterOpenBracket: AlwaysBreak
AllowShortBlocksOnASingleLine: true
AllowShortIfStatementsOnASingleLine: true
AllowShortLoopsOnASingleLine: true
AlwaysBreakBeforeMultilineStrings: true
BinPackArguments: false
BinPackParameters: false
BraceWrapping:
    AfterControlStatement: true
    AfterEnum: true
    AfterStruct: true
    AfterUnion: true
    BeforeCatch: true
    BeforeElse: true
BreakBeforeBraces: Custom
BreakBeforeInheritanceComma: true
ColumnLimit: 100
ConstructorInitializerAllOnOneLineOrOnePerLine: true
Cpp11BracedListStyle: true
IndentWidth: 2
SortIncludes: false
TabWidth: 2
...

如果我正确地解释了文档,那么将AfterControlStatement设置为true应该会导致clangformat将大括号放在If后面的行上,这就是我想要的。这并没有发生。我已将.clang格式文件与项目文件放在同一目录中。我还试着把它命名为“铿锵格式”。什么都不管用。每次我使用“铿锵格式文档”菜单项时,它都会将与if语句关联的所有大括号与if放在同一行上。

结果表明,我的问题是由AllowShortLoopsOnASingleLine和AllowShortBlocksOnASingleLine设置为true引起的

这一问题报告为

我最终使用以下.clang格式文件来实现我的目标

---
Language: Cpp
BasedOnStyle: WebKit
AccessModifierOffset: -2
AlignAfterOpenBracket: AlwaysBreak
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: true
AlwaysBreakBeforeMultilineStrings: true
BreakBeforeBraces: Custom
BraceWrapping:
  AfterClass: true
  AfterControlStatement: true
  AfterEnum: true
  AfterFunction: true
  AfterNamespace: false
  AfterObjCDeclaration: true
  AfterStruct: true
  AfterUnion: true
  BeforeCatch: true
  BeforeElse: true
  IndentBraces: false
ColumnLimit: 100
ConstructorInitializerIndentWidth: 2
ContinuationIndentWidth: 2
Cpp11BracedListStyle: true
IndentWidth: 2
KeepEmptyLinesAtTheStartOfBlocks: false
PointerAlignment: Right
SortIncludes: false
SpacesInContainerLiterals: false
TabWidth: 2
UseTab: ForContinuationAndIndentation
...

我认为以下错误可能与我的问题有关:。