11

如何解决线路长度违规?

由于行长度违规而不允许的警报消息的相关部分: message: NSLocalizedString("\nYou will be requested to Use %@ to Sign In. %@ doesn't share any information about you. The permission is required to post your Live Video.", ⚠ 行应为 120 个字符或更少:当前为 208 个字符 (line_length)

4

3 回答 3

29

使行更短:

message: NSLocalizedString(
    ["\nYou will be requested to Use %@ to Sign In. ",
    "%@ doesn't share any information about you. The ",
    "permission is required to post your Live Video."].joined()
)

或者更好,使用 vacawama 的多线解决方案:

let message = 
    """

    You will be requested to Use %@ to Sign In. \
    %@ doesn't share any information about you. \
    The permission is required to post your Live Video.
    """

这是一个通用的解决方案,但并不真正适合,NSLocalizedString因为它破坏了扫描本地化字符串的工具,例如genstrings.

您的另一个解决方案是通过在该行之前添加一个禁用来关闭该行的警告:

// swiftlint:disable:next line_length

有关禁用 swiftlint 规则的完整详细信息,请参阅在代码中禁用规则。

于 2018-02-24T18:18:58.283 回答
20

在这种情况下,只需像这样更新您的line_length规则ignores_interpolated_strings

line_length:
  warning: 120
  ignores_function_declarations: true
  ignores_comments: true
  ignores_interpolated_strings: true
  ignores_urls: true

并确保您使用的是最新版本swiftlint(它是在几周前添加的)

于 2018-05-21T01:35:09.380 回答
1

此行添加到 .swiftlint.yml 规则文件中,它对我有用

# implicitly 
line_length: 110
于 2020-04-30T03:56:25.547 回答