Merge pull request #10051 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-rspec-2.1.0

build(deps): bump rubocop-rspec from 2.0.1 to 2.1.0 in /Library/Homebrew
This commit is contained in:
Markus Reiter 2020-12-18 20:36:31 +01:00 committed by GitHub
commit 18e414683d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
112 changed files with 65 additions and 23 deletions

View File

@ -120,7 +120,7 @@ GEM
activesupport (>= 4.2.0) activesupport (>= 4.2.0)
rack (>= 1.1) rack (>= 1.1)
rubocop (>= 0.90.0, < 2.0) rubocop (>= 0.90.0, < 2.0)
rubocop-rspec (2.0.1) rubocop-rspec (2.1.0)
rubocop (~> 1.0) rubocop (~> 1.0)
rubocop-ast (>= 1.1.0) rubocop-ast (>= 1.1.0)
rubocop-sorbet (0.5.1) rubocop-sorbet (0.5.1)

View File

@ -652,11 +652,11 @@ class RuboCop::Cop::RSpec::FilePath < ::RuboCop::Cop::RSpec::Base
def custom_transform; end def custom_transform; end
def ensure_correct_file_path(send_node, described_class, arguments); end def ensure_correct_file_path(send_node, described_class, arguments); end
def expected_path(constant); end def expected_path(constant); end
def filename_ends_with?(glob); end def filename_ends_with?(pattern); end
def glob_for(described_class, method_name); end
def glob_for_spec_suffix_only?; end
def ignore_methods?; end def ignore_methods?; end
def name_glob(method_name); end def name_pattern(method_name); end
def pattern_for(described_class, method_name); end
def pattern_for_spec_suffix_only?; end
def relevant_rubocop_rspec_file?(_file); end def relevant_rubocop_rspec_file?(_file); end
def routing_spec?(args); end def routing_spec?(args); end
def spec_suffix_only?; end def spec_suffix_only?; end
@ -669,6 +669,9 @@ module RuboCop::Cop::RSpec::FinalEndLocation
end end
class RuboCop::Cop::RSpec::Focus < ::RuboCop::Cop::RSpec::Base class RuboCop::Cop::RSpec::Focus < ::RuboCop::Cop::RSpec::Base
include(::RuboCop::Cop::RangeHelp)
extend(::RuboCop::Cop::AutoCorrector)
def focusable_selector?(param0 = T.unsafe(nil)); end def focusable_selector?(param0 = T.unsafe(nil)); end
def focused_block?(param0 = T.unsafe(nil)); end def focused_block?(param0 = T.unsafe(nil)); end
def metadata(param0 = T.unsafe(nil)); end def metadata(param0 = T.unsafe(nil)); end
@ -676,7 +679,9 @@ class RuboCop::Cop::RSpec::Focus < ::RuboCop::Cop::RSpec::Base
private private
def correct_send(corrector, focus); end
def focus_metadata(node, &block); end def focus_metadata(node, &block); end
def with_surrounding(focus); end
end end
RuboCop::Cop::RSpec::Focus::MSG = T.let(T.unsafe(nil), String) RuboCop::Cop::RSpec::Focus::MSG = T.let(T.unsafe(nil), String)

View File

@ -79,7 +79,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.5.1/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.5.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.9.1/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.9.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.9.1/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.9.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.0.1/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.1.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.5.1/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.5.1/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.5.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-macho-2.5.0/lib"
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/sorbet-runtime-stub-0.2.0/lib" $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/sorbet-runtime-stub-0.2.0/lib"

View File

@ -328,6 +328,7 @@ RSpec/Focus:
Description: Checks if examples are focused. Description: Checks if examples are focused.
Enabled: true Enabled: true
VersionAdded: '1.5' VersionAdded: '1.5'
VersionChanged: '2.1'
StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Focus StyleGuide: https://www.rubydoc.info/gems/rubocop-rspec/RuboCop/Cop/RSpec/Focus
RSpec/HookArgument: RSpec/HookArgument:

View File

@ -82,30 +82,39 @@ module RuboCop
private private
def ensure_correct_file_path(send_node, described_class, arguments) def ensure_correct_file_path(send_node, described_class, arguments)
glob = glob_for(described_class, arguments.first) pattern = pattern_for(described_class, arguments.first)
return if filename_ends_with?(glob) return if filename_ends_with?(pattern)
add_offense(send_node, message: format(MSG, suffix: glob)) # For the suffix shown in the offense message, modify the regular
# expression pattern to resemble a glob pattern for clearer error
# messages.
offense_suffix = pattern.gsub('.*', '*').sub('[^/]', '')
.sub('\.', '.')
add_offense(send_node, message: format(MSG, suffix: offense_suffix))
end end
def routing_spec?(args) def routing_spec?(args)
args.any?(&method(:routing_metadata?)) args.any?(&method(:routing_metadata?))
end end
def glob_for(described_class, method_name) def pattern_for(described_class, method_name)
return glob_for_spec_suffix_only? if spec_suffix_only? return pattern_for_spec_suffix_only? if spec_suffix_only?
"#{expected_path(described_class)}#{name_glob(method_name)}*_spec.rb" [
expected_path(described_class),
name_pattern(method_name),
'[^/]*_spec\.rb'
].join
end end
def glob_for_spec_suffix_only? def pattern_for_spec_suffix_only?
'*_spec.rb' '.*_spec\.rb'
end end
def name_glob(method_name) def name_pattern(method_name)
return unless method_name&.str_type? return unless method_name&.str_type?
"*#{method_name.str_content.gsub(/\W/, '')}" unless ignore_methods? ".*#{method_name.str_content.gsub(/\W/, '')}" unless ignore_methods?
end end
def expected_path(constant) def expected_path(constant)
@ -131,11 +140,9 @@ module RuboCop
cop_config['IgnoreMethods'] cop_config['IgnoreMethods']
end end
def filename_ends_with?(glob) def filename_ends_with?(pattern)
filename = filename = File.expand_path(processed_source.buffer.name)
RuboCop::PathUtil.relative_path(processed_source.buffer.name) filename.match?("#{pattern}$")
.gsub('../', '')
File.fnmatch?("*#{glob}", filename)
end end
def relevant_rubocop_rspec_file?(_file) def relevant_rubocop_rspec_file?(_file)

View File

@ -20,6 +20,9 @@ module RuboCop
# describe MyClass do # describe MyClass do
# end # end
class Focus < Base class Focus < Base
extend AutoCorrector
include RangeHelp
MSG = 'Focused spec found.' MSG = 'Focused spec found.'
def_node_matcher :focusable_selector?, <<-PATTERN def_node_matcher :focusable_selector?, <<-PATTERN
@ -44,7 +47,13 @@ module RuboCop
def on_send(node) def on_send(node)
focus_metadata(node) do |focus| focus_metadata(node) do |focus|
add_offense(focus) add_offense(focus) do |corrector|
if focus.pair_type? || focus.str_type? || focus.sym_type?
corrector.remove(with_surrounding(focus))
elsif focus.send_type?
correct_send(corrector, focus)
end
end
end end
end end
@ -55,6 +64,26 @@ module RuboCop
metadata(node, &block) metadata(node, &block)
end end
def with_surrounding(focus)
range_with_space = range_with_surrounding_space(
range: focus.loc.expression,
side: :left
)
range_with_surrounding_comma(range_with_space, :left)
end
def correct_send(corrector, focus)
range = focus.loc.selector
unfocused = focus.method_name.to_s.sub(/^f/, '')
unless Examples.regular(unfocused) || ExampleGroups.regular(unfocused)
return
end
corrector.replace(range,
range.source.sub(focus.method_name.to_s, unfocused))
end
end end
end end
end end

Some files were not shown because too many files have changed in this diff Show More