Skip to content

Commit

Permalink
Improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
mildm8nnered committed Dec 12, 2024
1 parent 8328d06 commit 1ce8ea8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
8 changes: 4 additions & 4 deletions Source/SwiftLintCore/Documentation/RuleDocumentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ struct RuleDocumentation {
var content = [h1(description.name), description.description, detailsSummary(ruleType.init())]
if let rationale = description.rationale {
content += [h2("Rationale")]
content.append(rationale.formattedAsRationale)
content.append(rationale.formattedRationale)
}
let nonTriggeringExamples = description.nonTriggeringExamples.filter { !$0.excludeFromDocumentation }
if nonTriggeringExamples.isNotEmpty {
Expand Down Expand Up @@ -104,17 +104,17 @@ private func detailsSummary(_ rule: some Rule) -> String {
}

extension String {
var formattedAsRationale: String {
var formattedRationale: String {
formattedRationale(forConsole: false)
}

var formattedAsConsoleRationale: String {
var consoleRationale: String {
formattedRationale(forConsole: true)
}

private func formattedRationale(forConsole: Bool) -> String {
var insideMultilineString = false
return components(separatedBy: "\n").compactMap { line in
return components(separatedBy: "\n").compactMap { line -> String? in
if line.contains("```") {
if insideMultilineString {
insideMultilineString = false
Expand Down
5 changes: 1 addition & 4 deletions Source/SwiftLintCore/Models/RuleDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,10 +62,7 @@ public struct RuleDescription: Equatable, Sendable {

/// The console-printable rationale for this description.
public var consoleRationale: String? {
guard let rationale else {
return nil
}
return rationale.formattedAsConsoleRationale
rationale?.consoleRationale
}

/// All identifiers that have been used to uniquely identify this rule in past and current SwiftLint versions.
Expand Down

0 comments on commit 1ce8ea8

Please sign in to comment.