Ignore block comments in `let_var_whitespace` rule (#4889)

This commit is contained in:
Danny Mösch 2023-04-16 00:10:03 +02:00 committed by GitHub
parent 74b82daba0
commit f127ba14dd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 2 deletions

View File

@ -37,6 +37,10 @@
[SimplyDanny](https://github.com/SimplyDanny)
[#4860](https://github.com/realm/SwiftLint/issues/4860)
* Ignore block comments in `let_var_whitespace` rule.
[SimplyDanny](https://github.com/SimplyDanny)
[#4871](https://github.com/realm/SwiftLint/issues/4871)
* Fix false positives in `indentation_width` rule.
[Sven Münnich](https://github.com/svenmuennich)

View File

@ -40,7 +40,17 @@ struct LetVarWhitespaceRule: ConfigurationProviderRule, OptInRule {
@Attribute
func f() {}
"""),
Example("var x: Int {\n\tlet a = 0\n\treturn a\n}\n") // don't trigger on local vars
Example("var x: Int {\n\tlet a = 0\n\treturn a\n}\n"), // don't trigger on local vars
Example("""
struct S {
static var test: String { /* Comment block */
let s = "!"
return "Test" + s
}
func f() {}
}
""", excludeFromDocumentation: true)
],
triggeringExamples: [
Example("var x = 1\n↓x = 2\n"),
@ -213,7 +223,11 @@ struct LetVarWhitespaceRule: ConfigurationProviderRule, OptInRule {
for token in syntaxMap.tokens where token.kind == .comment ||
token.kind == .docComment {
let startLine = file.line(byteOffset: token.offset)
let endLine = file.line(byteOffset: token.offset + token.length)
var endLine = file.line(byteOffset: token.offset + token.length)
if file.contents(for: token)?.starts(with: "/*") == true {
endLine += 1
}
if startLine <= endLine {
result.formUnion(Set(startLine...endLine))