Uncrustify:删除 ObjC 代码中的双空行和更多空行

Uncrustify: Remove double and more empty lines in ObjC code

所以基本上我有这样的代码:

NSString *const SomeKey = @"SomeKey";


@implementation SomeClass


- (void)doSomeWork {
    [self startDoingSomeWork];



    [self stopDoingSomeWork];
    [self notifySomeWorkDone];
}

我需要将此代码自动格式化为这种形式:

NSString *const SomeKey = @"SomeKey";

@implementation SomeClass

- (void)doSomeWork {
    [self startDoingSomeWork];

    [self stopDoingSomeWork];
    [self notifySomeWorkDone];
}

所以基本上我需要用单个空行替换所有双倍、三倍等空行。

是否有任何 Uncrustify 选项可以启用它?
如果否,那么您知道这种情况的解决方法吗?

如果 Uncrustify 不支持该功能,您可以尝试 ClangFormat。

MaxEmptyLinesToKeep: 1 最多保留 1 个空行。

来源:Line breaks between function definitions

最后我找到了正确的选项。
只需将此行添加到您的配置文件中:

nl_max = 2