我必须使用的 C 风格指南强制函数调用中函数参数之间没有空格(或逗号后没有空格),例如:
foo(a,5.0,"foo");
multi_line_foo(long_var_name,42.0,
43.0);
Run Code Online (Sandbox Code Playgroud)
我怎样才能用 clang-format 实现这一点?文档中描述的与间距相关的选项似乎都不适合于此。
我有以下代码,例如:
[UIView animateWithDuration:10 animations:^{
} completion:^(BOOL finished) {
}]
Run Code Online (Sandbox Code Playgroud)
当我对其应用 clang-format 时,它变成:
[UIView animateWithDuration:10 animations:^{
}
completion:^(BOOL finished){
}];
Run Code Online (Sandbox Code Playgroud)
如您所见,新行中的第二个块参数。
我的风格 :
AlignTrailingComments: true
BasedOnStyle: Chromium
BreakBeforeBraces: Allman
ColumnLimit: 0
IndentWidth: 4
TabWidth: 8
ObjCSpaceAfterProperty: true
ObjCSpaceBeforeProtocolList: true
ObjCBlockIndentWidth: 4
PointerBindsToType: false
SpacesBeforeTrailingComments: 1
SpacesInSquareBrackets: false
SpacesInContainerLiterals: false
#SpaceInEmptyParentheses: true
SpacesInParentheses: false
UseTab: Never
KeepEmptyLinesAtTheStartOfBlocks: false
#SpaceAfterCStyleCast: true
Run Code Online (Sandbox Code Playgroud) 我希望我的代码中的块之前和之后都有空行。Astyle 支持这一点(Break-Blocks)。有没有办法用 clang-format 来做到这一点?我已经知道了KeepEmptyLinesAtTheStartOfBlocks,但如果我理解正确的话,那只会保留现有的空行。
我有一个 json 文件。如果我在其上运行 clang-format ,它会将其格式化为代码(丑陋)。
{
"name" : "My great app",
"description" : "It's really cool.",
"version" : "0.0.1"
}
Run Code Online (Sandbox Code Playgroud)
如果我将 'foo = ' 放在文件的开头,那很好,但它不再是 json 了。
foo = {
"name" : "My great app",
"description" : "It's really cool.",
"version" : "0.0.1"
}
Run Code Online (Sandbox Code Playgroud)
如何获得 clang-format 来格式化 json 文件中的裸对象,如第二个示例所示?
我加入了一个现有项目,并且是第一个使用 clang-format 的团队成员。除了一些恼人的差异之外,现有的样式大部分都匹配。这是一个(另一个在这里):
folly::dynamic makeRequest(const string &response) {
return folly::dynamic::object()
("log_type", "FOO")
("src_id", "42")
("dst_id", "666")
("success", true);
}
Run Code Online (Sandbox Code Playgroud)
clang-format 坚持将其格式化为这样:
folly::dynamic makeRequest(const string &token_response) {
// using longer variable names to highlight using up the whole line lenght
return folly::dynamic::object()("log_type", "FOO")(
"src_id", somethingId)("dst_id", whateverId)("success",
sucess);
}
Run Code Online (Sandbox Code Playgroud)
在前一种风格中,我对连续行如何缩进没有强烈的感觉,只要我们每行调用一个方法即可。那可能吗?
Xcode 更新到版本 8 后。非常有用的 Alcatraz PlugIn Manager 被锁定,并且像 clang-format、突出显示所选单词出现或使用快捷方式调整字体大小等出色的实用程序都消失了。
如何重新启用 clang-format 以在源文件的任何父目录中使用模板 .clang-format 保存时格式化当前源代码文件?
我怎样才能让 clang 格式在 '<<' 和 '>>' 运算符上中断?
我尝试将 BreakBeforeBinaryOperators 设置为 All,但这在这里似乎没有任何区别。
我希望我的代码格式如下:
in >> a
>> b
>> c;
Run Code Online (Sandbox Code Playgroud)
代替
in >> a >> b >> c;
Run Code Online (Sandbox Code Playgroud) 我们尝试使用 clang-format 工具稍微美化我们的代码。
为了在我们所做的所有机器上得到统一的结果clang-format --style=llvm --dump-config,已经稍微调优并存储到 repo 中。
问题是 clang 10 和 9 似乎为我们提供了完全相同的代码的不同输出。到目前为止,我只看到了注释对齐的变化,但它仍然打破了使代码风格一致的整个想法。另一个问题是 clang 9 无法解析从 v10 转储的某些设置。
有什么方法可以确保多个版本的 clang-format 格式一致?
我的clang-format样式文件如下:
BasedOnStyle: Google
---
Language: Java
ColumnLimit: 100
BreakStringLiterals: true
BreakAfterJavaFieldAnnotations: false
BraceWrapping:
AfterCaseLabel: true
AfterClass: true
AfterControlStatement: true
AfterEnum: true
AfterFunction: true
AfterNamespace: true
AfterObjCDeclaration: true
AfterStruct: true
AfterUnion: true
AfterExternBlock: true
BeforeCatch: true
BeforeElse: true
IndentBraces: true
SplitEmptyFunction: false
SplitEmptyRecord: false
SplitEmptyNamespace: false
Run Code Online (Sandbox Code Playgroud)
考虑以下输入java代码:
public class Lambda {
void handle() {
// TODO Try a compiling example next to see if it's different with clang-format.
try {
updateTranscriptResponse = Utils.doWithRetry(
/* task */
() -> { …Run Code Online (Sandbox Code Playgroud) 当我输入一些 UTF-8 字符而不是简单的 ASCII 时,我发现 clang-format 将字符的长度视为表示的字节数,而不是终端中显示的长度。
例如:
? 存储在 3 个字节中,但在 vim 或其他编辑器中需要 2 个 ASCII 空间。
预期的格式化代码应如下所示:
#define test \
/* ?? */ \
"aa" \
"bb" \
"bb"
Run Code Online (Sandbox Code Playgroud)
但我真正得到的是如下:
#define test \
/* ?? */ \
"aa" \
"bb" \
"bb"
Run Code Online (Sandbox Code Playgroud)
如何通过某些配置获得预期结果?
clang-format ×10
c++ ×5
c ×2
xcode ×2
java ×1
javascript ×1
json ×1
llvm ×1
objective-c ×1
plugins ×1