Fix rewrite issue with `comma` rule (#4635)

This commit is contained in:
JP Simard 2022-12-09 12:56:50 -05:00 committed by GitHub
parent 7f8eb9de77
commit 73a64d674c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View File

@ -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

View File

@ -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"),
@ -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: [])"#)
]
)
@ -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
}