Skip to content

Commit

Permalink
Fix an offense creation for Lint/EmptyFile
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima authored and bbatsov committed Sep 14, 2020
1 parent d9e04a7 commit 4b6b6c8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -15,6 +15,7 @@
* [#8627](https://github.com/rubocop-hq/rubocop/issues/8627): Fix a false positive for `Lint/DuplicateRequire` when same feature argument but different require method. ([@koic][])
* [#8674](https://github.com/rubocop-hq/rubocop/issues/8674): Fix an error for `Layout/EmptyLineAfterMultilineCondition` when conditional is at the top level. ([@fatkodima][])
* [#8658](https://github.com/rubocop-hq/rubocop/pull/8658): Fix a false positive for `Style/RedundantSelfAssignment` when calling coercion methods. ([@fatkodima][])
* [#8669](https://github.com/rubocop-hq/rubocop/issues/8669): Fix an offense creation for `Lint/EmptyFile`. ([@fatkodima][])
* [#8607](https://github.com/rubocop-hq/rubocop/issues/8607): Fix a false positive for `Lint/UnreachableLoop` when conditional branch includes continue statement preceding break statement. ([@fatkodima][])
* [#8572](https://github.com/rubocop-hq/rubocop/issues/8572): Fix a false positive for `Style/RedundantParentheses` when parentheses are used like method argument parentheses. ([@koic][])
* [#8630](https://github.com/rubocop-hq/rubocop/issues/8630): Fix some false positives for `Style/HashTransformKeys` and `Style/HashTransformValues` when the receiver is an array. ([@eugeneius][])
Expand Down
5 changes: 1 addition & 4 deletions lib/rubocop/cop/lint/empty_file.rb
Expand Up @@ -26,10 +26,7 @@ class EmptyFile < Base
MSG = 'Empty file detected.'

def on_new_investigation
return unless offending?

range = source_range(processed_source.buffer, 1, 0)
add_offense(range)
add_global_offense(MSG) if offending?
end

private
Expand Down
18 changes: 9 additions & 9 deletions spec/rubocop/cop/lint/empty_file_spec.rb
@@ -1,16 +1,18 @@
# frozen_string_literal: true

RSpec.describe RuboCop::Cop::Lint::EmptyFile, :config do
subject(:cop) { described_class.new(config) }

let(:commissioner) { RuboCop::Cop::Commissioner.new([cop]) }
let(:offenses) { commissioner.investigate(processed_source).offenses }
let(:cop_config) do
{ 'AllowComments' => true }
end
let(:source) { '' }

it 'registers an offense when the file is empty' do
expect_offense(<<~RUBY)
^ Empty file detected.
RUBY
expect(offenses.size).to eq(1)
offense = offenses.first
expect(offense.message).to eq('Empty file detected.')
expect(offense.severity).to eq(:warning)
end

it 'does not register an offense when the file contains code' do
Expand All @@ -29,12 +31,10 @@
let(:cop_config) do
{ 'AllowComments' => false }
end
let(:source) { '# comment' }

it 'registers an offense when the file contains comments' do
expect_offense(<<~RUBY)
# comment
^ Empty file detected.
RUBY
expect(offenses.size).to eq(1)
end
end
end

0 comments on commit 4b6b6c8

Please sign in to comment.