Clang Format 正在删除空行上的所有缩进空格

Clang Format is removing all the indent spaces on my empty lines

我正在 运行宁 _clang-format 文件使用 BBUncrustifyPlugin 用于 Xcode。

在Xcode中,每当我换行时,它都会保留缩进空格。 (空格显示为•) 像这样:

if(YES) { 
••••NSInteger myNum = 2;
••••
••••myNum = 4;
}

当我 运行 我的 _clang-format 文件时,它从我的代码中删除了空格,所以现在它看起来像这样:

if(YES) { 
••••NSInteger myNum = 2;

••••myNum = 4;
}

没什么大不了的,但它确实会导致恼人的提交更改,因为每个换行符都会删除空格。更不用说如果我回去编辑文件,我更希望那些空间已经存在。

我似乎找不到可以帮助我解决此问题的 _clang-format 密钥。有帮助吗?

这是我当前的 _clang-format 文件

BasedOnStyle: Chromium,
AlignTrailingComments: true,
BreakBeforeBraces: Linux,
ColumnLimit: 140,
IndentWidth: 4,
KeepEmptyLinesAtTheStartOfBlocks: false,
ObjCBlockIndentWidth: 4,
ObjCSpaceAfterProperty: true,
ObjCSpaceBeforeProtocolList: true,
PointerBindsToType: false,
SpacesBeforeTrailingComments: 1,
TabWidth: 8,
MaxEmptyLinesToKeep: 2,
UseTab: Never,

谢谢。

您正在寻找的是一个禁用尾随空格删除的选项。但是,clang-format 似乎没有 option。但是,您可以在 Xcode 中设置一个选项以自动删除尾随空格。 (它在 Xcode 首选项中;不幸的是,我现在不在 Mac 上,所以我无法为您获取屏幕截图。)

虽然这不能解决您的 clang 格式问题,但它可能仍能解决您的问题。您可以通过选中 Preferences > Text Editing:

中的两个选项来制作 Xcode trim 空格
While Editing:   ☑ Automatically trim trailing spaces  
                   ☑ Including whitespace-only lines