Merge pull request #6123 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-0.69.0
build: bump rubocop from 0.68.1 to 0.69.0 in /Library/Homebrew
This commit is contained in:
commit
1226a82067
@ -80,16 +80,16 @@ GEM
|
|||||||
rspec-support (3.8.0)
|
rspec-support (3.8.0)
|
||||||
rspec-wait (0.0.9)
|
rspec-wait (0.0.9)
|
||||||
rspec (>= 3, < 4)
|
rspec (>= 3, < 4)
|
||||||
rubocop (0.68.1)
|
rubocop (0.69.0)
|
||||||
jaro_winkler (~> 1.5.1)
|
jaro_winkler (~> 1.5.1)
|
||||||
parallel (~> 1.10)
|
parallel (~> 1.10)
|
||||||
parser (>= 2.5, != 2.5.1.1)
|
parser (>= 2.6)
|
||||||
rainbow (>= 2.2.2, < 4.0)
|
rainbow (>= 2.2.2, < 4.0)
|
||||||
ruby-progressbar (~> 1.7)
|
ruby-progressbar (~> 1.7)
|
||||||
unicode-display_width (>= 1.4.0, < 1.6)
|
unicode-display_width (>= 1.4.0, < 1.7)
|
||||||
rubocop-performance (1.2.0)
|
rubocop-performance (1.2.0)
|
||||||
rubocop (>= 0.68.0)
|
rubocop (>= 0.68.0)
|
||||||
rubocop-rspec (1.32.0)
|
rubocop-rspec (1.33.0)
|
||||||
rubocop (>= 0.60.0)
|
rubocop (>= 0.60.0)
|
||||||
ruby-macho (2.2.0)
|
ruby-macho (2.2.0)
|
||||||
ruby-progressbar (1.10.0)
|
ruby-progressbar (1.10.0)
|
||||||
@ -110,7 +110,7 @@ GEM
|
|||||||
unf (0.1.4)
|
unf (0.1.4)
|
||||||
unf_ext
|
unf_ext
|
||||||
unf_ext (0.0.7.6)
|
unf_ext (0.0.7.6)
|
||||||
unicode-display_width (1.5.0)
|
unicode-display_width (1.6.0)
|
||||||
webrobots (0.1.2)
|
webrobots (0.1.2)
|
||||||
|
|
||||||
PLATFORMS
|
PLATFORMS
|
||||||
|
|||||||
@ -60,9 +60,9 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-its-1.3.0/lib"
|
|||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-retry-0.6.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-retry-0.6.1/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-wait-0.0.9/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-wait-0.0.9/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.10.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.10.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-1.5.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-1.6.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.68.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-0.69.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.2.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.2.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-1.32.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-1.33.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.2.0/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.2.0/lib"
|
||||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-cobertura-1.3.1/lib"
|
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/simplecov-cobertura-1.3.1/lib"
|
||||||
|
|||||||
@ -83,6 +83,12 @@ RSpec/DescribedClass:
|
|||||||
- explicit
|
- explicit
|
||||||
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClass
|
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/DescribedClass
|
||||||
|
|
||||||
|
RSpec/Dialect:
|
||||||
|
Description: This cop enforces custom RSpec dialects.
|
||||||
|
Enabled: false
|
||||||
|
PreferredMethods: {}
|
||||||
|
StyleGuide: http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Dialect
|
||||||
|
|
||||||
RSpec/EmptyExampleGroup:
|
RSpec/EmptyExampleGroup:
|
||||||
Description: Checks if an example group does not include any tests.
|
Description: Checks if an example group does not include any tests.
|
||||||
Enabled: true
|
Enabled: true
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'pathname'
|
require 'pathname'
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
|
|
||||||
@ -18,6 +20,7 @@ require_relative 'rubocop/rspec/example'
|
|||||||
require_relative 'rubocop/rspec/hook'
|
require_relative 'rubocop/rspec/hook'
|
||||||
require_relative 'rubocop/cop/rspec/cop'
|
require_relative 'rubocop/cop/rspec/cop'
|
||||||
require_relative 'rubocop/rspec/align_let_brace'
|
require_relative 'rubocop/rspec/align_let_brace'
|
||||||
|
require_relative 'rubocop/rspec/factory_bot'
|
||||||
require_relative 'rubocop/rspec/final_end_location'
|
require_relative 'rubocop/rspec/final_end_location'
|
||||||
require_relative 'rubocop/rspec/blank_line_separation'
|
require_relative 'rubocop/rspec/blank_line_separation'
|
||||||
|
|
||||||
@ -18,7 +18,7 @@ module RuboCop
|
|||||||
# let(:a) { b }
|
# let(:a) { b }
|
||||||
#
|
#
|
||||||
class AlignLeftLetBrace < Cop
|
class AlignLeftLetBrace < Cop
|
||||||
MSG = 'Align left let brace'.freeze
|
MSG = 'Align left let brace'
|
||||||
|
|
||||||
def self.autocorrect_incompatible_with
|
def self.autocorrect_incompatible_with
|
||||||
[Layout::ExtraSpacing]
|
[Layout::ExtraSpacing]
|
||||||
@ -18,7 +18,7 @@ module RuboCop
|
|||||||
# let(:a) { b }
|
# let(:a) { b }
|
||||||
#
|
#
|
||||||
class AlignRightLetBrace < Cop
|
class AlignRightLetBrace < Cop
|
||||||
MSG = 'Align right let brace'.freeze
|
MSG = 'Align right let brace'
|
||||||
|
|
||||||
def self.autocorrect_incompatible_with
|
def self.autocorrect_incompatible_with
|
||||||
[Layout::ExtraSpacing]
|
[Layout::ExtraSpacing]
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -21,7 +23,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
class AnyInstance < Cop
|
class AnyInstance < Cop
|
||||||
MSG = 'Avoid stubbing using `%<method>s`.'.freeze
|
MSG = 'Avoid stubbing using `%<method>s`.'
|
||||||
|
|
||||||
def_node_matcher :disallowed_stub, <<-PATTERN
|
def_node_matcher :disallowed_stub, <<-PATTERN
|
||||||
(send _ ${:any_instance :allow_any_instance_of :expect_any_instance_of} ...)
|
(send _ ${:any_instance :allow_any_instance_of :expect_any_instance_of} ...)
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -24,9 +26,9 @@ module RuboCop
|
|||||||
# test.run
|
# test.run
|
||||||
# end
|
# end
|
||||||
class AroundBlock < Cop
|
class AroundBlock < Cop
|
||||||
MSG_NO_ARG = 'Test object should be passed to around block.'.freeze
|
MSG_NO_ARG = 'Test object should be passed to around block.'
|
||||||
MSG_UNUSED_ARG = 'You should call `%<arg>s.call` '\
|
MSG_UNUSED_ARG = 'You should call `%<arg>s.call` '\
|
||||||
'or `%<arg>s.run`.'.freeze
|
'or `%<arg>s.run`.'
|
||||||
|
|
||||||
def_node_matcher :hook, <<-PATTERN
|
def_node_matcher :hook, <<-PATTERN
|
||||||
(block {(send nil? :around) (send nil? :around sym)} (args $...) ...)
|
(block {(send nil? :around) (send nil? :around sym)} (args $...) ...)
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -18,10 +20,10 @@ module RuboCop
|
|||||||
# expect(foo).to be(true)
|
# expect(foo).to be(true)
|
||||||
#
|
#
|
||||||
class Be < Cop
|
class Be < Cop
|
||||||
MSG = 'Don\'t use `be` without an argument.'.freeze
|
MSG = 'Don\'t use `be` without an argument.'
|
||||||
|
|
||||||
def_node_matcher :be_without_args, <<-PATTERN
|
def_node_matcher :be_without_args, <<-PATTERN
|
||||||
(send _ {:to :not_to :to_not} $(send nil? :be))
|
(send _ #{Runners::ALL.node_pattern_union} $(send nil? :be))
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -34,7 +36,7 @@ module RuboCop
|
|||||||
# coerce objects for comparison.
|
# coerce objects for comparison.
|
||||||
#
|
#
|
||||||
class BeEql < Cop
|
class BeEql < Cop
|
||||||
MSG = 'Prefer `be` over `eql`.'.freeze
|
MSG = 'Prefer `be` over `eql`.'
|
||||||
|
|
||||||
def_node_matcher :eql_type_with_identity, <<-PATTERN
|
def_node_matcher :eql_type_with_identity, <<-PATTERN
|
||||||
(send _ :to $(send nil? :eql {true false int float sym nil_type?}))
|
(send _ :to $(send nil? :eql {true false int float sym nil_type?}))
|
||||||
@ -27,7 +27,7 @@ module RuboCop
|
|||||||
MSG = 'Beware of using `%<hook>s` as it may cause state to leak '\
|
MSG = 'Beware of using `%<hook>s` as it may cause state to leak '\
|
||||||
'between tests. If you are using `rspec-rails`, and '\
|
'between tests. If you are using `rspec-rails`, and '\
|
||||||
'`use_transactional_fixtures` is enabled, then records created '\
|
'`use_transactional_fixtures` is enabled, then records created '\
|
||||||
'in `%<hook>s` are not automatically rolled back.'.freeze
|
'in `%<hook>s` are not automatically rolled back.'
|
||||||
|
|
||||||
def_node_matcher :before_or_after_all, <<-PATTERN
|
def_node_matcher :before_or_after_all, <<-PATTERN
|
||||||
$(send _ {:before :after} (sym {:all :context}))
|
$(send _ {:before :after} (sym {:all :context}))
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -24,7 +26,7 @@ module RuboCop
|
|||||||
class CurrentPathExpectation < Cop
|
class CurrentPathExpectation < Cop
|
||||||
MSG = 'Do not set an RSpec expectation on `current_path` in ' \
|
MSG = 'Do not set an RSpec expectation on `current_path` in ' \
|
||||||
'Capybara feature specs - instead, use the ' \
|
'Capybara feature specs - instead, use the ' \
|
||||||
'`have_current_path` matcher on `page`'.freeze
|
'`have_current_path` matcher on `page`'
|
||||||
|
|
||||||
def_node_matcher :expectation_set_on_current_path, <<-PATTERN
|
def_node_matcher :expectation_set_on_current_path, <<-PATTERN
|
||||||
(send nil? :expect (send {(send nil? :page) nil?} :current_path))
|
(send nil? :expect (send {(send nil? :page) nil?} :current_path))
|
||||||
@ -33,13 +35,13 @@ module RuboCop
|
|||||||
# Supported matchers: eq(...) / match(/regexp/) / match('regexp')
|
# Supported matchers: eq(...) / match(/regexp/) / match('regexp')
|
||||||
def_node_matcher :as_is_matcher, <<-PATTERN
|
def_node_matcher :as_is_matcher, <<-PATTERN
|
||||||
(send
|
(send
|
||||||
#expectation_set_on_current_path ${:to :not_to :to_not}
|
#expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
|
||||||
${(send nil? :eq ...) (send nil? :match (regexp ...))})
|
${(send nil? :eq ...) (send nil? :match (regexp ...))})
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def_node_matcher :regexp_str_matcher, <<-PATTERN
|
def_node_matcher :regexp_str_matcher, <<-PATTERN
|
||||||
(send
|
(send
|
||||||
#expectation_set_on_current_path ${:to :not_to :to_not}
|
#expectation_set_on_current_path $#{Runners::ALL.node_pattern_union}
|
||||||
$(send nil? :match (str $_)))
|
$(send nil? :match (str $_)))
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
@ -41,7 +41,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
# end
|
# end
|
||||||
class FeatureMethods < Cop
|
class FeatureMethods < Cop
|
||||||
MSG = 'Use `%<replacement>s` instead of `%<method>s`.'.freeze
|
MSG = 'Use `%<replacement>s` instead of `%<method>s`.'
|
||||||
|
|
||||||
# https://git.io/v7Kwr
|
# https://git.io/v7Kwr
|
||||||
MAP = {
|
MAP = {
|
||||||
@ -55,13 +55,13 @@ module RuboCop
|
|||||||
|
|
||||||
def_node_matcher :spec?, <<-PATTERN
|
def_node_matcher :spec?, <<-PATTERN
|
||||||
(block
|
(block
|
||||||
(send {(const nil? :RSpec) nil?} {:describe :feature} ...)
|
(send #{RSPEC} {:describe :feature} ...)
|
||||||
...)
|
...)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def_node_matcher :feature_method, <<-PATTERN
|
def_node_matcher :feature_method, <<-PATTERN
|
||||||
(block
|
(block
|
||||||
$(send {(const nil? :RSpec) nil?} ${#{MAP.keys.map(&:inspect).join(' ')}} ...)
|
$(send #{RSPEC} ${#{MAP.keys.map(&:inspect).join(' ')}} ...)
|
||||||
...)
|
...)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
@ -27,10 +27,10 @@ module RuboCop
|
|||||||
# # ...
|
# # ...
|
||||||
# end
|
# end
|
||||||
class ContextWording < Cop
|
class ContextWording < Cop
|
||||||
MSG = 'Start context description with %<prefixes>s.'.freeze
|
MSG = 'Start context description with %<prefixes>s.'
|
||||||
|
|
||||||
def_node_matcher :context_wording, <<-PATTERN
|
def_node_matcher :context_wording, <<-PATTERN
|
||||||
(block (send _ { :context :shared_context } $(str #bad_prefix?)) ...)
|
(block (send #{RSPEC} { :context :shared_context } $(str #bad_prefix?) ...) ...)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
@ -20,17 +20,17 @@ module RuboCop
|
|||||||
include RuboCop::RSpec::TopLevelDescribe
|
include RuboCop::RSpec::TopLevelDescribe
|
||||||
|
|
||||||
MSG = 'The first argument to describe should be '\
|
MSG = 'The first argument to describe should be '\
|
||||||
'the class or module being tested.'.freeze
|
'the class or module being tested.'
|
||||||
|
|
||||||
def_node_matcher :valid_describe?, <<-PATTERN
|
def_node_matcher :valid_describe?, <<-PATTERN
|
||||||
{
|
{
|
||||||
(send {(const nil? :RSpec) nil?} :describe const ...)
|
(send #{RSPEC} :describe const ...)
|
||||||
(send {(const nil? :RSpec) nil?} :describe)
|
(send #{RSPEC} :describe)
|
||||||
}
|
}
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def_node_matcher :describe_with_metadata, <<-PATTERN
|
def_node_matcher :describe_with_metadata, <<-PATTERN
|
||||||
(send {(const nil? :RSpec) nil?} :describe
|
(send #{RSPEC} :describe
|
||||||
!const
|
!const
|
||||||
...
|
...
|
||||||
(hash $...))
|
(hash $...))
|
||||||
@ -21,10 +21,10 @@ module RuboCop
|
|||||||
include RuboCop::RSpec::Util
|
include RuboCop::RSpec::Util
|
||||||
|
|
||||||
MSG = 'The second argument to describe should be the method '\
|
MSG = 'The second argument to describe should be the method '\
|
||||||
"being tested. '#instance' or '.class'.".freeze
|
"being tested. '#instance' or '.class'."
|
||||||
|
|
||||||
def on_top_level_describe(_node, (_, second_arg))
|
def on_top_level_describe(_node, (_, second_arg))
|
||||||
return unless second_arg && second_arg.str_type?
|
return unless second_arg&.str_type?
|
||||||
return if second_arg.str_content.start_with?('#', '.')
|
return if second_arg.str_content.start_with?('#', '.')
|
||||||
|
|
||||||
add_offense(second_arg, location: :expression)
|
add_offense(second_arg, location: :expression)
|
||||||
@ -18,10 +18,10 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
# @see https://github.com/rspec/rspec-core/issues/1610
|
# @see https://github.com/rspec/rspec-core/issues/1610
|
||||||
class DescribeSymbol < Cop
|
class DescribeSymbol < Cop
|
||||||
MSG = 'Avoid describing symbols.'.freeze
|
MSG = 'Avoid describing symbols.'
|
||||||
|
|
||||||
def_node_matcher :describe_symbol?, <<-PATTERN
|
def_node_matcher :describe_symbol?, <<-PATTERN
|
||||||
(send {(const nil? :RSpec) nil?} :describe $sym ...)
|
(send #{RSPEC} :describe $sym ...)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
@ -36,11 +36,11 @@ module RuboCop
|
|||||||
include RuboCop::RSpec::TopLevelDescribe
|
include RuboCop::RSpec::TopLevelDescribe
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
DESCRIBED_CLASS = 'described_class'.freeze
|
DESCRIBED_CLASS = 'described_class'
|
||||||
MSG = 'Use `%<replacement>s` instead of `%<src>s`.'.freeze
|
MSG = 'Use `%<replacement>s` instead of `%<src>s`.'
|
||||||
|
|
||||||
def_node_matcher :common_instance_exec_closure?, <<-PATTERN
|
def_node_matcher :common_instance_exec_closure?, <<-PATTERN
|
||||||
(block (send (const nil? {:Class :Module}) :new ...) ...)
|
(block (send (const nil? {:Class :Module :Struct}) :new ...) ...)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def_node_matcher :rspec_block?,
|
def_node_matcher :rspec_block?,
|
||||||
@ -0,0 +1,76 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module Cop
|
||||||
|
module RSpec
|
||||||
|
# This cop enforces custom RSpec dialects.
|
||||||
|
#
|
||||||
|
# A dialect can be based on the following RSpec methods:
|
||||||
|
#
|
||||||
|
# - describe, context, feature, example_group
|
||||||
|
# - xdescribe, xcontext, xfeature
|
||||||
|
# - fdescribe, fcontext, ffeature
|
||||||
|
# - shared_examples, shared_examples_for, shared_context
|
||||||
|
# - it, specify, example, scenario, its
|
||||||
|
# - fit, fspecify, fexample, fscenario, focus
|
||||||
|
# - xit, xspecify, xexample, xscenario, skip
|
||||||
|
# - pending
|
||||||
|
# - prepend_before, before, append_before,
|
||||||
|
# - around
|
||||||
|
# - prepend_after, after, append_after
|
||||||
|
# - let, let!
|
||||||
|
# - subject, subject!
|
||||||
|
# - expect, is_expected, expect_any_instance_of
|
||||||
|
#
|
||||||
|
# By default all of the RSpec methods and aliases are allowed. By setting
|
||||||
|
# a config like:
|
||||||
|
#
|
||||||
|
# RSpec/Dialect:
|
||||||
|
# PreferredMethods:
|
||||||
|
# context: describe
|
||||||
|
#
|
||||||
|
# You can expect the following behavior:
|
||||||
|
#
|
||||||
|
# @example
|
||||||
|
# # bad
|
||||||
|
# context 'display name presence' do
|
||||||
|
# # ...
|
||||||
|
# end
|
||||||
|
#
|
||||||
|
# # good
|
||||||
|
# describe 'display name presence' do
|
||||||
|
# # ...
|
||||||
|
# end
|
||||||
|
class Dialect < Cop
|
||||||
|
include MethodPreference
|
||||||
|
|
||||||
|
MSG = 'Prefer `%<prefer>s` over `%<current>s`.'
|
||||||
|
|
||||||
|
def_node_matcher :rspec_method?, ALL.send_pattern
|
||||||
|
|
||||||
|
def on_send(node)
|
||||||
|
return unless rspec_method?(node)
|
||||||
|
return unless preferred_methods[node.method_name]
|
||||||
|
|
||||||
|
add_offense(node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def autocorrect(node)
|
||||||
|
lambda do |corrector|
|
||||||
|
current = node.loc.selector
|
||||||
|
preferred = preferred_method(current.source)
|
||||||
|
|
||||||
|
corrector.replace(current, preferred)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def message(node)
|
||||||
|
format(MSG, prefer: preferred_method(node.method_name),
|
||||||
|
current: node.method_name)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -58,7 +58,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
class EmptyExampleGroup < Cop
|
class EmptyExampleGroup < Cop
|
||||||
MSG = 'Empty example group detected.'.freeze
|
MSG = 'Empty example group detected.'
|
||||||
|
|
||||||
def_node_search :contains_example?, <<-PATTERN
|
def_node_search :contains_example?, <<-PATTERN
|
||||||
{
|
{
|
||||||
@ -26,7 +26,7 @@ module RuboCop
|
|||||||
class EmptyLineAfterExampleGroup < Cop
|
class EmptyLineAfterExampleGroup < Cop
|
||||||
include RuboCop::RSpec::BlankLineSeparation
|
include RuboCop::RSpec::BlankLineSeparation
|
||||||
|
|
||||||
MSG = 'Add an empty line after `%<example_group>s`.'.freeze
|
MSG = 'Add an empty line after `%<example_group>s`.'
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
@ -19,7 +19,7 @@ module RuboCop
|
|||||||
class EmptyLineAfterFinalLet < Cop
|
class EmptyLineAfterFinalLet < Cop
|
||||||
include RuboCop::RSpec::BlankLineSeparation
|
include RuboCop::RSpec::BlankLineSeparation
|
||||||
|
|
||||||
MSG = 'Add an empty line after the last `let` block.'.freeze
|
MSG = 'Add an empty line after the last `let` block.'
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example_group_with_body?(node)
|
return unless example_group_with_body?(node)
|
||||||
@ -36,7 +36,7 @@ module RuboCop
|
|||||||
class EmptyLineAfterHook < Cop
|
class EmptyLineAfterHook < Cop
|
||||||
include RuboCop::RSpec::BlankLineSeparation
|
include RuboCop::RSpec::BlankLineSeparation
|
||||||
|
|
||||||
MSG = 'Add an empty line after `%<hook>s`.'.freeze
|
MSG = 'Add an empty line after `%<hook>s`.'
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless hook?(node)
|
return unless hook?(node)
|
||||||
@ -17,7 +17,7 @@ module RuboCop
|
|||||||
class EmptyLineAfterSubject < Cop
|
class EmptyLineAfterSubject < Cop
|
||||||
include RuboCop::RSpec::BlankLineSeparation
|
include RuboCop::RSpec::BlankLineSeparation
|
||||||
|
|
||||||
MSG = 'Add empty line after `subject`.'.freeze
|
MSG = 'Add empty line after `subject`.'
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless subject?(node) && !in_spec_block?(node)
|
return unless subject?(node) && !in_spec_block?(node)
|
||||||
@ -28,7 +28,7 @@ module RuboCop
|
|||||||
class ExampleLength < Cop
|
class ExampleLength < Cop
|
||||||
include CodeLength
|
include CodeLength
|
||||||
|
|
||||||
MSG = 'Example has too many lines [%<total>d/%<max>d].'.freeze
|
MSG = 'Example has too many lines [%<total>d/%<max>d].'
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example?(node)
|
return unless example?(node)
|
||||||
@ -51,8 +51,8 @@ module RuboCop
|
|||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
MSG_DEFAULT_ARGUMENT = 'Omit the argument when you want to ' \
|
MSG_DEFAULT_ARGUMENT = 'Omit the argument when you want to ' \
|
||||||
'have auto-generated description.'.freeze
|
'have auto-generated description.'
|
||||||
MSG_ADD_DESCRIPTION = 'Add a description.'.freeze
|
MSG_ADD_DESCRIPTION = 'Add a description.'
|
||||||
|
|
||||||
def_node_matcher :example_description, '(send nil? _ $(str $_))'
|
def_node_matcher :example_description, '(send nil? _ $(str $_))'
|
||||||
|
|
||||||
@ -30,8 +30,8 @@ module RuboCop
|
|||||||
# it 'does things' do
|
# it 'does things' do
|
||||||
# end
|
# end
|
||||||
class ExampleWording < Cop
|
class ExampleWording < Cop
|
||||||
MSG_SHOULD = 'Do not use should when describing your tests.'.freeze
|
MSG_SHOULD = 'Do not use should when describing your tests.'
|
||||||
MSG_IT = "Do not repeat 'it' when describing your tests.".freeze
|
MSG_IT = "Do not repeat 'it' when describing your tests."
|
||||||
|
|
||||||
SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
|
SHOULD_PREFIX = /\Ashould(?:n't)?\b/i.freeze
|
||||||
IT_PREFIX = /\Ait /i.freeze
|
IT_PREFIX = /\Ait /i.freeze
|
||||||
@ -17,7 +17,7 @@ module RuboCop
|
|||||||
# expect(name).to eq("John")
|
# expect(name).to eq("John")
|
||||||
#
|
#
|
||||||
class ExpectActual < Cop
|
class ExpectActual < Cop
|
||||||
MSG = 'Provide the actual you are testing to `expect(...)`.'.freeze
|
MSG = 'Provide the actual you are testing to `expect(...)`.'
|
||||||
|
|
||||||
SIMPLE_LITERALS = %i[
|
SIMPLE_LITERALS = %i[
|
||||||
true
|
true
|
||||||
@ -32,8 +32,8 @@ module RuboCop
|
|||||||
class ExpectChange < Cop
|
class ExpectChange < Cop
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
MSG_BLOCK = 'Prefer `change(%<obj>s, :%<attr>s)`.'.freeze
|
MSG_BLOCK = 'Prefer `change(%<obj>s, :%<attr>s)`.'
|
||||||
MSG_CALL = 'Prefer `change { %<obj>s.%<attr>s }`.'.freeze
|
MSG_CALL = 'Prefer `change { %<obj>s.%<attr>s }`.'
|
||||||
|
|
||||||
def_node_matcher :expect_change_with_arguments, <<-PATTERN
|
def_node_matcher :expect_change_with_arguments, <<-PATTERN
|
||||||
(send nil? :change ({const send} nil? $_) (sym $_))
|
(send nil? :change ({const send} nil? $_) (sym $_))
|
||||||
@ -21,7 +21,7 @@ module RuboCop
|
|||||||
# expect(something).to eq 'foo'
|
# expect(something).to eq 'foo'
|
||||||
# end
|
# end
|
||||||
class ExpectInHook < Cop
|
class ExpectInHook < Cop
|
||||||
MSG = 'Do not use `%<expect>s` in `%<hook>s` hook'.freeze
|
MSG = 'Do not use `%<expect>s` in `%<hook>s` hook'
|
||||||
|
|
||||||
def_node_search :expectation, Expectations::ALL.send_pattern
|
def_node_search :expectation, Expectations::ALL.send_pattern
|
||||||
|
|
||||||
@ -16,7 +16,7 @@ module RuboCop
|
|||||||
# expect { my_app.print_report }.to output('Hello World').to_stdout
|
# expect { my_app.print_report }.to output('Hello World').to_stdout
|
||||||
class ExpectOutput < Cop
|
class ExpectOutput < Cop
|
||||||
MSG = 'Use `expect { ... }.to output(...).to_%<name>s` '\
|
MSG = 'Use `expect { ... }.to output(...).to_%<name>s` '\
|
||||||
'instead of mutating $%<name>s.'.freeze
|
'instead of mutating $%<name>s.'
|
||||||
|
|
||||||
def on_gvasgn(node)
|
def on_gvasgn(node)
|
||||||
return unless inside_example_scope?(node)
|
return unless inside_example_scope?(node)
|
||||||
@ -25,53 +25,19 @@ module RuboCop
|
|||||||
# # good
|
# # good
|
||||||
# count { 1 }
|
# count { 1 }
|
||||||
class AttributeDefinedStatically < Cop
|
class AttributeDefinedStatically < Cop
|
||||||
MSG = 'Use a block to declare attribute values.'.freeze
|
MSG = 'Use a block to declare attribute values.'
|
||||||
|
|
||||||
ATTRIBUTE_DEFINING_METHODS = %i[factory trait transient ignore].freeze
|
|
||||||
|
|
||||||
UNPROXIED_METHODS = %i[
|
|
||||||
__send__
|
|
||||||
__id__
|
|
||||||
nil?
|
|
||||||
send
|
|
||||||
object_id
|
|
||||||
extend
|
|
||||||
instance_eval
|
|
||||||
initialize
|
|
||||||
block_given?
|
|
||||||
raise
|
|
||||||
caller
|
|
||||||
method
|
|
||||||
].freeze
|
|
||||||
|
|
||||||
DEFINITION_PROXY_METHODS = %i[
|
|
||||||
add_attribute
|
|
||||||
after
|
|
||||||
association
|
|
||||||
before
|
|
||||||
callback
|
|
||||||
ignore
|
|
||||||
initialize_with
|
|
||||||
sequence
|
|
||||||
skip_create
|
|
||||||
to_create
|
|
||||||
].freeze
|
|
||||||
|
|
||||||
RESERVED_METHODS =
|
|
||||||
DEFINITION_PROXY_METHODS +
|
|
||||||
UNPROXIED_METHODS +
|
|
||||||
ATTRIBUTE_DEFINING_METHODS
|
|
||||||
|
|
||||||
def_node_matcher :value_matcher, <<-PATTERN
|
def_node_matcher :value_matcher, <<-PATTERN
|
||||||
(send {self nil?} !#reserved_method? $...)
|
(send _ !#reserved_method? $...)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def_node_search :factory_attributes, <<-PATTERN
|
def_node_search :factory_attributes, <<-PATTERN
|
||||||
(block (send nil? #attribute_defining_method? ...) _ { (begin $...) $(send ...) } )
|
(block (send _ #attribute_defining_method? ...) _ { (begin $...) $(send ...) } )
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
factory_attributes(node).to_a.flatten.each do |attribute|
|
factory_attributes(node).to_a.flatten.each do |attribute|
|
||||||
|
next unless offensive_receiver?(attribute.receiver, node)
|
||||||
next if proc?(attribute) || association?(attribute)
|
next if proc?(attribute) || association?(attribute)
|
||||||
|
|
||||||
add_offense(attribute, location: :expression)
|
add_offense(attribute, location: :expression)
|
||||||
@ -88,6 +54,20 @@ module RuboCop
|
|||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
def offensive_receiver?(receiver, node)
|
||||||
|
receiver.nil? ||
|
||||||
|
receiver.self_type? ||
|
||||||
|
receiver_matches_first_block_argument?(receiver, node)
|
||||||
|
end
|
||||||
|
|
||||||
|
def receiver_matches_first_block_argument?(receiver, node)
|
||||||
|
first_block_argument = node.arguments.first
|
||||||
|
|
||||||
|
!first_block_argument.nil? &&
|
||||||
|
receiver.lvar_type? &&
|
||||||
|
receiver.node_parts == first_block_argument.node_parts
|
||||||
|
end
|
||||||
|
|
||||||
def proc?(attribute)
|
def proc?(attribute)
|
||||||
value_matcher(attribute).to_a.all?(&:block_pass_type?)
|
value_matcher(attribute).to_a.all?(&:block_pass_type?)
|
||||||
end
|
end
|
||||||
@ -134,11 +114,12 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def reserved_method?(method_name)
|
def reserved_method?(method_name)
|
||||||
RESERVED_METHODS.include?(method_name)
|
RuboCop::RSpec::FactoryBot.reserved_methods.include?(method_name)
|
||||||
end
|
end
|
||||||
|
|
||||||
def attribute_defining_method?(method_name)
|
def attribute_defining_method?(method_name)
|
||||||
ATTRIBUTE_DEFINING_METHODS.include?(method_name)
|
RuboCop::RSpec::FactoryBot.attribute_defining_methods
|
||||||
|
.include?(method_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -27,8 +27,8 @@ module RuboCop
|
|||||||
class CreateList < Cop
|
class CreateList < Cop
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
MSG_CREATE_LIST = 'Prefer create_list.'.freeze
|
MSG_CREATE_LIST = 'Prefer create_list.'
|
||||||
MSG_N_TIMES = 'Prefer %<number>s.times.'.freeze
|
MSG_N_TIMES = 'Prefer %<number>s.times.'
|
||||||
|
|
||||||
def_node_matcher :n_times_block_without_arg?, <<-PATTERN
|
def_node_matcher :n_times_block_without_arg?, <<-PATTERN
|
||||||
(block
|
(block
|
||||||
@ -44,7 +44,7 @@ module RuboCop
|
|||||||
class FilePath < Cop
|
class FilePath < Cop
|
||||||
include RuboCop::RSpec::TopLevelDescribe
|
include RuboCop::RSpec::TopLevelDescribe
|
||||||
|
|
||||||
MSG = 'Spec path should end with `%<suffix>s`.'.freeze
|
MSG = 'Spec path should end with `%<suffix>s`.'
|
||||||
|
|
||||||
def_node_search :const_described?, '(send _ :describe (const ...) ...)'
|
def_node_search :const_described?, '(send _ :describe (const ...) ...)'
|
||||||
def_node_search :routing_metadata?, '(pair (sym :type) (sym :routing))'
|
def_node_search :routing_metadata?, '(pair (sym :type) (sym :routing))'
|
||||||
@ -75,7 +75,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def name_glob(name)
|
def name_glob(name)
|
||||||
return unless name && name.str_type?
|
return unless name&.str_type?
|
||||||
|
|
||||||
"*#{name.str_content.gsub(/\W/, '')}" unless ignore_methods?
|
"*#{name.str_content.gsub(/\W/, '')}" unless ignore_methods?
|
||||||
end
|
end
|
||||||
@ -20,7 +20,7 @@ module RuboCop
|
|||||||
# describe MyClass do
|
# describe MyClass do
|
||||||
# end
|
# end
|
||||||
class Focus < Cop
|
class Focus < Cop
|
||||||
MSG = 'Focused spec found.'.freeze
|
MSG = 'Focused spec found.'
|
||||||
|
|
||||||
focusable =
|
focusable =
|
||||||
ExampleGroups::GROUPS +
|
ExampleGroups::GROUPS +
|
||||||
@ -36,8 +36,8 @@ module RuboCop
|
|||||||
FOCUS_TRUE = s(:pair, FOCUS_SYMBOL, s(:true))
|
FOCUS_TRUE = s(:pair, FOCUS_SYMBOL, s(:true))
|
||||||
|
|
||||||
def_node_matcher :metadata, <<-PATTERN
|
def_node_matcher :metadata, <<-PATTERN
|
||||||
{(send {(const nil? :RSpec) nil?} #{FOCUSABLE_SELECTORS} ... (hash $...))
|
{(send #{RSPEC} #{FOCUSABLE_SELECTORS} ... (hash $...))
|
||||||
(send {(const nil? :RSpec) nil?} #{FOCUSABLE_SELECTORS} $...)}
|
(send #{RSPEC} #{FOCUSABLE_SELECTORS} $...)}
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def_node_matcher :focused_block?, focused.send_pattern
|
def_node_matcher :focused_block?, focused.send_pattern
|
||||||
@ -59,11 +59,10 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
class HookArgument < Cop
|
class HookArgument < Cop
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
include RangeHelp
|
|
||||||
|
|
||||||
IMPLICIT_MSG = 'Omit the default `%<scope>p` ' \
|
IMPLICIT_MSG = 'Omit the default `%<scope>p` ' \
|
||||||
'argument for RSpec hooks.'.freeze
|
'argument for RSpec hooks.'
|
||||||
EXPLICIT_MSG = 'Use `%<scope>p` for RSpec hooks.'.freeze
|
EXPLICIT_MSG = 'Use `%<scope>p` for RSpec hooks.'
|
||||||
|
|
||||||
HOOKS = Hooks::ALL.node_pattern_union.freeze
|
HOOKS = Hooks::ALL.node_pattern_union.freeze
|
||||||
|
|
||||||
@ -125,9 +124,8 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def argument_range(send_node)
|
def argument_range(send_node)
|
||||||
range_between(
|
send_node.loc.selector.end.with(
|
||||||
send_node.loc.selector.end_pos,
|
end_pos: send_node.loc.expression.end_pos
|
||||||
send_node.loc.expression.end_pos
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -27,7 +27,7 @@ module RuboCop
|
|||||||
include RangeHelp
|
include RangeHelp
|
||||||
include RuboCop::RSpec::FinalEndLocation
|
include RuboCop::RSpec::FinalEndLocation
|
||||||
|
|
||||||
MSG = 'Move `%<hook>s` above the examples in the group.'.freeze
|
MSG = 'Move `%<hook>s` above the examples in the group.'
|
||||||
|
|
||||||
def_node_matcher :example_or_group?, <<-PATTERN
|
def_node_matcher :example_or_group?, <<-PATTERN
|
||||||
{
|
{
|
||||||
@ -88,10 +88,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def node_range(node)
|
def node_range(node)
|
||||||
range_between(
|
node.loc.expression.with(end_pos: final_end_location(node).end_pos)
|
||||||
node.loc.expression.begin_pos,
|
|
||||||
final_end_location(node).end_pos
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -27,12 +27,12 @@ module RuboCop
|
|||||||
class ImplicitExpect < Cop
|
class ImplicitExpect < Cop
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
MSG = 'Prefer `%<good>s` over `%<bad>s`.'.freeze
|
MSG = 'Prefer `%<good>s` over `%<bad>s`.'
|
||||||
|
|
||||||
def_node_matcher :implicit_expect, <<-PATTERN
|
def_node_matcher :implicit_expect, <<-PATTERN
|
||||||
{
|
{
|
||||||
(send nil? ${:should :should_not} ...)
|
(send nil? ${:should :should_not} ...)
|
||||||
(send (send nil? $:is_expected) {:to :to_not :not_to} ...)
|
(send (send nil? $:is_expected) #{Runners::ALL.node_pattern_union} ...)
|
||||||
}
|
}
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
@ -29,7 +29,7 @@ module RuboCop
|
|||||||
class ImplicitSubject < Cop
|
class ImplicitSubject < Cop
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
MSG = "Don't use implicit subject.".freeze
|
MSG = "Don't use implicit subject."
|
||||||
|
|
||||||
def_node_matcher :implicit_subject?, <<-PATTERN
|
def_node_matcher :implicit_subject?, <<-PATTERN
|
||||||
(send nil? {:should :should_not :is_expected} ...)
|
(send nil? {:should :should_not :is_expected} ...)
|
||||||
@ -20,7 +20,7 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
class InstanceSpy < Cop
|
class InstanceSpy < Cop
|
||||||
MSG = 'Use `instance_spy` when you check your double '\
|
MSG = 'Use `instance_spy` when you check your double '\
|
||||||
'with `have_received`.'.freeze
|
'with `have_received`.'
|
||||||
|
|
||||||
def_node_search :null_double, <<-PATTERN
|
def_node_search :null_double, <<-PATTERN
|
||||||
(lvasgn $_
|
(lvasgn $_
|
||||||
@ -47,7 +47,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
class InstanceVariable < Cop
|
class InstanceVariable < Cop
|
||||||
MSG = 'Replace instance variable with local variable or `let`.'.freeze
|
MSG = 'Replace instance variable with local variable or `let`.'
|
||||||
|
|
||||||
EXAMPLE_GROUP_METHODS = ExampleGroups::ALL + SharedGroups::ALL
|
EXAMPLE_GROUP_METHODS = ExampleGroups::ALL + SharedGroups::ALL
|
||||||
|
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -14,10 +16,10 @@ module RuboCop
|
|||||||
# # good
|
# # good
|
||||||
# expect(foo).to be_something
|
# expect(foo).to be_something
|
||||||
class InvalidPredicateMatcher < Cop
|
class InvalidPredicateMatcher < Cop
|
||||||
MSG = 'Omit `?` from `%<matcher>s`.'.freeze
|
MSG = 'Omit `?` from `%<matcher>s`.'
|
||||||
|
|
||||||
def_node_matcher :invalid_predicate_matcher?, <<-PATTERN
|
def_node_matcher :invalid_predicate_matcher?, <<-PATTERN
|
||||||
(send (send nil? :expect ...) {:to :not_to :to_not} $(send nil? #predicate?))
|
(send (send nil? :expect ...) #{Runners::ALL.node_pattern_union} $(send nil? #predicate?))
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
@ -22,7 +22,7 @@ module RuboCop
|
|||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
MSG = 'Prefer `%<replacement>s` over `%<original>s` when including '\
|
MSG = 'Prefer `%<replacement>s` over `%<original>s` when including '\
|
||||||
'examples in a nested context.'.freeze
|
'examples in a nested context.'
|
||||||
|
|
||||||
def_node_matcher :example_inclusion_offense, '(send _ % ...)'
|
def_node_matcher :example_inclusion_offense, '(send _ % ...)'
|
||||||
|
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -15,7 +17,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
class IteratedExpectation < Cop
|
class IteratedExpectation < Cop
|
||||||
MSG = 'Prefer using the `all` matcher instead ' \
|
MSG = 'Prefer using the `all` matcher instead ' \
|
||||||
'of iterating over an array.'.freeze
|
'of iterating over an array.'
|
||||||
|
|
||||||
def_node_matcher :each?, <<-PATTERN
|
def_node_matcher :each?, <<-PATTERN
|
||||||
(block
|
(block
|
||||||
@ -34,8 +34,7 @@ module RuboCop
|
|||||||
class LeadingSubject < Cop
|
class LeadingSubject < Cop
|
||||||
include RangeHelp
|
include RangeHelp
|
||||||
|
|
||||||
MSG = 'Declare `subject` above any other `%<offending>s` ' \
|
MSG = 'Declare `subject` above any other `%<offending>s` declarations.'
|
||||||
'declarations.'.freeze
|
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless subject?(node) && !in_spec_block?(node)
|
return unless subject?(node) && !in_spec_block?(node)
|
||||||
@ -34,7 +34,7 @@ module RuboCop
|
|||||||
include RangeHelp
|
include RangeHelp
|
||||||
include RuboCop::RSpec::FinalEndLocation
|
include RuboCop::RSpec::FinalEndLocation
|
||||||
|
|
||||||
MSG = 'Move `let` before the examples in the group.'.freeze
|
MSG = 'Move `let` before the examples in the group.'
|
||||||
|
|
||||||
def_node_matcher :example_or_group?, <<-PATTERN
|
def_node_matcher :example_or_group?, <<-PATTERN
|
||||||
{
|
{
|
||||||
@ -91,10 +91,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def node_range(node)
|
def node_range(node)
|
||||||
range_between(
|
node.loc.expression.with(end_pos: final_end_location(node).end_pos)
|
||||||
node.loc.expression.begin_pos,
|
|
||||||
final_end_location(node).end_pos
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -28,7 +28,7 @@ module RuboCop
|
|||||||
class LetSetup < Cop
|
class LetSetup < Cop
|
||||||
include RuboCop::RSpec::TopLevelDescribe
|
include RuboCop::RSpec::TopLevelDescribe
|
||||||
|
|
||||||
MSG = 'Do not use `let!` for test setup.'.freeze
|
MSG = 'Do not use `let!` for test setup.'
|
||||||
|
|
||||||
def_node_search :let_bang, <<-PATTERN
|
def_node_search :let_bang, <<-PATTERN
|
||||||
(block $(send nil? :let! (sym $_)) args ...)
|
(block $(send nil? :let! (sym $_)) args ...)
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -12,7 +14,7 @@ module RuboCop
|
|||||||
# allow(foo).to receive(bar: thing)
|
# allow(foo).to receive(bar: thing)
|
||||||
#
|
#
|
||||||
class MessageChain < Cop
|
class MessageChain < Cop
|
||||||
MSG = 'Avoid stubbing using `%<method>s`.'.freeze
|
MSG = 'Avoid stubbing using `%<method>s`.'
|
||||||
|
|
||||||
def_node_matcher :message_chain, <<-PATTERN
|
def_node_matcher :message_chain, <<-PATTERN
|
||||||
(send _ {:receive_message_chain :stub_chain} ...)
|
(send _ {:receive_message_chain :stub_chain} ...)
|
||||||
@ -27,7 +27,7 @@ module RuboCop
|
|||||||
class MessageExpectation < Cop
|
class MessageExpectation < Cop
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
MSG = 'Prefer `%<style>s` for setting message expectations.'.freeze
|
MSG = 'Prefer `%<style>s` for setting message expectations.'
|
||||||
|
|
||||||
SUPPORTED_STYLES = %w[allow expect].freeze
|
SUPPORTED_STYLES = %w[allow expect].freeze
|
||||||
|
|
||||||
@ -27,17 +27,16 @@ module RuboCop
|
|||||||
class MessageSpies < Cop
|
class MessageSpies < Cop
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
MSG_RECEIVE = 'Prefer `receive` for setting message '\
|
MSG_RECEIVE = 'Prefer `receive` for setting message expectations.'
|
||||||
'expectations.'.freeze
|
|
||||||
|
|
||||||
MSG_HAVE_RECEIVED = 'Prefer `have_received` for setting message '\
|
MSG_HAVE_RECEIVED = 'Prefer `have_received` for setting message '\
|
||||||
'expectations. Setup `%<source>s` as a spy using '\
|
'expectations. Setup `%<source>s` as a spy using '\
|
||||||
'`allow` or `instance_spy`.'.freeze
|
'`allow` or `instance_spy`.'
|
||||||
|
|
||||||
SUPPORTED_STYLES = %w[have_received receive].freeze
|
SUPPORTED_STYLES = %w[have_received receive].freeze
|
||||||
|
|
||||||
def_node_matcher :message_expectation, %(
|
def_node_matcher :message_expectation, %(
|
||||||
(send (send nil? :expect $_) {:to :to_not :not_to} ...)
|
(send (send nil? :expect $_) #{Runners::ALL.node_pattern_union} ...)
|
||||||
)
|
)
|
||||||
|
|
||||||
def_node_search :receive_message, %(
|
def_node_search :receive_message, %(
|
||||||
@ -20,7 +20,7 @@ module RuboCop
|
|||||||
# describe "A feature example" do
|
# describe "A feature example" do
|
||||||
# end
|
# end
|
||||||
class MissingExampleGroupArgument < Cop
|
class MissingExampleGroupArgument < Cop
|
||||||
MSG = 'The first argument to `%<method>s` should not be empty.'.freeze
|
MSG = 'The first argument to `%<method>s` should not be empty.'
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
@ -26,7 +26,7 @@ module RuboCop
|
|||||||
include RuboCop::RSpec::TopLevelDescribe
|
include RuboCop::RSpec::TopLevelDescribe
|
||||||
|
|
||||||
MSG = 'Do not use multiple top level describes - '\
|
MSG = 'Do not use multiple top level describes - '\
|
||||||
'try to nest them.'.freeze
|
'try to nest them.'
|
||||||
|
|
||||||
def on_top_level_describe(node, _args)
|
def on_top_level_describe(node, _args)
|
||||||
return if single_top_level_describe?
|
return if single_top_level_describe?
|
||||||
@ -48,7 +48,7 @@ module RuboCop
|
|||||||
class MultipleExpectations < Cop
|
class MultipleExpectations < Cop
|
||||||
include ConfigurableMax
|
include ConfigurableMax
|
||||||
|
|
||||||
MSG = 'Example has too many expectations [%<total>d/%<max>d].'.freeze
|
MSG = 'Example has too many expectations [%<total>d/%<max>d].'
|
||||||
|
|
||||||
def_node_search :with_aggregated_failures?, '(sym :aggregate_failures)'
|
def_node_search :with_aggregated_failures?, '(sym :aggregate_failures)'
|
||||||
def_node_search :disabled_aggregated_failures?, <<-PATTERN
|
def_node_search :disabled_aggregated_failures?, <<-PATTERN
|
||||||
@ -34,7 +34,9 @@ module RuboCop
|
|||||||
# This is enough of an edge case that people can just move this to
|
# This is enough of an edge case that people can just move this to
|
||||||
# a `before` hook on their own
|
# a `before` hook on their own
|
||||||
class MultipleSubjects < Cop
|
class MultipleSubjects < Cop
|
||||||
MSG = 'Do not set more than one subject per example group'.freeze
|
include RangeHelp
|
||||||
|
|
||||||
|
MSG = 'Do not set more than one subject per example group'
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
@ -70,7 +72,9 @@ module RuboCop
|
|||||||
|
|
||||||
def remove_autocorrect(node)
|
def remove_autocorrect(node)
|
||||||
lambda do |corrector|
|
lambda do |corrector|
|
||||||
corrector.remove(node.loc.expression)
|
range = range_by_whole_lines(node.source_range,
|
||||||
|
include_final_newline: true)
|
||||||
|
corrector.remove(range)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -43,7 +43,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
class NamedSubject < Cop
|
class NamedSubject < Cop
|
||||||
MSG = 'Name your test subject if you need '\
|
MSG = 'Name your test subject if you need '\
|
||||||
'to reference it explicitly.'.freeze
|
'to reference it explicitly.'
|
||||||
|
|
||||||
def_node_matcher :rspec_block?, <<-PATTERN
|
def_node_matcher :rspec_block?, <<-PATTERN
|
||||||
{
|
{
|
||||||
@ -89,14 +89,13 @@ module RuboCop
|
|||||||
include ConfigurableMax
|
include ConfigurableMax
|
||||||
include RuboCop::RSpec::TopLevelDescribe
|
include RuboCop::RSpec::TopLevelDescribe
|
||||||
|
|
||||||
MSG = 'Maximum example group nesting exceeded ' \
|
MSG = 'Maximum example group nesting exceeded [%<total>d/%<max>d].'
|
||||||
'[%<total>d/%<max>d].'.freeze
|
|
||||||
|
|
||||||
DEPRECATED_MAX_KEY = 'MaxNesting'.freeze
|
DEPRECATED_MAX_KEY = 'MaxNesting'
|
||||||
|
|
||||||
DEPRECATION_WARNING =
|
DEPRECATION_WARNING =
|
||||||
"Configuration key `#{DEPRECATED_MAX_KEY}` for #{cop_name} is " \
|
"Configuration key `#{DEPRECATED_MAX_KEY}` for #{cop_name} is " \
|
||||||
'deprecated in favor of `Max`. Please use that instead.'.freeze
|
'deprecated in favor of `Max`. Please use that instead.'
|
||||||
|
|
||||||
def_node_search :find_contexts, ExampleGroups::ALL.block_pattern
|
def_node_search :find_contexts, ExampleGroups::ALL.block_pattern
|
||||||
|
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -16,7 +18,7 @@ module RuboCop
|
|||||||
class NotToNot < Cop
|
class NotToNot < Cop
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
MSG = 'Prefer `%<replacement>s` over `%<original>s`.'.freeze
|
MSG = 'Prefer `%<replacement>s` over `%<original>s`.'
|
||||||
|
|
||||||
def_node_matcher :not_to_not_offense, '(send _ % ...)'
|
def_node_matcher :not_to_not_offense, '(send _ % ...)'
|
||||||
|
|
||||||
@ -22,7 +22,7 @@ module RuboCop
|
|||||||
# let(:baz) { baz }
|
# let(:baz) { baz }
|
||||||
# let!(:other) { other }
|
# let!(:other) { other }
|
||||||
class OverwritingSetup < Cop
|
class OverwritingSetup < Cop
|
||||||
MSG = '`%<name>s` is already defined.'.freeze
|
MSG = '`%<name>s` is already defined.'
|
||||||
|
|
||||||
def_node_matcher :setup?, (Helpers::ALL + Subject::ALL).block_pattern
|
def_node_matcher :setup?, (Helpers::ALL + Subject::ALL).block_pattern
|
||||||
def_node_matcher :first_argument_name, '(send _ _ ({str sym} $_))'
|
def_node_matcher :first_argument_name, '(send _ _ ({str sym} $_))'
|
||||||
@ -26,7 +26,7 @@ module RuboCop
|
|||||||
# describe MyClass do
|
# describe MyClass do
|
||||||
# end
|
# end
|
||||||
class Pending < Cop
|
class Pending < Cop
|
||||||
MSG = 'Pending spec found.'.freeze
|
MSG = 'Pending spec found.'
|
||||||
|
|
||||||
PENDING_EXAMPLES = Examples::PENDING + Examples::SKIPPED \
|
PENDING_EXAMPLES = Examples::PENDING + Examples::SKIPPED \
|
||||||
+ ExampleGroups::SKIPPED
|
+ ExampleGroups::SKIPPED
|
||||||
@ -37,8 +37,8 @@ module RuboCop
|
|||||||
PENDING_SYMBOL = s(:sym, :pending)
|
PENDING_SYMBOL = s(:sym, :pending)
|
||||||
|
|
||||||
def_node_matcher :metadata, <<-PATTERN
|
def_node_matcher :metadata, <<-PATTERN
|
||||||
{(send {(const nil? :RSpec) nil?} #{SKIPPABLE_SELECTORS} ... (hash $...))
|
{(send #{RSPEC} #{SKIPPABLE_SELECTORS} ... (hash $...))
|
||||||
(send {(const nil? :RSpec) nil?} #{SKIPPABLE_SELECTORS} $...)}
|
(send #{RSPEC} #{SKIPPABLE_SELECTORS} $...)}
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
def_node_matcher :pending_block?, PENDING_EXAMPLES.send_pattern
|
def_node_matcher :pending_block?, PENDING_EXAMPLES.send_pattern
|
||||||
@ -1,12 +1,15 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
# A helper for `inflected` style
|
# A helper for `inflected` style
|
||||||
module InflectedHelper
|
module InflectedHelper
|
||||||
|
include RuboCop::RSpec::Language
|
||||||
extend NodePattern::Macros
|
extend NodePattern::Macros
|
||||||
|
|
||||||
MSG_INFLECTED = 'Prefer using `%<matcher_name>s` matcher over ' \
|
MSG_INFLECTED = 'Prefer using `%<matcher_name>s` matcher over ' \
|
||||||
'`%<predicate_name>s`.'.freeze
|
'`%<predicate_name>s`.'
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
@ -25,7 +28,7 @@ module RuboCop
|
|||||||
(send nil? :expect {
|
(send nil? :expect {
|
||||||
(block $(send !nil? #predicate? ...) ...)
|
(block $(send !nil? #predicate? ...) ...)
|
||||||
$(send !nil? #predicate? ...)})
|
$(send !nil? #predicate? ...)})
|
||||||
${:to :not_to :to_not}
|
$#{Runners::ALL.node_pattern_union}
|
||||||
$#boolean_matcher?)
|
$#boolean_matcher?)
|
||||||
PATTERN
|
PATTERN
|
||||||
|
|
||||||
@ -86,10 +89,10 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def remove_predicate(corrector, predicate)
|
def remove_predicate(corrector, predicate)
|
||||||
range = range_between(
|
range = predicate.loc.dot.with(
|
||||||
predicate.loc.dot.begin_pos,
|
end_pos: predicate.loc.expression.end_pos
|
||||||
predicate.loc.expression.end_pos
|
|
||||||
)
|
)
|
||||||
|
|
||||||
corrector.remove(range)
|
corrector.remove(range)
|
||||||
|
|
||||||
block_range = block_loc(predicate)
|
block_range = block_loc(predicate)
|
||||||
@ -123,10 +126,11 @@ module RuboCop
|
|||||||
# A helper for `explicit` style
|
# A helper for `explicit` style
|
||||||
# rubocop:disable Metrics/ModuleLength
|
# rubocop:disable Metrics/ModuleLength
|
||||||
module ExplicitHelper
|
module ExplicitHelper
|
||||||
|
include RuboCop::RSpec::Language
|
||||||
extend NodePattern::Macros
|
extend NodePattern::Macros
|
||||||
|
|
||||||
MSG_EXPLICIT = 'Prefer using `%<predicate_name>s` over ' \
|
MSG_EXPLICIT = 'Prefer using `%<predicate_name>s` over ' \
|
||||||
'`%<matcher_name>s` matcher.'.freeze
|
'`%<matcher_name>s` matcher.'
|
||||||
BUILT_IN_MATCHERS = %w[
|
BUILT_IN_MATCHERS = %w[
|
||||||
be_truthy be_falsey be_falsy
|
be_truthy be_falsey be_falsy
|
||||||
have_attributes have_received
|
have_attributes have_received
|
||||||
@ -160,7 +164,7 @@ module RuboCop
|
|||||||
def_node_matcher :predicate_matcher?, <<-PATTERN
|
def_node_matcher :predicate_matcher?, <<-PATTERN
|
||||||
(send
|
(send
|
||||||
(send nil? :expect $!nil?)
|
(send nil? :expect $!nil?)
|
||||||
{:to :not_to :to_not}
|
#{Runners::ALL.node_pattern_union}
|
||||||
{$(send nil? #predicate_matcher_name? ...)
|
{$(send nil? #predicate_matcher_name? ...)
|
||||||
(block $(send nil? #predicate_matcher_name? ...) ...)})
|
(block $(send nil? #predicate_matcher_name? ...) ...)})
|
||||||
PATTERN
|
PATTERN
|
||||||
@ -169,7 +173,7 @@ module RuboCop
|
|||||||
(block
|
(block
|
||||||
(send
|
(send
|
||||||
(send nil? :expect $!nil?)
|
(send nil? :expect $!nil?)
|
||||||
{:to :not_to :to_not}
|
#{Runners::ALL.node_pattern_union}
|
||||||
$(send nil? #predicate_matcher_name?))
|
$(send nil? #predicate_matcher_name?))
|
||||||
...)
|
...)
|
||||||
PATTERN
|
PATTERN
|
||||||
@ -299,7 +303,6 @@ module RuboCop
|
|||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
include InflectedHelper
|
include InflectedHelper
|
||||||
include ExplicitHelper
|
include ExplicitHelper
|
||||||
include RangeHelp
|
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
case style
|
case style
|
||||||
@ -330,8 +333,9 @@ module RuboCop
|
|||||||
# foo 1, 2
|
# foo 1, 2
|
||||||
# ^^^^^
|
# ^^^^^
|
||||||
def args_loc(send_node)
|
def args_loc(send_node)
|
||||||
range_between(send_node.loc.selector.end_pos,
|
send_node.loc.selector.end.with(
|
||||||
send_node.loc.expression.end_pos)
|
end_pos: send_node.loc.expression.end_pos
|
||||||
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
# returns block location with whitespace
|
# returns block location with whitespace
|
||||||
@ -342,9 +346,8 @@ module RuboCop
|
|||||||
parent = send_node.parent
|
parent = send_node.parent
|
||||||
return unless parent.block_type?
|
return unless parent.block_type?
|
||||||
|
|
||||||
range_between(
|
send_node.loc.expression.end.with(
|
||||||
send_node.loc.expression.end_pos,
|
end_pos: parent.loc.expression.end_pos
|
||||||
parent.loc.expression.end_pos
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -67,7 +67,7 @@ module RuboCop
|
|||||||
# :nodoc:
|
# :nodoc:
|
||||||
class SymbolicStyleChecker
|
class SymbolicStyleChecker
|
||||||
MSG = 'Prefer `%<prefer>s` over `%<current>s` ' \
|
MSG = 'Prefer `%<prefer>s` over `%<current>s` ' \
|
||||||
'to describe HTTP status code.'.freeze
|
'to describe HTTP status code.'
|
||||||
|
|
||||||
attr_reader :node
|
attr_reader :node
|
||||||
def initialize(node)
|
def initialize(node)
|
||||||
@ -105,7 +105,7 @@ module RuboCop
|
|||||||
# :nodoc:
|
# :nodoc:
|
||||||
class NumericStyleChecker
|
class NumericStyleChecker
|
||||||
MSG = 'Prefer `%<prefer>s` over `%<current>s` ' \
|
MSG = 'Prefer `%<prefer>s` over `%<current>s` ' \
|
||||||
'to describe HTTP status code.'.freeze
|
'to describe HTTP status code.'
|
||||||
|
|
||||||
WHITELIST_STATUS = %i[error success missing redirect].freeze
|
WHITELIST_STATUS = %i[error success missing redirect].freeze
|
||||||
|
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -22,9 +24,7 @@ module RuboCop
|
|||||||
# expect(foo).to receive(:bar).at_most(:twice).times
|
# expect(foo).to receive(:bar).at_most(:twice).times
|
||||||
#
|
#
|
||||||
class ReceiveCounts < Cop
|
class ReceiveCounts < Cop
|
||||||
include RangeHelp
|
MSG = 'Use `%<alternative>s` instead of `%<original>s`.'
|
||||||
|
|
||||||
MSG = 'Use `%<alternative>s` instead of `%<original>s`.'.freeze
|
|
||||||
|
|
||||||
def_node_matcher :receive_counts, <<-PATTERN
|
def_node_matcher :receive_counts, <<-PATTERN
|
||||||
(send $(send _ {:exactly :at_least :at_most} (int {1 2})) :times)
|
(send $(send _ {:exactly :at_least :at_most} (int {1 2})) :times)
|
||||||
@ -78,9 +78,8 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def range(node, offending_node)
|
def range(node, offending_node)
|
||||||
range_between(
|
offending_node.loc.dot.with(
|
||||||
offending_node.loc.dot.begin_pos,
|
end_pos: node.loc.expression.end_pos
|
||||||
node.loc.expression.end_pos
|
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -12,9 +14,7 @@ module RuboCop
|
|||||||
# expect(foo).not_to receive(:bar)
|
# expect(foo).not_to receive(:bar)
|
||||||
#
|
#
|
||||||
class ReceiveNever < Cop
|
class ReceiveNever < Cop
|
||||||
include RangeHelp
|
MSG = 'Use `not_to receive` instead of `never`.'
|
||||||
|
|
||||||
MSG = 'Use `not_to receive` instead of `never`.'.freeze
|
|
||||||
|
|
||||||
def_node_search :method_on_stub?, '(send nil? :receive ...)'
|
def_node_search :method_on_stub?, '(send nil? :receive ...)'
|
||||||
|
|
||||||
@ -30,10 +30,7 @@ module RuboCop
|
|||||||
def autocorrect(node)
|
def autocorrect(node)
|
||||||
lambda do |corrector|
|
lambda do |corrector|
|
||||||
corrector.replace(node.parent.loc.selector, 'not_to')
|
corrector.replace(node.parent.loc.selector, 'not_to')
|
||||||
range = range_between(
|
range = node.loc.dot.with(end_pos: node.loc.selector.end_pos)
|
||||||
node.loc.dot.begin_pos,
|
|
||||||
node.loc.selector.end_pos
|
|
||||||
)
|
|
||||||
corrector.remove(range)
|
corrector.remove(range)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -28,7 +30,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
class RepeatedDescription < Cop
|
class RepeatedDescription < Cop
|
||||||
MSG = "Don't repeat descriptions within an example group.".freeze
|
MSG = "Don't repeat descriptions within an example group."
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -14,7 +16,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
class RepeatedExample < Cop
|
class RepeatedExample < Cop
|
||||||
MSG = "Don't repeat examples within an example group.".freeze
|
MSG = "Don't repeat examples within an example group."
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
@ -36,8 +36,8 @@ module RuboCop
|
|||||||
class ReturnFromStub < Cop
|
class ReturnFromStub < Cop
|
||||||
include ConfigurableEnforcedStyle
|
include ConfigurableEnforcedStyle
|
||||||
|
|
||||||
MSG_AND_RETURN = 'Use `and_return` for static values.'.freeze
|
MSG_AND_RETURN = 'Use `and_return` for static values.'
|
||||||
MSG_BLOCK = 'Use block for static values.'.freeze
|
MSG_BLOCK = 'Use block for static values.'
|
||||||
|
|
||||||
def_node_search :contains_stub?, '(send nil? :receive (...))'
|
def_node_search :contains_stub?, '(send nil? :receive (...))'
|
||||||
def_node_search :and_return_value, <<-PATTERN
|
def_node_search :and_return_value, <<-PATTERN
|
||||||
@ -27,7 +27,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
class ScatteredLet < Cop
|
class ScatteredLet < Cop
|
||||||
MSG = 'Group all let/let! blocks in the example group together.'.freeze
|
MSG = 'Group all let/let! blocks in the example group together.'
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example_group_with_body?(node)
|
return unless example_group_with_body?(node)
|
||||||
@ -23,7 +23,7 @@ module RuboCop
|
|||||||
# end
|
# end
|
||||||
#
|
#
|
||||||
class ScatteredSetup < Cop
|
class ScatteredSetup < Cop
|
||||||
MSG = 'Do not define multiple hooks in the same example group.'.freeze
|
MSG = 'Do not define multiple hooks in the same example group.'
|
||||||
|
|
||||||
def on_block(node)
|
def on_block(node)
|
||||||
return unless example_group?(node)
|
return unless example_group?(node)
|
||||||
@ -52,10 +52,10 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
class SharedContext < Cop
|
class SharedContext < Cop
|
||||||
MSG_EXAMPLES = "Use `shared_examples` when you don't "\
|
MSG_EXAMPLES = "Use `shared_examples` when you don't "\
|
||||||
'define context.'.freeze
|
'define context.'
|
||||||
|
|
||||||
MSG_CONTEXT = "Use `shared_context` when you don't "\
|
MSG_CONTEXT = "Use `shared_context` when you don't "\
|
||||||
'define examples.'.freeze
|
'define examples.'
|
||||||
|
|
||||||
examples = (Examples::ALL + Includes::EXAMPLES)
|
examples = (Examples::ALL + Includes::EXAMPLES)
|
||||||
def_node_search :examples?, examples.send_pattern
|
def_node_search :examples?, examples.send_pattern
|
||||||
@ -21,14 +21,14 @@ module RuboCop
|
|||||||
# include_examples 'foo bar baz'
|
# include_examples 'foo bar baz'
|
||||||
#
|
#
|
||||||
class SharedExamples < Cop
|
class SharedExamples < Cop
|
||||||
def_node_matcher :shared_examples, <<-PATTERN
|
def_node_matcher :shared_examples,
|
||||||
(send
|
(SharedGroups::ALL + Includes::ALL).send_pattern
|
||||||
{(const nil? :RSpec) nil?}
|
|
||||||
{#{(SharedGroups::ALL + Includes::ALL).node_pattern}} $sym ...)
|
|
||||||
PATTERN
|
|
||||||
|
|
||||||
def on_send(node)
|
def on_send(node)
|
||||||
shared_examples(node) do |ast_node|
|
shared_examples(node) do
|
||||||
|
ast_node = node.first_argument
|
||||||
|
next unless ast_node&.sym_type?
|
||||||
|
|
||||||
checker = Checker.new(ast_node)
|
checker = Checker.new(ast_node)
|
||||||
add_offense(checker.node, message: checker.message)
|
add_offense(checker.node, message: checker.message)
|
||||||
end
|
end
|
||||||
@ -44,7 +44,7 @@ module RuboCop
|
|||||||
# :nodoc:
|
# :nodoc:
|
||||||
class Checker
|
class Checker
|
||||||
MSG = 'Prefer %<prefer>s over `%<current>s` ' \
|
MSG = 'Prefer %<prefer>s over `%<current>s` ' \
|
||||||
'to titleize shared examples.'.freeze
|
'to titleize shared examples.'
|
||||||
|
|
||||||
attr_reader :node
|
attr_reader :node
|
||||||
def initialize(node)
|
def initialize(node)
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -16,7 +18,7 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
class SingleArgumentMessageChain < Cop
|
class SingleArgumentMessageChain < Cop
|
||||||
MSG = 'Use `%<recommended>s` instead of calling '\
|
MSG = 'Use `%<recommended>s` instead of calling '\
|
||||||
'`%<called>s` with a single argument.'.freeze
|
'`%<called>s` with a single argument.'
|
||||||
|
|
||||||
def_node_matcher :message_chain, <<-PATTERN
|
def_node_matcher :message_chain, <<-PATTERN
|
||||||
(send _ {:receive_message_chain :stub_chain} $_)
|
(send _ {:receive_message_chain :stub_chain} $_)
|
||||||
@ -20,7 +20,7 @@ module RuboCop
|
|||||||
class SubjectStub < Cop
|
class SubjectStub < Cop
|
||||||
include RuboCop::RSpec::TopLevelDescribe
|
include RuboCop::RSpec::TopLevelDescribe
|
||||||
|
|
||||||
MSG = 'Do not stub your test subject.'.freeze
|
MSG = 'Do not stub your test subject.'
|
||||||
|
|
||||||
# @!method subject(node)
|
# @!method subject(node)
|
||||||
# Find a named or unnamed subject definition
|
# Find a named or unnamed subject definition
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module Cop
|
module Cop
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -29,9 +31,9 @@ module RuboCop
|
|||||||
#
|
#
|
||||||
# expect { do_something }.not_to raise_error
|
# expect { do_something }.not_to raise_error
|
||||||
class UnspecifiedException < Cop
|
class UnspecifiedException < Cop
|
||||||
MSG = 'Specify the exception being captured'.freeze
|
MSG = 'Specify the exception being captured'
|
||||||
|
|
||||||
def_node_matcher :empty_raise_error_or_exception, <<-PATTERN.freeze
|
def_node_matcher :empty_raise_error_or_exception, <<-PATTERN
|
||||||
(send
|
(send
|
||||||
(block
|
(block
|
||||||
(send nil? :expect) ...)
|
(send nil? :expect) ...)
|
||||||
@ -54,7 +56,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def block_with_args?(node)
|
def block_with_args?(node)
|
||||||
return unless node && node.block_type?
|
return unless node&.block_type?
|
||||||
|
|
||||||
node.arguments?
|
node.arguments?
|
||||||
end
|
end
|
||||||
@ -23,7 +23,7 @@ module RuboCop
|
|||||||
# instance_double("ClassName", method_name: 'returned value')
|
# instance_double("ClassName", method_name: 'returned value')
|
||||||
# end
|
# end
|
||||||
class VerifiedDoubles < Cop
|
class VerifiedDoubles < Cop
|
||||||
MSG = 'Prefer using verifying doubles over normal doubles.'.freeze
|
MSG = 'Prefer using verifying doubles over normal doubles.'
|
||||||
|
|
||||||
def_node_matcher :unverified_double, <<-PATTERN
|
def_node_matcher :unverified_double, <<-PATTERN
|
||||||
{(send nil? {:double :spy} $...)}
|
{(send nil? {:double :spy} $...)}
|
||||||
@ -41,7 +41,7 @@ module RuboCop
|
|||||||
private
|
private
|
||||||
|
|
||||||
def symbol?(name)
|
def symbol?(name)
|
||||||
name && name.sym_type?
|
name&.sym_type?
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -13,7 +13,7 @@ module RuboCop
|
|||||||
# expect(something).to be(1)
|
# expect(something).to be(1)
|
||||||
class VoidExpect < Cop
|
class VoidExpect < Cop
|
||||||
MSG = 'Do not use `expect()` without `.to` or `.not_to`. ' \
|
MSG = 'Do not use `expect()` without `.to` or `.not_to`. ' \
|
||||||
'Chain the methods or remove it.'.freeze
|
'Chain the methods or remove it.'
|
||||||
|
|
||||||
def_node_matcher :expect?, <<-PATTERN
|
def_node_matcher :expect?, <<-PATTERN
|
||||||
(send nil? :expect ...)
|
(send nil? :expect ...)
|
||||||
@ -14,7 +14,7 @@ module RuboCop
|
|||||||
class Yield < Cop
|
class Yield < Cop
|
||||||
include RangeHelp
|
include RangeHelp
|
||||||
|
|
||||||
MSG = 'Use `.and_yield`.'.freeze
|
MSG = 'Use `.and_yield`.'
|
||||||
|
|
||||||
def_node_search :method_on_stub?, '(send nil? :receive ...)'
|
def_node_search :method_on_stub?, '(send nil? :receive ...)'
|
||||||
|
|
||||||
@ -52,9 +52,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def block_range(node)
|
def block_range(node)
|
||||||
block_start = node.loc.begin.begin_pos
|
node.loc.begin.with(end_pos: node.loc.end.end_pos)
|
||||||
block_end = node.loc.end.end_pos
|
|
||||||
range_between(block_start, block_end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def generate_replacement(node)
|
def generate_replacement(node)
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require_relative 'rspec/capybara/current_path_expectation'
|
require_relative 'rspec/capybara/current_path_expectation'
|
||||||
require_relative 'rspec/capybara/feature_methods'
|
require_relative 'rspec/capybara/feature_methods'
|
||||||
|
|
||||||
@ -22,6 +24,7 @@ require_relative 'rspec/describe_class'
|
|||||||
require_relative 'rspec/describe_method'
|
require_relative 'rspec/describe_method'
|
||||||
require_relative 'rspec/describe_symbol'
|
require_relative 'rspec/describe_symbol'
|
||||||
require_relative 'rspec/described_class'
|
require_relative 'rspec/described_class'
|
||||||
|
require_relative 'rspec/dialect'
|
||||||
require_relative 'rspec/empty_example_group'
|
require_relative 'rspec/empty_example_group'
|
||||||
require_relative 'rspec/empty_line_after_example_group'
|
require_relative 'rspec/empty_line_after_example_group'
|
||||||
require_relative 'rspec/empty_line_after_final_let'
|
require_relative 'rspec/empty_line_after_final_let'
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
# RuboCop RSpec project namespace
|
# RuboCop RSpec project namespace
|
||||||
module RSpec
|
module RSpec
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module RSpec
|
module RSpec
|
||||||
# Helps determine the offending location if there is not a blank line
|
# Helps determine the offending location if there is not a blank line
|
||||||
@ -26,7 +28,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def last_child?(node)
|
def last_child?(node)
|
||||||
return true unless node.parent && node.parent.begin_type?
|
return true unless node.parent&.begin_type?
|
||||||
|
|
||||||
node.equal?(node.parent.children.last)
|
node.equal?(node.parent.children.last)
|
||||||
end
|
end
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
@ -5,7 +7,7 @@ module RuboCop
|
|||||||
# Builds a YAML config file from two config hashes
|
# Builds a YAML config file from two config hashes
|
||||||
class ConfigFormatter
|
class ConfigFormatter
|
||||||
NAMESPACES = /^(RSpec|Capybara|FactoryBot|Rails)/.freeze
|
NAMESPACES = /^(RSpec|Capybara|FactoryBot|Rails)/.freeze
|
||||||
STYLE_GUIDE_BASE_URL = 'http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'.freeze
|
STYLE_GUIDE_BASE_URL = 'http://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/'
|
||||||
|
|
||||||
def initialize(config, descriptions)
|
def initialize(config, descriptions)
|
||||||
@config = config
|
@config = config
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module RSpec
|
module RSpec
|
||||||
# Extracts cop descriptions from YARD docstrings
|
# Extracts cop descriptions from YARD docstrings
|
||||||
@ -20,7 +22,7 @@ module RuboCop
|
|||||||
# Decorator of a YARD code object for working with documented rspec cops
|
# Decorator of a YARD code object for working with documented rspec cops
|
||||||
class CodeObject
|
class CodeObject
|
||||||
COP_CLASS_NAMES = %w[RuboCop::Cop RuboCop::Cop::RSpec::Cop].freeze
|
COP_CLASS_NAMES = %w[RuboCop::Cop RuboCop::Cop::RSpec::Cop].freeze
|
||||||
RSPEC_NAMESPACE = 'RuboCop::Cop::RSpec'.freeze
|
RSPEC_NAMESPACE = 'RuboCop::Cop::RSpec'
|
||||||
|
|
||||||
def initialize(yardoc)
|
def initialize(yardoc)
|
||||||
@yardoc = yardoc
|
@yardoc = yardoc
|
||||||
@ -0,0 +1,58 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
module RuboCop
|
||||||
|
module RSpec
|
||||||
|
# RuboCop FactoryBot project namespace
|
||||||
|
module FactoryBot
|
||||||
|
ATTRIBUTE_DEFINING_METHODS = %i[factory trait transient ignore].freeze
|
||||||
|
|
||||||
|
UNPROXIED_METHODS = %i[
|
||||||
|
__send__
|
||||||
|
__id__
|
||||||
|
nil?
|
||||||
|
send
|
||||||
|
object_id
|
||||||
|
extend
|
||||||
|
instance_eval
|
||||||
|
initialize
|
||||||
|
block_given?
|
||||||
|
raise
|
||||||
|
caller
|
||||||
|
method
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
DEFINITION_PROXY_METHODS = %i[
|
||||||
|
add_attribute
|
||||||
|
after
|
||||||
|
association
|
||||||
|
before
|
||||||
|
callback
|
||||||
|
ignore
|
||||||
|
initialize_with
|
||||||
|
sequence
|
||||||
|
skip_create
|
||||||
|
to_create
|
||||||
|
].freeze
|
||||||
|
|
||||||
|
RESERVED_METHODS =
|
||||||
|
DEFINITION_PROXY_METHODS +
|
||||||
|
UNPROXIED_METHODS +
|
||||||
|
ATTRIBUTE_DEFINING_METHODS
|
||||||
|
|
||||||
|
private_constant(
|
||||||
|
:ATTRIBUTE_DEFINING_METHODS,
|
||||||
|
:UNPROXIED_METHODS,
|
||||||
|
:DEFINITION_PROXY_METHODS,
|
||||||
|
:RESERVED_METHODS
|
||||||
|
)
|
||||||
|
|
||||||
|
def self.attribute_defining_methods
|
||||||
|
ATTRIBUTE_DEFINING_METHODS
|
||||||
|
end
|
||||||
|
|
||||||
|
def self.reserved_methods
|
||||||
|
RESERVED_METHODS
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module RSpec
|
module RSpec
|
||||||
# Helps find the true end location of nodes which might contain heredocs.
|
# Helps find the true end location of nodes which might contain heredocs.
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module RSpec
|
module RSpec
|
||||||
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
# Because RuboCop doesn't yet support plugins, we have to monkey patch in a
|
||||||
@ -4,6 +4,8 @@ module RuboCop
|
|||||||
module RSpec
|
module RSpec
|
||||||
# RSpec public API methods that are commonly used in cops
|
# RSpec public API methods that are commonly used in cops
|
||||||
module Language
|
module Language
|
||||||
|
RSPEC = '{(const nil? :RSpec) nil?}'
|
||||||
|
|
||||||
# Set of method selectors
|
# Set of method selectors
|
||||||
class SelectorSet
|
class SelectorSet
|
||||||
def initialize(selectors)
|
def initialize(selectors)
|
||||||
@ -27,7 +29,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def send_pattern
|
def send_pattern
|
||||||
"(send {(const nil? :RSpec) nil?} #{node_pattern_union} ...)"
|
"(send #{RSPEC} #{node_pattern_union} ...)"
|
||||||
end
|
end
|
||||||
|
|
||||||
def node_pattern_union
|
def node_pattern_union
|
||||||
@ -106,6 +108,10 @@ module RuboCop
|
|||||||
ALL = SelectorSet.new(%i[expect is_expected expect_any_instance_of])
|
ALL = SelectorSet.new(%i[expect is_expected expect_any_instance_of])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
module Runners
|
||||||
|
ALL = SelectorSet.new(%i[to to_not not_to])
|
||||||
|
end
|
||||||
|
|
||||||
ALL =
|
ALL =
|
||||||
ExampleGroups::ALL +
|
ExampleGroups::ALL +
|
||||||
SharedGroups::ALL +
|
SharedGroups::ALL +
|
||||||
@ -113,7 +119,8 @@ module RuboCop
|
|||||||
Hooks::ALL +
|
Hooks::ALL +
|
||||||
Helpers::ALL +
|
Helpers::ALL +
|
||||||
Subject::ALL +
|
Subject::ALL +
|
||||||
Expectations::ALL
|
Expectations::ALL +
|
||||||
|
Runners::ALL
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -1,3 +1,5 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
module RuboCop
|
module RuboCop
|
||||||
module RSpec
|
module RSpec
|
||||||
# Helper methods for top level describe cops
|
# Helper methods for top level describe cops
|
||||||
@ -4,7 +4,7 @@ module RuboCop
|
|||||||
module RSpec
|
module RSpec
|
||||||
# Version information for the RSpec RuboCop plugin.
|
# Version information for the RSpec RuboCop plugin.
|
||||||
module Version
|
module Version
|
||||||
STRING = '1.32.0'.freeze
|
STRING = '1.33.0'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Loading…
x
Reference in New Issue
Block a user