Skip to content

Commit

Permalink
Keep trailing trivia in explicit_init rule correction (#5296)
Browse files Browse the repository at this point in the history
  • Loading branch information
BB9z authored Oct 23, 2023
1 parent 4c0f337 commit cb3001b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@

#### Bug Fixes

* Fix correction of `explicit_init` rule by keeping significant trivia.
[BB9z](https://github.com/BB9z)
[#5289](https://github.com/realm/SwiftLint/issues/5289)

* Fix invalid corrections for opaque and existential optionals in
`syntactic_sugar` rule.
[SimplyDanny](https://github.com/SimplyDanny)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,18 @@ struct ExplicitInitRule: OptInRule {
"""),
Example("""
f { e in
// comment
A↓.init(e: e)
}
"""):
Example("""
f { e in
// comment
A(e: e)
}
"""),
Example("_ = GleanMetrics.Tabs.GroupedTabExtra↓.init()"):
Example("_ = GleanMetrics.Tabs.GroupedTabExtra()"),
Expand Down Expand Up @@ -197,7 +209,7 @@ private extension ExplicitInitRule {
return super.visit(node)
}
correctionPositions.append(violationPosition)
let newNode = node.with(\.calledExpression, calledBase.trimmed)
let newNode = node.with(\.calledExpression, calledBase)
return super.visit(newNode)
}
}
Expand Down
1 change: 0 additions & 1 deletion Tests/SwiftLintFrameworkTests/ExplicitInitRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ class ExplicitInitRuleTests: SwiftLintTestCase {
let description = ExplicitInitRule.description
.with(nonTriggeringExamples: nonTriggeringExamples)
.with(triggeringExamples: triggeringExamples)
.with(corrections: [:])

verifyRule(description, ruleConfiguration: ["include_bare_init": true])
}
Expand Down

0 comments on commit cb3001b

Please sign in to comment.