Skip to content

Commit

Permalink
Fix rewrite issue with comma rule (realm#4635)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsim authored Dec 9, 2022
1 parent 7f8eb9d commit 73a64d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
12 changes: 8 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,20 @@
[SimplyDanny](https://github.com/SimplyDanny)
[#4612](https://github.com/realm/SwiftLint/issues/4612)

* Skip `defer` statements being last in an `#if` block if the `#if` statement is
not itself the last statement in a block.
* Skip `defer` statements being last in an `#if` block if the `#if`
statement is not itself the last statement in a block.
[SimplyDanny](https://github.com/SimplyDanny)
[#4615](https://github.com/realm/SwiftLint/issues/4615)

* Fix false positives in `empty_enum_arguments` when the called expression
is an identifier or an init call.
* Fix false positives in `empty_enum_arguments` when the called
expression is an identifier or an init call.
[Steffen Matthischke](https://github.com/heeaad)
[#4597](https://github.com/realm/SwiftLint/issues/4597)

* Fix correction issue in `comma` when there was too much whitespace
following the comma.
[JP Simard](https://github.com/jpsim)

## 0.50.1: Artisanal Clothes Pegs Fixup Edition

#### Breaking
Expand Down
11 changes: 8 additions & 3 deletions Source/SwiftLintFramework/Rules/Style/CommaRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ struct CommaRule: CorrectableRule, ConfigurationProviderRule, SourceKitFreeRule
message: My.Custom.message↓ ,
another: parameter, doIt: true,
alignment: .center)
""")
"""),
Example(#"Logger.logError("Hat is too large"↓, info: [])"#)
],
corrections: [
Example("func abc(a: String↓,b: String) {}\n"): Example("func abc(a: String, b: String) {}\n"),
Expand Down Expand Up @@ -83,7 +84,9 @@ struct CommaRule: CorrectableRule, ConfigurationProviderRule, SourceKitFreeRule
message: My.Custom.message,
another: parameter, doIt: true,
alignment: .center)
""")
"""),
Example(#"Logger.logError("Hat is too large"↓, info: [])"#):
Example(#"Logger.logError("Hat is too large", info: [])"#)
]
)

Expand All @@ -109,7 +112,9 @@ struct CommaRule: CorrectableRule, ConfigurationProviderRule, SourceKitFreeRule
let nextIsNewline = next.leadingTrivia.containsNewlines()
return (ByteRange(location: start, length: end - start), shouldAddSpace: !nextIsNewline)
} else if !current.trailingTrivia.starts(with: [.spaces(1)]), !next.leadingTrivia.containsNewlines() {
return (ByteRange(location: ByteCount(current.position), length: 1), shouldAddSpace: true)
let start = ByteCount(current.position)
let end = ByteCount(next.positionAfterSkippingLeadingTrivia)
return (ByteRange(location: start, length: end - start), shouldAddSpace: true)
} else {
return nil
}
Expand Down

0 comments on commit 73a64d6

Please sign in to comment.