Skip to content

Commit

Permalink
Ignore block comments in let_var_whitespace rule (realm#4889)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimplyDanny authored Apr 15, 2023
1 parent 74b82da commit f127ba1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
18 changes: 16 additions & 2 deletions Source/SwiftLintFramework/Rules/Style/LetVarWhitespaceRule.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit f127ba1

Please sign in to comment.