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

后端 未结 3 1273
误落风尘
误落风尘 2021-01-05 02:50

How to fix Line Length Violation?

Relevant part of alert message that isn\'t allowed due to Line Length Violation: message: NSLocalizedString(\"\\nYou will b

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-05 03:15

    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.

提交回复
热议问题