Skip to content

Commit

Permalink
CR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mildm8nnered committed Nov 5, 2024
1 parent 12cc65d commit 37706c8
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 39 deletions.
15 changes: 7 additions & 8 deletions Source/SwiftLintBuiltInRules/Rules/Style/AttributesRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,20 @@ struct AttributesRule: OptInRule {
imports
""",
rationale: """
See https://ericasadun.com/2016/10/02/quick-style-survey/ for discussion.
Erica Sadun says:
Summarizing here: "[Erica Sadun's] take on things after the poll and after talking directly with a number of \
> my take on things after the poll and after talking directly with a number of \
developers is this: Placing attributes like `@objc`, `@testable`, `@available`, `@discardableResult` on \
their own lines before a member declaration has become a conventional Swift style."
their own lines before a member declaration has become a conventional Swift style.
"This approach limits declaration length. It allows a member to float below its attribute and supports \
> This approach limits declaration length. It allows a member to float below its attribute and supports \
flush-left access modifiers, so `internal`, `public`, etc appear in the leftmost column. Many developers \
mix-and-match styles for short Swift attributes like `@objc`"
mix-and-match styles for short Swift attributes like `@objc`
See https://ericasadun.com/2016/10/02/quick-style-survey/ for discussion.
SwiftLint's rule requires attributes to be on their own lines for functions and types, but on the same line \
for variables and imports.
The `attributes_with_arguments_always_on_line_above`, `always_on_same_line`, and `always_on_line_above` \
configuration parameters can be used to fine-tune the rules behaviour for particular attributes.
""",
kind: .style,
nonTriggeringExamples: AttributesRuleExamples.nonTriggeringExamples,
Expand Down
34 changes: 20 additions & 14 deletions Source/SwiftLintCore/Documentation/RuleDocumentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,7 @@ struct RuleDocumentation {
}

private func formattedRationale(_ rationale: String) -> String {
var insideMultilineString = false
return rationale.components(separatedBy: "\n").map { line in
if line.contains("```") {
if insideMultilineString {
insideMultilineString = false
} else {
insideMultilineString = true
if line.hasSuffix("```") {
return line + "swift"
}
}
}
return line
}.joined(separator: "\n")
rationale.formattedAsRationale
}

private func formattedCode(_ example: Example) -> String {
Expand Down Expand Up @@ -119,3 +106,22 @@ private func detailsSummary(_ rule: some Rule) -> String {
}
return ruleDescription
}

extension String {
var formattedAsRationale: String {
var insideMultilineString = false
return components(separatedBy: "\n").map { line in
if line.contains("```") {
if insideMultilineString {
insideMultilineString = false
} else {
insideMultilineString = true
if line.hasSuffix("```") {
return line + "swift"
}
}
}
return line
}.joined(separator: "\n")
}
}
18 changes: 1 addition & 17 deletions Source/SwiftLintCore/Models/RuleDescription.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,23 +64,7 @@ public struct RuleDescription: Equatable, Sendable {
guard let rationale else {
return nil
}
var insideMultilineString = false
return rationale.components(separatedBy: "\n").map { line in
if line.contains("```") {
if insideMultilineString {
insideMultilineString = false
} else {
insideMultilineString = true
if line.hasSuffix("```") {
return line + "swift"
}
}
}
if insideMultilineString {
return " \(line)"
}
return line
}.joined(separator: "\n")
return rationale.formattedAsRationale
}

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

0 comments on commit 37706c8

Please sign in to comment.