Skip to content

Commit

Permalink
Merge pull request #1410 from rubocop/bquorning.enable-some-new-cops
Browse files Browse the repository at this point in the history
Enable some new cops
  • Loading branch information
pirj authored Oct 13, 2022
2 parents 4a05fd3 + 7b5b940 commit 494de00
Show file tree
Hide file tree
Showing 17 changed files with 64 additions and 56 deletions.
9 changes: 9 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,15 @@ Style/FormatStringToken:
Exclude:
- spec/rubocop/**/*.rb

# Enable some of RuboCop's pending cops.

Layout/LineContinuationSpacing:
Enabled: true
Layout/LineEndStringConcatenationIndentation:
Enabled: true
Style/EmptyHeredoc:
Enabled: true

# Enable our own pending cops.

RSpec/BeEq:
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/change_by_zero.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class ChangeByZero < Base
extend AutoCorrector
MSG = 'Prefer `not_to change` over `to change.by(0)`.'
MSG_COMPOUND = 'Prefer %<preferred>s with compound expectations ' \
'over `change.by(0)`.'
'over `change.by(0)`.'
RESTRICT_ON_SEND = %i[change].freeze

# @!method expect_change_with_arguments(node)
Expand Down
4 changes: 2 additions & 2 deletions lib/rubocop/cop/rspec/factory_bot/create_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,8 @@ def format_multiline_block(node)
indent = ' ' * node.body.loc.column
indent_end = ' ' * node.parent.loc.column
" do #{node.arguments.source}\n" \
"#{indent}#{node.body.source}\n" \
"#{indent_end}end"
"#{indent}#{node.body.source}\n" \
"#{indent_end}end"
end

def format_singleline_block(node)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/rspec/repeated_include_example.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ module RSpec
#
class RepeatedIncludeExample < Base
MSG = 'Repeated include of shared_examples %<name>s ' \
'on line(s) %<repeat>s'
'on line(s) %<repeat>s'

# @!method several_include_examples?(node)
def_node_matcher :several_include_examples?, <<-PATTERN
Expand Down
2 changes: 1 addition & 1 deletion spec/rubocop/cli/autocorrect_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
include_context 'when cli spec behavior'

context 'when corrects `RSpec/Capybara/CurrentPathExpectation` with ' \
'`Style/TrailingCommaInArguments`' do
'`Style/TrailingCommaInArguments`' do
before do
RuboCop::ConfigLoader
.default_configuration
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cop/rspec/before_after_all_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
RSpec.describe RuboCop::Cop::RSpec::BeforeAfterAll do
def message(hook)
"Beware of using `#{hook}` as it may cause state to leak between tests. " \
'If you are using `rspec-rails`, and `use_transactional_fixtures` is ' \
"enabled, then records created in `#{hook}` are not automatically rolled " \
'back.'
'If you are using `rspec-rails`, and `use_transactional_fixtures` is ' \
"enabled, then records created in `#{hook}` are not automatically " \
'rolled back.'
end

context 'when using before all' do
Expand Down
14 changes: 7 additions & 7 deletions spec/rubocop/cop/rspec/capybara/specific_finders_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
end

it 'registers an offense when using `find` and other args ' \
'with no parentheses' do
'with no parentheses' do
expect_offense(<<~RUBY)
find '#some-id', exact_text: 'foo'
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
Expand All @@ -60,7 +60,7 @@
end

it 'registers an offense when using `find ' \
'with argument is attribute specified id' do
'with argument is attribute specified id' do
expect_offense(<<~RUBY)
find('[id=some-id]')
^^^^^^^^^^^^^^^^^^^^ Prefer `find_by` over `find`.
Expand All @@ -78,29 +78,29 @@
end

it 'does not register an offense when using `find ' \
'with argument is attribute not specified id' do
'with argument is attribute not specified id' do
expect_no_offenses(<<~RUBY)
find('[visible]')
find('[class=some-cls][visible]')
RUBY
end

it 'does not register an offense when using `find ' \
'with argument is element with id' do
'with argument is element with id' do
expect_no_offenses(<<~RUBY)
find('h1#some-id')
RUBY
end

it 'does not register an offense when using `find ' \
'with argument is element with attribute specified id' do
'with argument is element with attribute specified id' do
expect_no_offenses(<<~RUBY)
find('h1[id=some-id]')
RUBY
end

it 'does not register an offense when using `find` ' \
'with argument is not id' do
'with argument is not id' do
expect_no_offenses(<<~RUBY)
find('a.some-id')
find('.some-id')
Expand All @@ -114,7 +114,7 @@
end

it 'does not register an offense when using `find` ' \
'with argument is id with multiple matcher' do
'with argument is id with multiple matcher' do
expect_no_offenses(<<~RUBY)
find('#some-id body')
find('#some-id>h1')
Expand Down
22 changes: 11 additions & 11 deletions spec/rubocop/cop/rspec/capybara/specific_matcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

RSpec.describe RuboCop::Cop::RSpec::Capybara::SpecificMatcher do
it 'does not register an offense for abstract matcher when ' \
'first argument is not a replaceable element' do
'first argument is not a replaceable element' do
expect_no_offenses(<<-RUBY)
expect(page).to have_selector('article')
expect(page).to have_no_selector('body')
Expand All @@ -11,7 +11,7 @@
end

it 'does not register an offense for abstract matcher when ' \
'first argument is not an element' do
'first argument is not an element' do
expect_no_offenses(<<-RUBY)
expect(page).to have_no_css('.a')
expect(page).to have_selector('#button')
Expand Down Expand Up @@ -206,7 +206,7 @@ class style visible obscured exact exact_text normalize_ws match wait
end

it 'registers an offense when using abstract matcher with ' \
'first argument is element with replaceable pseudo-classes' do
'first argument is element with replaceable pseudo-classes' do
expect_offense(<<-RUBY)
expect(page).to have_css('button:not([disabled])', exact_text: 'bar')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `have_button` over `have_css`.
Expand All @@ -216,7 +216,7 @@ class style visible obscured exact exact_text normalize_ws match wait
end

it 'registers an offense when using abstract matcher with ' \
'first argument is element with multiple replaceable pseudo-classes' do
'first argument is element with multiple replaceable pseudo-classes' do
expect_offense(<<-RUBY)
expect(page).to have_css('button:not([disabled]):enabled')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Prefer `have_button` over `have_css`.
Expand All @@ -234,22 +234,22 @@ class style visible obscured exact exact_text normalize_ws match wait
end

it 'does not register an offense when using abstract matcher with ' \
'first argument is element with replaceable pseudo-classes' \
'and not boolean attributes' do
'first argument is element with replaceable pseudo-classes' \
'and not boolean attributes' do
expect_no_offenses(<<-RUBY)
expect(page).to have_css('button:not([name="foo"][disabled])')
RUBY
end

it 'does not register an offense when using abstract matcher with ' \
'first argument is element with multiple nonreplaceable pseudo-classes' do
'first argument is element with multiple nonreplaceable pseudo-classes' do
expect_no_offenses(<<-RUBY)
expect(page).to have_css('button:first-of-type:not([disabled])')
RUBY
end

it 'does not register an offense for abstract matcher when ' \
'first argument is element with nonreplaceable attributes' do
'first argument is element with nonreplaceable attributes' do
expect_no_offenses(<<-RUBY)
expect(page).to have_css('button[data-disabled]')
expect(page).to have_css('button[foo=bar]')
Expand All @@ -258,7 +258,7 @@ class style visible obscured exact exact_text normalize_ws match wait
end

it 'does not register an offense for abstract matcher when ' \
'first argument is element with multiple nonreplaceable attributes' do
'first argument is element with multiple nonreplaceable attributes' do
expect_no_offenses(<<-RUBY)
expect(page).to have_css('button[disabled][foo]')
expect(page).to have_css('button[foo][disabled]')
Expand All @@ -269,7 +269,7 @@ class style visible obscured exact exact_text normalize_ws match wait
end

it 'does not register an offense for abstract matcher when ' \
'first argument is element with sub matcher' do
'first argument is element with sub matcher' do
expect_no_offenses(<<-RUBY)
expect(page).to have_css('button body')
expect(page).to have_css('a,h1')
Expand All @@ -279,7 +279,7 @@ class style visible obscured exact exact_text normalize_ws match wait
end

it 'does not register an offense for abstract matcher when ' \
'first argument is dstr' do
'first argument is dstr' do
expect_no_offenses(<<-'RUBY')
expect(page).to have_css(%{a[href="#{foo}"]}, text: "bar")
RUBY
Expand Down
22 changes: 11 additions & 11 deletions spec/rubocop/cop/rspec/change_by_zero_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

context 'when `NegatedMatcher` is not defined (default)' do
it 'registers an offense when the argument to `by` is zero ' \
'with compound expectations by `and`' do
'with compound expectations by `and`' do
expect_offense(<<-RUBY)
it do
expect { foo }.to change(Foo, :bar).by(0).and change(Foo, :baz).by(0)
Expand All @@ -43,7 +43,7 @@
end

it 'registers an offense when the argument to `by` is zero ' \
'with compound expectations by `&`' do
'with compound expectations by `&`' do
expect_offense(<<-RUBY)
it do
expect { foo }.to change(Foo, :bar).by(0) & change(Foo, :baz).by(0)
Expand All @@ -59,7 +59,7 @@
end

it 'registers an offense when the argument to `by` is zero ' \
'with compound expectations by `or`' do
'with compound expectations by `or`' do
expect_offense(<<-RUBY)
it do
expect { foo }.to change(Foo, :bar).by(0).or change(Foo, :baz).by(0)
Expand All @@ -75,7 +75,7 @@
end

it 'registers an offense when the argument to `by` is zero ' \
'with compound expectations by `|`' do
'with compound expectations by `|`' do
expect_offense(<<-RUBY)
it do
expect { foo }.to change(Foo, :bar).by(0) | change(Foo, :baz).by(0)
Expand All @@ -92,7 +92,7 @@

context 'when with a line break' do
it 'registers an offense when the argument to `by` is zero ' \
'with compound expectations by `and`' do
'with compound expectations by `and`' do
expect_offense(<<-RUBY)
it do
expect { foo }
Expand All @@ -112,7 +112,7 @@
end

it 'registers an offense when the argument to `by` is zero ' \
'with compound expectations by `&`' do
'with compound expectations by `&`' do
expect_offense(<<-RUBY)
it do
expect { foo }
Expand All @@ -132,7 +132,7 @@
end

it 'registers an offense when the argument to `by` is zero ' \
'with compound expectations by `or`' do
'with compound expectations by `or`' do
expect_offense(<<-RUBY)
it do
expect { foo }
Expand All @@ -152,7 +152,7 @@
end

it 'registers an offense when the argument to `by` is zero ' \
'with compound expectations by `|`' do
'with compound expectations by `|`' do
expect_offense(<<-RUBY)
it do
expect { foo }
Expand All @@ -177,7 +177,7 @@
let(:cop_config) { { 'NegatedMatcher' => 'not_change' } }

it 'registers an offense and autocorrect when ' \
'the argument to `by` is zero with compound expectations' do
'the argument to `by` is zero with compound expectations' do
expect_offense(<<-RUBY)
it do
expect { foo }.to change(Foo, :bar).by(0).and change(Foo, :baz).by(0)
Expand All @@ -198,8 +198,8 @@
end

it 'registers an offense and autocorrect when ' \
'the argument to `by` is zero with compound expectations ' \
'with line break' do
'the argument to `by` is zero with compound expectations ' \
'with line break' do
expect_offense(<<-RUBY)
it do
expect { foo }
Expand Down
5 changes: 2 additions & 3 deletions spec/rubocop/cop/rspec/empty_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@
end
RUBY

expect_correction(<<~RUBY)
RUBY
expect_correction('')
end

it 'flags example group with examples defined in hooks' do
Expand Down Expand Up @@ -160,7 +159,7 @@
end

it 'flags an empty example group with no examples defined in `case`' \
'branches' do
'branches' do
expect_offense(<<~RUBY)
describe Foo do
^^^^^^^^^^^^ Empty example group detected.
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/rspec/empty_line_after_example_group_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@
RUBY
end

it 'flags a missing empty line after a `rubocop:enable` directive '\
'when it is followed by a `rubocop:disable` directive' do
it 'flags a missing empty line after a `rubocop:enable` directive ' \
'when it is followed by a `rubocop:disable` directive' do
expect_offense(<<-RUBY)
RSpec.describe Foo do
# rubocop:disable RSpec/Foo
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/rspec/empty_line_after_example_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@
RUBY
end

it 'flags a missing empty line after a `rubocop:enable` directive '\
'when it is followed by a `rubocop:disable` directive' do
it 'flags a missing empty line after a `rubocop:enable` directive ' \
'when it is followed by a `rubocop:disable` directive' do
expect_offense(<<-RUBY)
RSpec.describe Foo do
# rubocop:disable RSpec/Foo
Expand Down
6 changes: 3 additions & 3 deletions spec/rubocop/cop/rspec/empty_line_after_final_let_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
RUBY
end

it 'does not register an offense for comment '\
it 'does not register an offense for comment ' \
'followed by an empty line after let' do
expect_no_offenses(<<-RUBY)
RSpec.describe User do
Expand Down Expand Up @@ -183,8 +183,8 @@
RUBY
end

it 'flags a missing empty line after a `rubocop:enable` directive '\
'when it is followed by a `rubocop:disable` directive' do
it 'flags a missing empty line after a `rubocop:enable` directive ' \
'when it is followed by a `rubocop:disable` directive' do
expect_offense(<<-RUBY)
RSpec.describe User do
# rubocop:disable RSpec/Foo
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/rspec/empty_line_after_hook_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@
RUBY
end

it 'flags a missing empty line after a `rubocop:enable` directive '\
'when it is followed by a `rubocop:disable` directive' do
it 'flags a missing empty line after a `rubocop:enable` directive ' \
'when it is followed by a `rubocop:disable` directive' do
expect_offense(<<-RUBY)
RSpec.describe User do
# rubocop:disable RSpec/Foo
Expand Down
4 changes: 2 additions & 2 deletions spec/rubocop/cop/rspec/empty_line_after_subject_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@
RUBY
end

it 'flags a missing empty line after a `rubocop:enable` directive '\
'when it is followed by a `rubocop:disable` directive' do
it 'flags a missing empty line after a `rubocop:enable` directive ' \
'when it is followed by a `rubocop:disable` directive' do
expect_offense(<<-RUBY)
RSpec.describe User do
# rubocop:disable RSpec/Foo
Expand Down
Loading

0 comments on commit 494de00

Please sign in to comment.