How to fix 'Line Length Violation: Line should be 120 characters or less' - SwiftLint

老子叫甜甜 提交于 2020-12-02 11:51:03

问题


How to fix Line Length Violation?

Relevant part of alert message that isn't allowed due to Line Length Violation: 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.", ⚠ Line should be 120 characters or less: currently 208 characters (line_length)


回答1:


Make the line shorter:

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()
)

or better, using vacawama's multi-line solution:

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.
    """

That's a generic solution, but isn't really appropriate for NSLocalizedString because it breaks tools that scan for localized strings like genstrings.

Your other solution is to turn off the warning for that line by adding a disable on the line immediately before:

// swiftlint:disable:next line_length

See Disable rules in code for full details on disabling swiftlint rules.




回答2:


In this case just update your line_length rule with ignores_interpolated_strings like this:

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

and make sure you are using last version of swiftlint (it was added just a few weeks ago)




回答3:


This line added in .swiftlint.yml rule file its works for me

# implicitly 
line_length: 110


来源:https://stackoverflow.com/questions/48965916/how-to-fix-line-length-violation-line-should-be-120-characters-or-less-swif

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!