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
4 changes: 2 additions & 2 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -4090,7 +4090,7 @@ Option | Description
`--no-wrap-operators` | Comma-delimited list of operators that shouldn't be wrapped
`--asset-literals` | Formatting of color/image literals: "actual-width" or "visual-width" (default)
`--wrap-ternary` | Ternary expression wrapping: "default" (wrap if needed) or "before-operators"
`--wrap-string-interpolation` | String interpolation wrapping: "default" (wrap if needed) or "preserve"
`--wrap-string-interpolation` | Wrap string interpolation if it exceeds max width: "true" or "false" (default)

<details>
<summary>Examples</summary>
Expand Down Expand Up @@ -4121,7 +4121,7 @@ Option | Description
`--wrap-conditions` | Conditional expression wrapping: "before-first", "after-first", "preserve" (default) or "disabled"
`--wrap-type-aliases` | Typealias wrapping: "before-first", "after-first", "preserve" (default) or "disabled"
`--wrap-effects` | Function effects (throws, async) wrapping: "preserve" (default), "if-multiline" or "never"
`--wrap-string-interpolation` | String interpolation wrapping: "default" (wrap if needed) or "preserve"
`--wrap-string-interpolation` | Wrap string interpolation if it exceeds max width: "true" or "false" (default)
`--allow-partial-wrapping` | Allow partial argument wrapping: "true" (default) or "false"

<details>
Expand Down
2 changes: 1 addition & 1 deletion Sources/FormattingHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1251,7 +1251,7 @@ extension Formatter {
i = startOfScope

if tokens[startOfScope].isStringDelimiter {
if options.wrapStringInterpolation == .preserve {
if !options.wrapStringInterpolation {
return true
} else if !tokens[startOfScope].isMultilineStringDelimiter {
// Single line strings can never have line break
Expand Down
6 changes: 4 additions & 2 deletions Sources/OptionDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,10 @@ struct _Descriptors {
let wrapStringInterpolation = OptionDescriptor(
argumentName: "wrap-string-interpolation",
displayName: "Wrap String Interpolation",
help: "String interpolation wrapping: \"default\" (wrap if needed) or \"preserve\"",
keyPath: \.wrapStringInterpolation
help: "Wrap string interpolation if it exceeds max width:",
keyPath: \.wrapStringInterpolation,
trueValues: ["true", "default"], // "default" was previously the default value, but is now deprecated.
falseValues: ["false", "preserve"]
)
let closingParenPosition = OptionDescriptor(
argumentName: "closing-paren",
Expand Down
12 changes: 2 additions & 10 deletions Sources/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,6 @@ public enum TernaryOperatorWrapMode: String, CaseIterable {
case beforeOperators = "before-operators"
}

public enum StringInterpolationWrapMode: String, CaseIterable {
/// Wraps string interpolation if necessary based on the max line length
case `default`
/// Preserve existing wrapping for string interpolations,
/// and don't insert line breaks.
case preserve
}

/// Whether or not to remove `-> Void` from closures
public enum ClosureVoidReturn: String, CaseIterable {
case remove
Expand Down Expand Up @@ -836,7 +828,7 @@ public struct FormatOptions: CustomStringConvertible {
public var wrapReturnType: WrapReturnType
public var wrapConditions: WrapMode
public var wrapTernaryOperators: TernaryOperatorWrapMode
public var wrapStringInterpolation: StringInterpolationWrapMode
public var wrapStringInterpolation: Bool
public var uppercaseHex: Bool
public var uppercaseExponent: Bool
public var decimalGrouping: Grouping
Expand Down Expand Up @@ -989,7 +981,7 @@ public struct FormatOptions: CustomStringConvertible {
wrapReturnType: WrapReturnType = .preserve,
wrapConditions: WrapMode = .preserve,
wrapTernaryOperators: TernaryOperatorWrapMode = .default,
wrapStringInterpolation: StringInterpolationWrapMode = .default,
wrapStringInterpolation: Bool = false,
uppercaseHex: Bool = true,
uppercaseExponent: Bool = false,
decimalGrouping: Grouping = .group(3, 6),
Expand Down
10 changes: 5 additions & 5 deletions Tests/Rules/WrapTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,7 @@ final class WrapTests: XCTestCase {
) inside
\"""
"""
let options = FormatOptions(maxWidth: 40)
let options = FormatOptions(wrapStringInterpolation: true, maxWidth: 40)
testFormatting(for: input, output, rule: .wrap, options: options)
}

Expand All @@ -549,7 +549,7 @@ final class WrapTests: XCTestCase {
a very long string literal with \\(interpolation) inside
\"""
"""
let options = FormatOptions(wrapArguments: .afterFirst, wrapStringInterpolation: .preserve, maxWidth: 40)
let options = FormatOptions(wrapArguments: .afterFirst, wrapStringInterpolation: false, maxWidth: 40)
testFormatting(for: input, rule: .wrap, options: options)
}

Expand All @@ -559,7 +559,7 @@ final class WrapTests: XCTestCase {
a very long string literal with \\(interpolation) inside
\"""
"""
let options = FormatOptions(wrapArguments: .beforeFirst, wrapStringInterpolation: .preserve, maxWidth: 40)
let options = FormatOptions(wrapArguments: .beforeFirst, wrapStringInterpolation: false, maxWidth: 40)
testFormatting(for: input, rule: .wrap, options: options)
}

Expand All @@ -569,7 +569,7 @@ final class WrapTests: XCTestCase {
\(raw: isPublic ? "public " : "")lazy var \(raw: name.trimmed.description): \(raw: typeName)<\(raw: genericName),\(returnType)> = {
"""
"""#
let options = FormatOptions(wrapArguments: .beforeFirst, wrapStringInterpolation: .preserve, maxWidth: 40)
let options = FormatOptions(wrapArguments: .beforeFirst, wrapStringInterpolation: false, maxWidth: 40)
testFormatting(for: input, rule: .wrap, options: options)
}

Expand Down Expand Up @@ -742,7 +742,7 @@ final class WrapTests: XCTestCase {
: "Some other string")"
\"""
"""
let options = FormatOptions(wrapTernaryOperators: .beforeOperators, maxWidth: 50)
let options = FormatOptions(wrapTernaryOperators: .beforeOperators, wrapStringInterpolation: true, maxWidth: 50)
testFormatting(for: input, output, rule: .wrap, options: options)
}

Expand Down