【发布时间】:2021-02-26 18:54:16
【问题描述】:
我在 Xcode (swift) 上有一个函数,它返回一个很长的数组,即每行一个字。喜欢
static func en() -> [String] {
[
"a",
"about",
"above",
"after",
"again",
"against",
"all",
"am",
...
当我尝试编译时,我得到:
Function Body Length Violation: Function body should span 40 lines or less excluding comments and whitespace: currently spans 175 lines (function_body_length)
如果我尝试删除换行符并添加空格,我会得到这个
Line Length Violation: Line should be 120 characters or less: currently 1492 characters (line_length)
我认为问题出在 SwiftLint。
我该如何解决这个问题?如何禁用此错误。
【问题讨论】:
-
你想达到什么目的?
-
也许在几行上有几个项目? 120 行中的 1492 个字符给出 13 行。如果考虑到 4.7 的平均英语单词长度,导致平均不安全标记长度为 6.7,避免破坏标记可能会平均增加 88 个字符,因此第 14 行。鉴于 175 行的限制,您仍有足够的利润空间。但我不会回答这个问题,因为独立于这个底层代码,看看是否以及如何规避这些限制是很有趣的。
-
由于它们似乎是来自 SwiftLint 的错误,您可以在文件中为带有注释标记的问题区域禁用 linter,例如
// swiftlint:disable function_body_length。见github.com/realm/SwiftLint -
此外,您还可以在这里找到一些关于自定义规则的附加信息:stackoverflow.com/q/48965916/3723423
-
@WarrenBurton - 我在哪里添加这个?我这里说的是 Xcode。