Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,10 @@

### Enhancements

* None.
* Add autocorrection to the `multiline_call_arguments` rule, expanding single-line
and multi-line calls to one-argument-per-line, including nested calls whose closing
`)` would otherwise be stranded with the last argument.
[GandaLF2006](https://github.com/GandaLF2006)

### Bug Fixes

Expand Down
16 changes: 13 additions & 3 deletions Source/SwiftLintBase/String+SwiftLint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,17 @@ public extension String {
}

func indent(by spaces: Int, skipFirst: Bool = false, skipEmptyLines: Bool = true) -> String {
indent(by: String(repeating: " ", count: spaces), skipFirst: skipFirst, skipEmptyLines: skipEmptyLines)
}

func indent(by indentation: String, skipFirst: Bool = false, skipEmptyLines: Bool = true) -> String {
Comment thread
SimplyDanny marked this conversation as resolved.
Resolved
let lines = components(separatedBy: "\n")
if skipFirst, let firstLine = lines.first {
return firstLine + "\n" + lines.dropFirst().indent(by: spaces, skipEmptyLines: skipEmptyLines)
let rest = lines.dropFirst()
guard !rest.isEmpty else { return firstLine }
return firstLine + "\n" + rest.indent(by: indentation, skipEmptyLines: skipEmptyLines)
}
return lines.indent(by: spaces, skipEmptyLines: skipEmptyLines)
return lines.indent(by: indentation, skipEmptyLines: skipEmptyLines)
}

func linesPrefixed(with prefix: Self) -> Self {
Expand All @@ -105,11 +111,15 @@ public extension String {

private extension Sequence where Element == String {
func indent(by spaces: Int, skipEmptyLines: Bool = true) -> String {
indent(by: String(repeating: " ", count: spaces), skipEmptyLines: skipEmptyLines)
}

func indent(by indentation: String, skipEmptyLines: Bool = true) -> String {
Comment thread
SimplyDanny marked this conversation as resolved.
Resolved
map { line in
if skipEmptyLines, line.isEmpty {
return line
}
return String(repeating: " ", count: spaces) + line
return indentation + line
}
.joined(separator: "\n")
}
Expand Down
Loading