Skip to content

Commit

Permalink
[Fix #5273] Fix Style/EvalWithLocation reporting bad line offset (#…
Browse files Browse the repository at this point in the history
…5275)

See #5273

Cause
====

I forgot an `abs`. 🙇
  • Loading branch information
pocke authored and bbatsov committed Dec 18, 2017
1 parent 1f742d8 commit 6fb5a84
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* [#5245](https://github.com/bbatsov/rubocop/issues/5245): Make `Style/FormatStringToken` to allow regexp token. ([@pocke][])
* [#5224](https://github.com/bbatsov/rubocop/pull/5224): Fix false positives for `Layout/EmptyLinesAroundArguments` operating on blocks. ([@garettarrowood][])
* [#5234](https://github.com/bbatsov/rubocop/issues/5234): Fix a false positive for `Rails/HasManyOrHasOneDependent` when using `class_name` option. ([@koic][])
* [#5273](https://github.com/bbatsov/rubocop/issues/5273): Fix `Style/EvalWithLocation` reporting bad line offset. ([@pocke][])
* [#5228](https://github.com/bbatsov/rubocop/issues/5228): Handle overridden `Metrics/LineLength:Max` for `--auto-gen-config`. ([@jonas054][])

### Changes
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/style/eval_with_location.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def add_offense_for_different_line(node, line_node, line_diff)
add_offense(
node,
location: line_node.loc.expression,
message: message_incorrect_line(line_node, sign, line_diff)
message: message_incorrect_line(line_node, sign, line_diff.abs)
)
end
end
Expand Down
10 changes: 10 additions & 0 deletions spec/rubocop/cop/style/eval_with_location_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,16 @@
RUBY
end

it 'registers an offense when using `#eval` with a string on a new line ' do
expect_offense(<<-RUBY.strip_indent)
eval('puts 42',
binding,
__FILE__,
__LINE__)
^^^^^^^^ Use `__LINE__ - 3` instead of `__LINE__`, as they are used by backtraces.
RUBY
end

it 'registers an offense when using `#class_eval` without any arguments' do
expect_offense(<<-RUBY.strip_indent)
C.class_eval <<-CODE
Expand Down

0 comments on commit 6fb5a84

Please sign in to comment.