-
-
Notifications
You must be signed in to change notification settings - Fork 285
Add autocorrect for RSpec/ExpectActual #855
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,17 @@ def on_send(node) | |
| end | ||
| end | ||
|
|
||
| def autocorrect(node) | ||
| lambda do |corrector| | ||
| expectation = node.parent.parent | ||
| rhs = expectation.children.last | ||
| return unless rhs.is_a?(RuboCop::AST::MethodDispatchNode) | ||
pirj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return if rhs.method_name != :eq | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe also expect(3).to be
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi @pirj, thanks for the suggestions. Could I trouble you to provide examples using the first three methods? I interpreted your suggestion as applying like so: expect(123).to ==(bar)
expect(123).to eql?(bar)
expect(123).to equal?(bar)…but that doesn't appear to be valid:
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My bad. Should of course be: expect(123).to be
expect(123).to be == 123
expect(123).to eql(123)
expect(123).to equal(123)Thanks for the extra care. |
||
|
|
||
| swap_order(corrector, node, rhs.children.last) | ||
pirj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| end | ||
| end | ||
pirj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| private | ||
|
|
||
| # This is not implement using a NodePattern because it seems | ||
|
|
@@ -65,6 +76,11 @@ def complex_literal?(node) | |
| COMPLEX_LITERALS.include?(node.type) && | ||
| node.each_child_node.all?(&method(:literal?)) | ||
| end | ||
|
|
||
| def swap_order(corrector, lhs_arg, rhs_arg) | ||
pirj marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| corrector.replace(lhs_arg.source_range, rhs_arg.source) | ||
| corrector.replace(rhs_arg.source_range, lhs_arg.source) | ||
| end | ||
| end | ||
| end | ||
| end | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.