Skip to content

Commit

Permalink
Fix expect_offense when annotations missing
Browse files Browse the repository at this point in the history
Fix crash in expect_offense where multiple offenses are detected by the
cop by some were not included in the annotated source. For example:

```ruby
expect_offense(<<~RUBY)
  x % 2 == 0
  ^^^^^^^^^^ Replace with `Integer#even?`
  x % 2 != 0
  # second offense missing
RUBY
```
  • Loading branch information
biinari authored and bbatsov committed Jul 13, 2020
1 parent 34a2dbd commit 930b65f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion lib/rubocop/rspec/expect_offense.rb
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ def ==(other)
def match_annotations?(other)
annotations.zip(other.annotations) do |(_actual_line, actual_annotation),
(_expected_line, expected_annotation)|
if expected_annotation.end_with?(ABBREV)
if expected_annotation&.end_with?(ABBREV)
if actual_annotation.start_with?(expected_annotation[0...-ABBREV.length])
expected_annotation.replace(actual_annotation)
end
Expand Down

0 comments on commit 930b65f

Please sign in to comment.