Skip to content

Add rule: no_multiline_collapse #44

@kj6dev

Description

@kj6dev

Overview

Never collapse multi-line code into a single line to meet line limits. The fix is always to extract into a named subview/property.

Rule Identifier

no_multiline_collapse

Rationale

Collapsing multi-line code into a single line destroys readability. Line limits exist to encourage extraction, not compression.

Example

// ORIGINAL - triggered skimmable_body warning
@ViewBuilder private var presetButtons: some View {
    if !config.presets.isEmpty {
        HStack {
            ForEach(config.presets.indices, id: \.self) { index in
                presetButton(at: index)
            }
        }
    }
}

// ❌ BAD "fix" - cramming code to reduce line count
@ViewBuilder private var presetButtons: some View {
    if !config.presets.isEmpty {
        HStack {
            ForEach(config.presets.indices, id: \.self) { presetButton(at: $0) }
        }
    }
}

// ✅ GOOD fix - extract complexity
@ViewBuilder private var presetButtons: some View {
    if !config.presets.isEmpty {
        presetButtonsRow
    }
}

private var presetButtonsRow: some View {
    HStack {
        ForEach(config.presets.indices, id: \.self) { index in
            presetButton(at: index)
        }
    }
}

Detection Challenge

Hard to detect programmatically - this is more of a code review principle. Could potentially detect:

  • Lines significantly longer than surrounding code
  • Closures with complex expressions crammed onto one line
  • { $0.something } patterns that could be expanded

Notes

May be better as skill/guidance than automated rule. Consider implementing as a "suggestion" level rather than warning/error.

Priority

High (as guidance), Medium (as automated rule)

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