Skip to content

Commit

Permalink
Use correct separator for nested descriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyDanny committed Aug 28, 2023
1 parent f824c75 commit 9ec8cae
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 9 additions & 2 deletions Source/SwiftLintCore/Models/RuleConfigurationDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,11 @@ extension RuleConfigurationDescription: Documentable {
}

public func oneLiner() -> String {
options.map { $0.oneLiner() }.joined(separator: "; ")
oneLiner(separator: ";")
}

fileprivate func oneLiner(separator: String) -> String {
options.map { $0.oneLiner() }.joined(separator: "\(separator) ")
}

public func markdown() -> String {
Expand Down Expand Up @@ -186,7 +190,10 @@ extension OptionType: Documentable {
}

public func oneLiner() -> String {
yaml()
if case let .nested(value) = self {
return value.oneLiner(separator: ",")
}
return yaml()
}

public func yaml() -> String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ class RequiredEnumCaseConfigurationTests: SwiftLintTestCase {
}

func testConsoleDescriptionReturnsAllConfiguredProtocols() {
let expected = "NetworkResults: error: warning; RequiredProtocol: error: warning; success: warning"
let expected = "NetworkResults: error: warning; RequiredProtocol: error: warning, success: warning"
XCTAssertEqual(config.parameterDescription?.oneLiner(), expected)
}

func testConsoleDescriptionReturnsNoConfiguredProtocols() {
let expected = "{Protocol Name}: {Case Name 1}: {warning|error}; {Case Name 2}: {warning|error}"
let expected = "{Protocol Name}: {Case Name 1}: {warning|error}, {Case Name 2}: {warning|error}"

config.protocols.removeAll()
XCTAssertEqual(config.parameterDescription?.oneLiner(), expected)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ class RuleConfigurationDescriptionTests: XCTestCase {
""")

XCTAssertEqual(description.oneLiner(), """
flag: true; nested 1: integer: 2; nested 2: float: 42.1; symbol: value; string: "value"
flag: true; nested 1: integer: 2, nested 2: float: 42.1, symbol: value; string: "value"
""")

XCTAssertEqual(description.yaml(), """
Expand Down

0 comments on commit 9ec8cae

Please sign in to comment.