Skip to content

Commit

Permalink
Merge pull request #13163 from Homebrew/dependabot/bundler/Library/Ho…
Browse files Browse the repository at this point in the history
…mebrew/rubocop-rspec-2.10.0

build(deps): bump rubocop-rspec from 2.9.0 to 2.10.0 in /Library/Homebrew
  • Loading branch information
MikeMcQuaid authored Apr 21, 2022
2 parents 92e4a5e + 4ffc697 commit c1a9ce6
Show file tree
Hide file tree
Showing 124 changed files with 260 additions and 94 deletions.
2 changes: 1 addition & 1 deletion Library/Homebrew/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ GEM
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.7.0, < 2.0)
rubocop-rspec (2.9.0)
rubocop-rspec (2.10.0)
rubocop (~> 1.19)
rubocop-sorbet (0.6.7)
rubocop (>= 0.90.0)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Library/Homebrew/vendor/bundle/bundler/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.27.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.13.3/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.14.2/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.9.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.10.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.6.7/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-3.0.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-html-0.12.3/lib"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,14 @@ RSpec/BeEql:
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeEql

RSpec/BeNil:
Description: Check that `be_nil` is used instead of `be(nil)`.
Description: Ensures a consistent style is used when matching `nil`.
Enabled: pending
EnforcedStyle: be_nil
SupportedStyles:
- be
- be_nil
VersionAdded: 2.9.0
VersionChanged: 2.10.0
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/BeNil

RSpec/BeforeAfterAll:
Expand Down Expand Up @@ -761,6 +766,16 @@ RSpec/VariableName:
VersionChanged: '1.43'
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VariableName

RSpec/VerifiedDoubleReference:
Description: Checks for consistent verified double reference style.
Enabled: pending
EnforcedStyle: constant
SupportedStyles:
- constant
- string
VersionAdded: 2.10.0
Reference: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/VerifiedDoubleReference

RSpec/VerifiedDoubles:
Description: Prefer using verifying doubles over normal doubles.
Enabled: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,21 @@
# We have to register our autocorrect incompatibilities in RuboCop's cops
# as well so we do not hit infinite loops

module RuboCop
module Cop
module Layout
class ExtraSpacing # rubocop:disable Style/Documentation
def self.autocorrect_incompatible_with
[RSpec::AlignLeftLetBrace, RSpec::AlignRightLetBrace]
end
end
RuboCop::Cop::Layout::ExtraSpacing.singleton_class.prepend(
Module.new do
def autocorrect_incompatible_with
super.push(RuboCop::Cop::RSpec::AlignLeftLetBrace)
.push(RuboCop::Cop::RSpec::AlignRightLetBrace)
end
end
end
)

RuboCop::Cop::Style::TrailingCommaInArguments.singleton_class.prepend(
Module.new do
def autocorrect_incompatible_with
super.push(RuboCop::Cop::RSpec::Capybara::CurrentPathExpectation)
end
end
)

RuboCop::AST::Node.include(RuboCop::RSpec::Node)
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
# frozen_string_literal: true

module RuboCop
module Cop
module RSpec
# Ensures a consistent style is used when matching `nil`.
#
# You can either use the more specific `be_nil` matcher, or the more
# generic `be` matcher with a `nil` argument.
#
# This cop can be configured using the `EnforcedStyle` option
#
# @example `EnforcedStyle: be_nil` (default)
# # bad
# expect(foo).to be(nil)
#
# # good
# expect(foo).to be_nil
#
# @example `EnforcedStyle: be`
# # bad
# expect(foo).to be_nil
#
# # good
# expect(foo).to be(nil)
#
class BeNil < Base
extend AutoCorrector
include ConfigurableEnforcedStyle

BE_MSG = 'Prefer `be(nil)` over `be_nil`.'
BE_NIL_MSG = 'Prefer `be_nil` over `be(nil)`.'
RESTRICT_ON_SEND = %i[be be_nil].freeze

# @!method be_nil_matcher?(node)
def_node_matcher :be_nil_matcher?, <<-PATTERN
(send nil? :be_nil)
PATTERN

# @!method nil_value_expectation?(node)
def_node_matcher :nil_value_expectation?, <<-PATTERN
(send nil? :be nil)
PATTERN

def on_send(node)
case style
when :be
check_be_style(node)
when :be_nil
check_be_nil_style(node)
end
end

private

def check_be_style(node)
return unless be_nil_matcher?(node)

add_offense(node, message: BE_MSG) do |corrector|
corrector.replace(node.loc.expression, 'be(nil)')
end
end

def check_be_nil_style(node)
return unless nil_value_expectation?(node)

add_offense(node, message: BE_NIL_MSG) do |corrector|
corrector.replace(node.loc.expression, 'be_nil')
end
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ class CurrentPathExpectation < Base
$(send nil? :match (str $_)))
PATTERN

def self.autocorrect_incompatible_with
[Style::TrailingCommaInArguments]
end

def on_send(node)
expectation_set_on_current_path(node) do
add_offense(node.loc.selector) do |corrector|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,23 +145,23 @@ def offensive?(body)
return true unless body
return false if conditionals_with_examples?(body)

if body.if_type?
if body.if_type? || body.case_type?
!examples_in_branches?(body)
else
!examples?(body)
end
end

def conditionals_with_examples?(body)
return unless body.begin_type?
return unless body.begin_type? || body.case_type?

body.each_descendant(:if).any? do |if_node|
examples_in_branches?(if_node)
body.each_descendant(:if, :case).any? do |condition_node|
examples_in_branches?(condition_node)
end
end

def examples_in_branches?(if_node)
if_node.branches.any? { |branch| examples?(branch) }
def examples_in_branches?(condition_node)
condition_node.branches.any? { |branch| examples?(branch) }
end
end
end
Expand Down
Loading

0 comments on commit c1a9ce6

Please sign in to comment.