Skip to content

Commit

Permalink
[Fix #4181] Improve the message of the Lint/AmbiguousBlockAssociation…
Browse files Browse the repository at this point in the history
… cop (#4235)
  • Loading branch information
smakagon authored and bbatsov committed Apr 3, 2017
1 parent 6414db1 commit 67ca736
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* [#4219](https://github.com/bbatsov/rubocop/issues/4219): Add a link to style guide for `Style/IndentationConsistency` cop. ([@pocke][])
* [#4168](https://github.com/bbatsov/rubocop/issues/4168): Removed `-n` option. ([@sadovnik][])
* [#4039](https://github.com/bbatsov/rubocop/pull/4039): Change `Style/PercentLiteralDelimiters` default configuration to match Style Guide update. ([@drenmi][])
* [#4235](https://github.com/bbatsov/rubocop/pull/4235): Improved copy of offense message in `Lint/AmbiguousBlockAssociation` cop. ([@smakagon][])

### Bug fixes

Expand Down
6 changes: 3 additions & 3 deletions lib/rubocop/cop/lint/ambiguous_block_association.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def on_send(node)
last_param = node.last_argument.children.first
return unless method_as_param?(last_param)

add_offense(node, :expression, message(last_param, node.method_name))
add_offense(node, :expression, message(node.last_argument))
end

private
Expand All @@ -53,8 +53,8 @@ def method_as_param?(param)
param && param.send_type? && !param.arguments?
end

def message(param, method_name)
format(MSG, param.children[1], method_name)
def message(param)
format(MSG, param.source, param.children.first.source)
end

def_node_matcher :lambda_argument?, <<-PATTERN
Expand Down
10 changes: 5 additions & 5 deletions spec/rubocop/cop/lint/ambiguous_block_association_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
it 'registers an offense' do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.first.message).to(
eq(format(error_message, 'a', 'some_method'))
eq(format(error_message, 'a { |el| puts el }', 'a'))
)
end
end
Expand All @@ -69,7 +69,7 @@
it 'registers an offense' do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.first.message).to(
eq(format(error_message, 'a', 'some_method'))
eq(format(error_message, 'a { |el| puts el }', 'a'))
)
end
end
Expand All @@ -82,7 +82,7 @@
it 'registers an offense' do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.first.message).to(
eq(format(error_message, 'change', 'to'))
eq(format(error_message, 'change { order.events }', 'change'))
)
end
end
Expand All @@ -93,7 +93,7 @@
it 'registers an offense' do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.first.message).to(
eq(format(error_message, 'a', 'some_method'))
eq(format(error_message, 'a { |el| el }', 'a'))
)
end
end
Expand All @@ -104,7 +104,7 @@
it 'registers an offense' do
expect(cop.offenses.size).to eq(1)
expect(cop.offenses.first.message).to(
eq(format(error_message, 'a', 'some_method'))
eq(format(error_message, 'a { |el| puts el }', 'a'))
)
end
end
Expand Down

0 comments on commit 67ca736

Please sign in to comment.