Skip to content

Fix Style/VerboseBlock rule to work with binary operations #384

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

Merged
merged 1 commit into from
Jun 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions spec/ameba/rule/style/verbose_block_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ module Ameba::Rule::Style
(1..3).map { |l| l.to_i64 * l.to_i64 }
(1..3).map { |m| m.to_s[start: m.to_i64, count: 3]? }
(1..3).map { |n| n.to_s.split.map { |z| n.to_i * z.to_i }.join }
(1..3).map { |o| o.foo = foos[o.abs]? || 0 }
CRYSTAL
end

Expand Down
5 changes: 4 additions & 1 deletion src/ameba/rule/style/verbose_block.cr
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@ module Ameba::Rule::Style
node.named_args.try &.each do |arg|
i += reference_count(arg.value, obj)
end
when Crystal::BinaryOp
i += reference_count(node.left, obj)
i += reference_count(node.right, obj)
when Crystal::Block
i += reference_count(node.body, obj)
when Crystal::Var
Expand Down Expand Up @@ -230,7 +233,7 @@ module Ameba::Rule::Style
# we filter out the blocks that are of call type - `i.to_i64.odd?`
return unless (body = block.body).is_a?(Crystal::Call)

# we need to "unwind" the chain challs, so the final receiver object
# we need to "unwind" the chain calls, so the final receiver object
# ends up being a variable - `i`
obj = body.obj
while obj.is_a?(Crystal::Call)
Expand Down