似乎SwiftLint对于任何单个字符(.
)都有点脆弱,所以我得到的最接近的是这个
custom_rules:
newline_block:
name: "Newline Block"
regex: "\\{[ ]*(\\S|( +))+[ ]*\\}"
message: "Statement must be on its own line"
更好的正则表达式应该是{[ ]*(.+)+[ ]*}
(未替换),但由于某种原因,当我在Xcode上运行它时,它不起作用.
这可以满足您的打印请求,但该解决方案确实存在一些缺点:
func foo() {
// No warning
if true {}
// Newline Block Violation: Statement must be on its own line (newline_block)
if true { }
}
但我不确定这是否也适用于你:
var connection: OpaquePointer? {
// Newline Block Violation: Statement must be on its own line
get { queue.sync { underlyingConnection } }
// Newline Block Violation: Statement must be on its own line
set { queue.sync { underlyingConnection = newValue } }
}