Skip to content

Commit

Permalink
Rename closingparenfcall to callsiteparen
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Jun 9, 2024
1 parent 164fb8a commit daf5c8d
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 22 deletions.
1 change: 1 addition & 0 deletions Rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -2510,6 +2510,7 @@ Option | Description
`--wrapparameters` | Wrap func params: "before-first", "after-first", "preserve"
`--wrapcollections` | Wrap array/dict: "before-first", "after-first", "preserve"
`--closingparen` | Closing paren position: "balanced" (default) or "same-line"
`--callsiteparen` | Closing paren at callsite: "inherit" (default) or "same-line"
`--wrapreturntype` | Wrap return type: "if-multiline", "preserve" (default)
`--wrapconditions` | Wrap conditions: "before-first", "after-first", "preserve"
`--wraptypealiases` | Wrap typealiases: "before-first", "after-first", "preserve"
Expand Down
2 changes: 1 addition & 1 deletion Sources/FormattingHelpers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ extension Formatter {
keepParameterLabelsOnSameLine(startOfScope: i,
endOfScope: &endOfScope)

if options.forceClosingParenOnSameLineForFunctionCalls, isFunctionCall(at: i) {
if options.closingCallSiteParenOnSameLine, isFunctionCall(at: i) {
removeLinebreakBeforeEndOfScope(at: &endOfScope)
} else if endOfScopeOnSameLine {
removeLinebreakBeforeEndOfScope(at: &endOfScope)
Expand Down
10 changes: 5 additions & 5 deletions Sources/Inference.swift
Original file line number Diff line number Diff line change
Expand Up @@ -407,15 +407,15 @@ private struct Inference {
}
}

// Decide on forceClosingParenOnSameLineForFunctionCalls
// Decide on closingCallSiteParenOnSameLine
if functionCallSameLine > functionCallBalanced && functionDeclarationBalanced > functionDeclarationSameLine {
options.forceClosingParenOnSameLineForFunctionCalls = true
options.closingCallSiteParenOnSameLine = true
} else {
options.forceClosingParenOnSameLineForFunctionCalls = false
options.closingCallSiteParenOnSameLine = false
}

// If forceClosingParenOnSameLineForFunctionCalls is true, trust only the declarations to infer closingParenOnSameLine
if options.forceClosingParenOnSameLineForFunctionCalls {
// If closingCallSiteParenOnSameLine is true, trust only the declarations to infer closingParenOnSameLine
if options.closingCallSiteParenOnSameLine {
options.closingParenOnSameLine = functionDeclarationSameLine > functionDeclarationBalanced
} else {
let balanced = functionDeclarationBalanced + functionCallBalanced
Expand Down
12 changes: 6 additions & 6 deletions Sources/OptionDescriptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -504,12 +504,12 @@ struct _Descriptors {
trueValues: ["same-line"],
falseValues: ["balanced"]
)
let forceClosingParenOnSameLineForFunctionCalls = OptionDescriptor(
argumentName: "closingparenfcall",
displayName: "Force Closing Paren on same line for function calls",
help: "Force the closingParenOnSameLine option specifically for function calls: \"inherit\" (default) or \"force-same-line\"",
keyPath: \.forceClosingParenOnSameLineForFunctionCalls,
trueValues: ["force-same-line", "same-line"],
let closingCallSiteParenOnSameLine = OptionDescriptor(
argumentName: "callsiteparen",
displayName: "Call Site Closing Paren",
help: "Closing paren at callsite: \"inherit\" (default) or \"same-line\"",
keyPath: \.closingCallSiteParenOnSameLine,
trueValues: ["same-line"],
falseValues: ["inherit"]
)
let uppercaseHex = OptionDescriptor(
Expand Down
6 changes: 3 additions & 3 deletions Sources/Options.swift
Original file line number Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ public struct FormatOptions: CustomStringConvertible {
public var wrapTypealiases: WrapMode
public var wrapEnumCases: WrapEnumCases
public var closingParenOnSameLine: Bool
public var forceClosingParenOnSameLineForFunctionCalls: Bool
public var closingCallSiteParenOnSameLine: Bool
public var wrapReturnType: WrapReturnType
public var wrapConditions: WrapMode
public var wrapTernaryOperators: TernaryOperatorWrapMode
Expand Down Expand Up @@ -674,7 +674,7 @@ public struct FormatOptions: CustomStringConvertible {
wrapTypealiases: WrapMode = .preserve,
wrapEnumCases: WrapEnumCases = .always,
closingParenOnSameLine: Bool = false,
forceClosingParenOnSameLineForFunctionCalls: Bool = false,
closingCallSiteParenOnSameLine: Bool = false,
wrapReturnType: WrapReturnType = .preserve,
wrapConditions: WrapMode = .preserve,
wrapTernaryOperators: TernaryOperatorWrapMode = .default,
Expand Down Expand Up @@ -772,7 +772,7 @@ public struct FormatOptions: CustomStringConvertible {
self.wrapTypealiases = wrapTypealiases
self.wrapEnumCases = wrapEnumCases
self.closingParenOnSameLine = closingParenOnSameLine
self.forceClosingParenOnSameLineForFunctionCalls = forceClosingParenOnSameLineForFunctionCalls
self.closingCallSiteParenOnSameLine = closingCallSiteParenOnSameLine
self.wrapReturnType = wrapReturnType
self.wrapConditions = wrapConditions
self.wrapTernaryOperators = wrapTernaryOperators
Expand Down
7 changes: 4 additions & 3 deletions Sources/Rules.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3882,8 +3882,9 @@ public struct _FormatRules {
public let wrap = FormatRule(
help: "Wrap lines that exceed the specified maximum width.",
options: ["maxwidth", "nowrapoperators", "assetliterals", "wrapternary"],
sharedOptions: ["wraparguments", "wrapparameters", "wrapcollections", "closingparen", "indent",
"trimwhitespace", "linebreaks", "tabwidth", "maxwidth", "smarttabs", "wrapreturntype", "wrapconditions", "wraptypealiases", "wrapternary", "wrapeffects"]
sharedOptions: ["wraparguments", "wrapparameters", "wrapcollections", "closingparen", "callsiteparen", "indent",
"trimwhitespace", "linebreaks", "tabwidth", "maxwidth", "smarttabs", "wrapreturntype",
"wrapconditions", "wraptypealiases", "wrapternary", "wrapeffects"]
) { formatter in
let maxWidth = formatter.options.maxWidth
guard maxWidth > 0 else { return }
Expand Down Expand Up @@ -3939,7 +3940,7 @@ public struct _FormatRules {
public let wrapArguments = FormatRule(
help: "Align wrapped function arguments or collection elements.",
orderAfter: ["wrap"],
options: ["wraparguments", "wrapparameters", "wrapcollections", "closingparen",
options: ["wraparguments", "wrapparameters", "wrapcollections", "closingparen", "callsiteparen",
"wrapreturntype", "wrapconditions", "wraptypealiases", "wrapeffects"],
sharedOptions: ["indent", "trimwhitespace", "linebreaks",
"tabwidth", "maxwidth", "smarttabs", "assetliterals", "wrapternary"]
Expand Down
3 changes: 2 additions & 1 deletion Tests/MetadataTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,8 @@ class MetadataTests: XCTestCase {
case .identifier("wrapCollectionsAndArguments"):
referencedOptions += [
Descriptors.wrapArguments, Descriptors.wrapParameters, Descriptors.wrapCollections,
Descriptors.closingParenOnSameLine, Descriptors.linebreak, Descriptors.truncateBlankLines,
Descriptors.closingParenOnSameLine, Descriptors.closingCallSiteParenOnSameLine,
Descriptors.linebreak, Descriptors.truncateBlankLines,
Descriptors.indent, Descriptors.tabWidth, Descriptors.smartTabs, Descriptors.maxWidth,
Descriptors.assetLiteralWidth, Descriptors.wrapReturnType, Descriptors.wrapEffects,
Descriptors.wrapConditions, Descriptors.wrapTypealiases, Descriptors.wrapTernaryOperators,
Expand Down
6 changes: 3 additions & 3 deletions Tests/RulesTests+Wrapping.swift
Original file line number Diff line number Diff line change
Expand Up @@ -1518,7 +1518,7 @@ class WrappingTests: RulesTests {
bar _: Int,
baz _: String) {}
"""
let options = FormatOptions(wrapArguments: .beforeFirst, closingParenOnSameLine: true, forceClosingParenOnSameLineForFunctionCalls: true)
let options = FormatOptions(wrapArguments: .beforeFirst, closingParenOnSameLine: true, closingCallSiteParenOnSameLine: true)
testFormatting(for: input, output, rule: FormatRules.wrapArguments, options: options)
}

Expand All @@ -1534,7 +1534,7 @@ class WrappingTests: RulesTests {
baz _: String
) {}
"""
let options = FormatOptions(wrapArguments: .beforeFirst, closingParenOnSameLine: false, forceClosingParenOnSameLineForFunctionCalls: true)
let options = FormatOptions(wrapArguments: .beforeFirst, closingParenOnSameLine: false, closingCallSiteParenOnSameLine: true)
testFormatting(for: input, output, rule: FormatRules.wrapArguments, options: options)
}

Expand All @@ -1550,7 +1550,7 @@ class WrappingTests: RulesTests {
bar: 42,
baz: "foo")
"""
let options = FormatOptions(wrapArguments: .beforeFirst, closingParenOnSameLine: false, forceClosingParenOnSameLineForFunctionCalls: true)
let options = FormatOptions(wrapArguments: .beforeFirst, closingParenOnSameLine: false, closingCallSiteParenOnSameLine: true)
testFormatting(for: input, output, rule: FormatRules.wrapArguments, options: options)
}

Expand Down

0 comments on commit daf5c8d

Please sign in to comment.