Skip to content

lineLength with multilineTrailingCommaBehavior : alwaysUsed seems broken #1219

Description

@kkebo

Input

.swift-format:

{
  "indentation" : {
    "spaces" : 4
  },
  "lineLength" : 120,
  "multilineTrailingCommaBehavior" : "alwaysUsed",
  "version" : 1
}

test.swift:

struct S {
    private mutating func doctype(_ input: inout BufferQueue) -> ProcessResult {
        repeat {
            switch self.getChar(from: &input) {
            case "\t", "\n", "\u{0C}", " ": #go(to: .beforeDOCTYPEName)
            case ">": #go(error: .missingDOCTYPEName, emitNewForceQuirksDOCTYPE: .data)
            case "\0":
                #go(error: .missingSpaceBeforeDOCTYPEName, .unexpectedNull, createDOCTYPE: "\u{FFFD}", to: .doctypeName)
            case nil:
                self.emitError(.eofInDOCTYPE)
                #goEmitNewForceQuirksDOCTYPEAndEOF
            case let c?: #go(error: .missingSpaceBeforeDOCTYPEName, createDOCTYPE: lowerASCII(c), to: .doctypeName)
            }
        } while true
    }
}

The line length of #go(error: .missingSpaceBeforeDOCTYPEName, .unexpectedNull, createDOCTYPE: "\u{FFFD}", to: .doctypeName) is just 120.

Expected result

No warnings.

Actual result

$ swift-format lint test.swift
test.swift:9:120: warning: [TrailingComma] add trailing comma to the last element in multiline collection literal
test.swift:8:1: warning: [LineLength] line is too long

If multilineTrailingCommaBehavior is keptAsWritten, there are no warnings.

Environment

  • swift-format main branch 95ed8b4
  • Linux aarch64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions