Skip to content

Commit

Permalink
Update as suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
BB9z committed Oct 22, 2023
1 parent 5e6af26 commit 1b05eaa
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 17 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#### Bug Fixes

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,16 @@ struct ExplicitInitRule: OptInRule {
"""),
Example("""
f { e in
A↓.init(e: e)
}
"""):
Example("""
f { e in
A(e: e)
}
"""),
Example("_ = GleanMetrics.Tabs.GroupedTabExtra↓.init()"):
Example("_ = GleanMetrics.Tabs.GroupedTabExtra()"),
Expand Down Expand Up @@ -201,7 +211,7 @@ private extension ExplicitInitRule {
}

correctionPositions.append(violationPosition)
let newNode = node.with(\.calledExpression, calledBase.with(\.trailingTrivia, []))
let newNode = node.with(\.calledExpression, calledBase)
return super.visit(newNode)
}
}
Expand Down
15 changes: 0 additions & 15 deletions Tests/SwiftLintFrameworkTests/ExplicitInitRuleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,24 +13,9 @@ class ExplicitInitRuleTests: SwiftLintTestCase {
Example("foo(↓.init())")
]

var correction = [
Example("""
f { e in
A↓.init(e: e)
}
"""):
Example("""
f { e in
A(e: e)
}
""")
]
correction.merge(ExplicitInitRule.description.corrections) { current, _ in current }

let description = ExplicitInitRule.description
.with(nonTriggeringExamples: nonTriggeringExamples)
.with(triggeringExamples: triggeringExamples)
.with(corrections: correction)

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

0 comments on commit 1b05eaa

Please sign in to comment.