Skip to content

Commit

Permalink
Fix line number for empty file offense
Browse files Browse the repository at this point in the history
An offense added by a cop to an empty file with have line number = 1.
For example:

```ruby
RSpec.describe RuboCop::Cop::Style::Copyright, :config do
  context 'when the source code file is empty' do
    it 'registers an offense' do
      expect_offense('^ Include a copyright notice matching [...]')
    end
  end
end
```

Ensure the line number matches for `expect_offense` on an empty file.
  • Loading branch information
biinari authored and bbatsov committed Jul 13, 2020
1 parent 930b65f commit 0c786c0
Showing 1 changed file with 1 addition and 0 deletions.
1 change: 1 addition & 0 deletions lib/rubocop/rspec/expect_offense.rb
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ def self.parse(annotated_source)
source << source_line
end
end
annotations.each { |a| a[0] = 1 } if source.empty?

new(source, annotations)
end
Expand Down

0 comments on commit 0c786c0

Please sign in to comment.