Merge pull request #10750 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-performance-1.10.0
build(deps): bump rubocop-performance from 1.9.2 to 1.10.0 in /Library/Homebrew
This commit is contained in:
		
						commit
						37f7b9ee73
					
				@ -77,7 +77,7 @@ GEM
 | 
			
		||||
    rack (2.2.3)
 | 
			
		||||
    rainbow (3.0.0)
 | 
			
		||||
    rdiscount (2.2.0.2)
 | 
			
		||||
    regexp_parser (2.0.3)
 | 
			
		||||
    regexp_parser (2.1.1)
 | 
			
		||||
    rexml (3.2.4)
 | 
			
		||||
    ronn (0.7.3)
 | 
			
		||||
      hpricot (>= 0.8.2)
 | 
			
		||||
@ -119,7 +119,7 @@ GEM
 | 
			
		||||
      unicode-display_width (>= 1.4.0, < 3.0)
 | 
			
		||||
    rubocop-ast (1.4.1)
 | 
			
		||||
      parser (>= 2.7.1.5)
 | 
			
		||||
    rubocop-performance (1.9.2)
 | 
			
		||||
    rubocop-performance (1.10.0)
 | 
			
		||||
      rubocop (>= 0.90.0, < 2.0)
 | 
			
		||||
      rubocop-ast (>= 0.4.0)
 | 
			
		||||
    rubocop-rails (2.9.1)
 | 
			
		||||
 | 
			
		||||
@ -165,7 +165,7 @@ module Cask
 | 
			
		||||
      odebug "Auditing stanzas which require an uninstall"
 | 
			
		||||
 | 
			
		||||
      return if cask.artifacts.none? { |k| k.is_a?(Artifact::Pkg) || k.is_a?(Artifact::Installer) }
 | 
			
		||||
      return if cask.artifacts.any? { |k| k.is_a?(Artifact::Uninstall) }
 | 
			
		||||
      return if cask.artifacts.any?(Artifact::Uninstall)
 | 
			
		||||
 | 
			
		||||
      add_error "installer and pkg stanzas require an uninstall stanza"
 | 
			
		||||
    end
 | 
			
		||||
 | 
			
		||||
@ -474,7 +474,7 @@ module Homebrew
 | 
			
		||||
 | 
			
		||||
              "<#{type}>"
 | 
			
		||||
            end.compact
 | 
			
		||||
            types << "<subcommand>" if @named_args_type.any? { |type| type.is_a? String }
 | 
			
		||||
            types << "<subcommand>" if @named_args_type.any?(String)
 | 
			
		||||
            types.join("|")
 | 
			
		||||
          elsif SYMBOL_TO_USAGE_MAPPING.key? @named_args_type
 | 
			
		||||
            SYMBOL_TO_USAGE_MAPPING[@named_args_type]
 | 
			
		||||
 | 
			
		||||
@ -166,11 +166,11 @@ module Homebrew
 | 
			
		||||
 | 
			
		||||
      requirements = f.recursive_requirements
 | 
			
		||||
      if @bottle_tag.to_s.end_with?("_linux")
 | 
			
		||||
        if requirements.any? { |r| r.is_a?(MacOSRequirement) }
 | 
			
		||||
        if requirements.any?(MacOSRequirement)
 | 
			
		||||
          puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires macOS" if any_named_args
 | 
			
		||||
          next
 | 
			
		||||
        end
 | 
			
		||||
      elsif requirements.any? { |r| r.is_a?(LinuxRequirement) }
 | 
			
		||||
      elsif requirements.any?(LinuxRequirement)
 | 
			
		||||
        puts "#{Tty.bold}#{Tty.red}#{name}#{Tty.reset}: requires Linux" if any_named_args
 | 
			
		||||
        next
 | 
			
		||||
      else
 | 
			
		||||
 | 
			
		||||
@ -1052,7 +1052,7 @@ class CVSDownloadStrategy < VCSDownloadStrategy
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
  def split_url(in_url)
 | 
			
		||||
    parts = in_url.split(/:/)
 | 
			
		||||
    parts = in_url.split(":")
 | 
			
		||||
    mod = parts.pop
 | 
			
		||||
    url = parts.join(":")
 | 
			
		||||
    [mod, url]
 | 
			
		||||
 | 
			
		||||
@ -84,6 +84,10 @@ class Regexp::Expression::Backreference::Base < ::Regexp::Expression::Base
 | 
			
		||||
  def match_length; end
 | 
			
		||||
  def referenced_expression; end
 | 
			
		||||
  def referenced_expression=(_arg0); end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def initialize_copy(orig); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Regexp::Expression::Backreference::Name < ::Regexp::Expression::Backreference::Base
 | 
			
		||||
@ -198,7 +202,7 @@ class Regexp::Expression::Base
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def initialize_clone(orig); end
 | 
			
		||||
  def initialize_copy(orig); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Regexp::Expression::CharacterSet < ::Regexp::Expression::Subexpression
 | 
			
		||||
@ -292,6 +296,10 @@ class Regexp::Expression::Conditional::Condition < ::Regexp::Expression::Base
 | 
			
		||||
  def reference; end
 | 
			
		||||
  def referenced_expression; end
 | 
			
		||||
  def referenced_expression=(_arg0); end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def initialize_copy(orig); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Regexp::Expression::Conditional::Expression < ::Regexp::Expression::Subexpression
 | 
			
		||||
@ -306,9 +314,13 @@ class Regexp::Expression::Conditional::Expression < ::Regexp::Expression::Subexp
 | 
			
		||||
  def referenced_expression; end
 | 
			
		||||
  def referenced_expression=(_arg0); end
 | 
			
		||||
  def to_s(format = T.unsafe(nil)); end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def initialize_copy(orig); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Regexp::Expression::Conditional::TooManyBranches < ::StandardError
 | 
			
		||||
class Regexp::Expression::Conditional::TooManyBranches < ::Regexp::Parser::Error
 | 
			
		||||
  def initialize; end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -431,12 +443,16 @@ class Regexp::Expression::Group::Named < ::Regexp::Expression::Group::Capture
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def initialize_clone(orig); end
 | 
			
		||||
  def initialize_copy(orig); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Regexp::Expression::Group::Options < ::Regexp::Expression::Group::Base
 | 
			
		||||
  def option_changes; end
 | 
			
		||||
  def option_changes=(_arg0); end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def initialize_copy(orig); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Regexp::Expression::Group::Passive < ::Regexp::Expression::Group::Base
 | 
			
		||||
@ -486,7 +502,7 @@ class Regexp::Expression::Quantifier
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def initialize_clone(orig); end
 | 
			
		||||
  def initialize_copy(orig); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
Regexp::Expression::Quantifier::MODES = T.let(T.unsafe(nil), Array)
 | 
			
		||||
@ -553,7 +569,7 @@ class Regexp::Expression::Subexpression < ::Regexp::Expression::Base
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def initialize_clone(orig); end
 | 
			
		||||
  def initialize_copy(orig); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
module Regexp::Expression::UnicodeProperty
 | 
			
		||||
@ -867,7 +883,6 @@ end
 | 
			
		||||
 | 
			
		||||
class Regexp::Parser
 | 
			
		||||
  include(::Regexp::Expression)
 | 
			
		||||
  include(::Regexp::Syntax)
 | 
			
		||||
  include(::Regexp::Expression::UnicodeProperty)
 | 
			
		||||
 | 
			
		||||
  def parse(input, syntax = T.unsafe(nil), options: T.unsafe(nil), &block); end
 | 
			
		||||
@ -898,6 +913,7 @@ class Regexp::Parser
 | 
			
		||||
  def intersection(token); end
 | 
			
		||||
  def interval(target_node, token); end
 | 
			
		||||
  def keep(token); end
 | 
			
		||||
  def literal(token); end
 | 
			
		||||
  def meta(token); end
 | 
			
		||||
  def negate_set; end
 | 
			
		||||
  def nest(exp); end
 | 
			
		||||
@ -933,11 +949,16 @@ end
 | 
			
		||||
 | 
			
		||||
Regexp::Parser::ENC_FLAGS = T.let(T.unsafe(nil), Array)
 | 
			
		||||
 | 
			
		||||
class Regexp::Parser::Error < ::StandardError
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
Regexp::Parser::MOD_FLAGS = T.let(T.unsafe(nil), Array)
 | 
			
		||||
 | 
			
		||||
class Regexp::Parser::ParserError < ::StandardError
 | 
			
		||||
class Regexp::Parser::ParserError < ::Regexp::Parser::Error
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
Regexp::Parser::UPTokens = Regexp::Syntax::Token::UnicodeProperty
 | 
			
		||||
 | 
			
		||||
class Regexp::Parser::UnknownTokenError < ::Regexp::Parser::ParserError
 | 
			
		||||
  def initialize(type, token); end
 | 
			
		||||
end
 | 
			
		||||
@ -1005,20 +1026,18 @@ class Regexp::Scanner::InvalidSequenceError < ::Regexp::Scanner::ValidationError
 | 
			
		||||
  def initialize(what = T.unsafe(nil), where = T.unsafe(nil)); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
Regexp::Scanner::PROP_MAPS_DIR = T.let(T.unsafe(nil), String)
 | 
			
		||||
 | 
			
		||||
class Regexp::Scanner::PrematureEndError < ::Regexp::Scanner::ScannerError
 | 
			
		||||
  def initialize(where = T.unsafe(nil)); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Regexp::Scanner::ScannerError < ::StandardError
 | 
			
		||||
class Regexp::Scanner::ScannerError < ::Regexp::Parser::Error
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Regexp::Scanner::UnknownUnicodePropertyError < ::Regexp::Scanner::ValidationError
 | 
			
		||||
  def initialize(name); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Regexp::Scanner::ValidationError < ::StandardError
 | 
			
		||||
class Regexp::Scanner::ValidationError < ::Regexp::Parser::Error
 | 
			
		||||
  def initialize(reason); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
@ -1088,7 +1107,7 @@ class Regexp::Syntax::NotImplementedError < ::Regexp::Syntax::SyntaxError
 | 
			
		||||
  def initialize(syntax, type, token); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
class Regexp::Syntax::SyntaxError < ::StandardError
 | 
			
		||||
class Regexp::Syntax::SyntaxError < ::Regexp::Parser::Error
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
module Regexp::Syntax::Token
 | 
			
		||||
@ -238,7 +238,7 @@ class RuboCop::Cop::Performance::ConstantRegexp < ::RuboCop::Cop::Base
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def include_interpolated_const?(node); end
 | 
			
		||||
  def within_const_assignment?(node); end
 | 
			
		||||
  def within_allowed_assignment?(node); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
RuboCop::Cop::Performance::ConstantRegexp::MSG = T.let(T.unsafe(nil), String)
 | 
			
		||||
@ -482,6 +482,25 @@ RuboCop::Cop::Performance::RedundantBlockCall::SPACE = T.let(T.unsafe(nil), Stri
 | 
			
		||||
 | 
			
		||||
RuboCop::Cop::Performance::RedundantBlockCall::YIELD = T.let(T.unsafe(nil), String)
 | 
			
		||||
 | 
			
		||||
class RuboCop::Cop::Performance::RedundantEqualityComparisonBlock < ::RuboCop::Cop::Base
 | 
			
		||||
  extend(::RuboCop::Cop::AutoCorrector)
 | 
			
		||||
  extend(::RuboCop::Cop::TargetRubyVersion)
 | 
			
		||||
 | 
			
		||||
  def on_block(node); end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def new_argument(block_argument, block_body); end
 | 
			
		||||
  def offense_range(node); end
 | 
			
		||||
  def use_equality_comparison_block?(block_body); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
RuboCop::Cop::Performance::RedundantEqualityComparisonBlock::COMPARISON_METHODS = T.let(T.unsafe(nil), Array)
 | 
			
		||||
 | 
			
		||||
RuboCop::Cop::Performance::RedundantEqualityComparisonBlock::MSG = T.let(T.unsafe(nil), String)
 | 
			
		||||
 | 
			
		||||
RuboCop::Cop::Performance::RedundantEqualityComparisonBlock::TARGET_METHODS = T.let(T.unsafe(nil), Array)
 | 
			
		||||
 | 
			
		||||
class RuboCop::Cop::Performance::RedundantMatch < ::RuboCop::Cop::Base
 | 
			
		||||
  extend(::RuboCop::Cop::AutoCorrector)
 | 
			
		||||
 | 
			
		||||
@ -561,6 +580,27 @@ end
 | 
			
		||||
 | 
			
		||||
RuboCop::Cop::Performance::RedundantSortBlock::MSG = T.let(T.unsafe(nil), String)
 | 
			
		||||
 | 
			
		||||
class RuboCop::Cop::Performance::RedundantSplitRegexpArgument < ::RuboCop::Cop::Base
 | 
			
		||||
  extend(::RuboCop::Cop::AutoCorrector)
 | 
			
		||||
 | 
			
		||||
  def on_send(node); end
 | 
			
		||||
  def split_call_with_regexp?(param0 = T.unsafe(nil)); end
 | 
			
		||||
 | 
			
		||||
  private
 | 
			
		||||
 | 
			
		||||
  def autocorrect(corrector, node); end
 | 
			
		||||
  def determinist_regexp?(first_argument); end
 | 
			
		||||
  def replacement(node); end
 | 
			
		||||
end
 | 
			
		||||
 | 
			
		||||
RuboCop::Cop::Performance::RedundantSplitRegexpArgument::DETERMINISTIC_REGEX = T.let(T.unsafe(nil), Regexp)
 | 
			
		||||
 | 
			
		||||
RuboCop::Cop::Performance::RedundantSplitRegexpArgument::MSG = T.let(T.unsafe(nil), String)
 | 
			
		||||
 | 
			
		||||
RuboCop::Cop::Performance::RedundantSplitRegexpArgument::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
 | 
			
		||||
 | 
			
		||||
RuboCop::Cop::Performance::RedundantSplitRegexpArgument::STR_SPECIAL_CHARS = T.let(T.unsafe(nil), Array)
 | 
			
		||||
 | 
			
		||||
class RuboCop::Cop::Performance::RedundantStringChars < ::RuboCop::Cop::Base
 | 
			
		||||
  include(::RuboCop::Cop::RangeHelp)
 | 
			
		||||
  extend(::RuboCop::Cop::AutoCorrector)
 | 
			
		||||
@ -63,7 +63,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/pry-0.14.0/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rack-2.2.3/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/extensions/x86_64-darwin-14/2.6.0-static/rdiscount-2.2.0.2"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rdiscount-2.2.0.2/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/regexp_parser-2.0.3/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/regexp_parser-2.1.1/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rexml-3.2.4/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ronn-0.7.3/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rspec-support-3.10.2/lib"
 | 
			
		||||
@ -82,7 +82,7 @@ $:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-ast-1.4.1/lib
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/ruby-progressbar-1.11.0/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/unicode-display_width-2.0.0/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-1.10.0/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.9.2/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-performance-1.10.0/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rails-2.9.1/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-rspec-2.2.0/lib"
 | 
			
		||||
$:.unshift "#{path}/../#{ruby_engine}/#{ruby_version}/gems/rubocop-sorbet-0.5.1/lib"
 | 
			
		||||
 | 
			
		||||
@ -10,7 +10,7 @@ Performance/AncestorsInclude:
 | 
			
		||||
Performance/ArraySemiInfiniteRangeSlice:
 | 
			
		||||
  Description: 'Identifies places where slicing arrays with semi-infinite ranges can be replaced by `Array#take` and `Array#drop`.'
 | 
			
		||||
  # This cop was created due to a mistake in microbenchmark.
 | 
			
		||||
  # Refer https://github.com/rubocop-hq/rubocop-performance/pull/175#issuecomment-731892717
 | 
			
		||||
  # Refer https://github.com/rubocop/rubocop-performance/pull/175#issuecomment-731892717
 | 
			
		||||
  Enabled: false
 | 
			
		||||
  # Unsafe for string slices because strings do not have `#take` and `#drop` methods.
 | 
			
		||||
  Safe: false
 | 
			
		||||
@ -80,6 +80,7 @@ Performance/ConstantRegexp:
 | 
			
		||||
  Description: 'Finds regular expressions with dynamic components that are all constants.'
 | 
			
		||||
  Enabled: pending
 | 
			
		||||
  VersionAdded: '1.9'
 | 
			
		||||
  VersionChanged: '1.10'
 | 
			
		||||
 | 
			
		||||
Performance/Count:
 | 
			
		||||
  Description: >-
 | 
			
		||||
@ -136,11 +137,10 @@ Performance/EndWith:
 | 
			
		||||
  # object. Switching these methods has to be done with knowledge of the types
 | 
			
		||||
  # of the variables which rubocop doesn't have.
 | 
			
		||||
  SafeAutoCorrect: false
 | 
			
		||||
  AutoCorrect: false
 | 
			
		||||
  Enabled: true
 | 
			
		||||
  SafeMultiline: true
 | 
			
		||||
  VersionAdded: '0.36'
 | 
			
		||||
  VersionChanged: '1.6'
 | 
			
		||||
  VersionChanged: '1.10'
 | 
			
		||||
 | 
			
		||||
Performance/FixedSize:
 | 
			
		||||
  Description: 'Do not compute the size of statically sized objects except in constants.'
 | 
			
		||||
@ -200,6 +200,15 @@ Performance/RedundantBlockCall:
 | 
			
		||||
  Enabled: true
 | 
			
		||||
  VersionAdded: '0.36'
 | 
			
		||||
 | 
			
		||||
Performance/RedundantEqualityComparisonBlock:
 | 
			
		||||
  Description: >-
 | 
			
		||||
                  Checks for uses `Enumerable#all?`, `Enumerable#any?`, `Enumerable#one?`,
 | 
			
		||||
                  or `Enumerable#none?` are compared with `===` or similar methods in block.
 | 
			
		||||
  Reference: 'https://github.com/rails/rails/pull/41363'
 | 
			
		||||
  Enabled: pending
 | 
			
		||||
  Safe: false
 | 
			
		||||
  VersionAdded: '1.10'
 | 
			
		||||
 | 
			
		||||
Performance/RedundantMatch:
 | 
			
		||||
  Description: >-
 | 
			
		||||
                  Use `=~` instead of `String#match` or `Regexp#match` in a context where the
 | 
			
		||||
@ -220,6 +229,11 @@ Performance/RedundantSortBlock:
 | 
			
		||||
  Enabled: 'pending'
 | 
			
		||||
  VersionAdded: '1.7'
 | 
			
		||||
 | 
			
		||||
Performance/RedundantSplitRegexpArgument:
 | 
			
		||||
  Description: 'This cop identifies places where `split` argument can be replaced from a deterministic regexp to a string.'
 | 
			
		||||
  Enabled: pending
 | 
			
		||||
  VersionAdded: '1.10'
 | 
			
		||||
 | 
			
		||||
Performance/RedundantStringChars:
 | 
			
		||||
  Description: 'Checks for redundant `String#chars`.'
 | 
			
		||||
  Enabled: 'pending'
 | 
			
		||||
@ -270,11 +284,10 @@ Performance/StartWith:
 | 
			
		||||
  # object. Switching these methods has to be done with knowledge of the types
 | 
			
		||||
  # of the variables which rubocop doesn't have.
 | 
			
		||||
  SafeAutoCorrect: false
 | 
			
		||||
  AutoCorrect: false
 | 
			
		||||
  Enabled: true
 | 
			
		||||
  SafeMultiline: true
 | 
			
		||||
  VersionAdded: '0.36'
 | 
			
		||||
  VersionChanged: '1.6'
 | 
			
		||||
  VersionChanged: '1.10'
 | 
			
		||||
 | 
			
		||||
Performance/StringInclude:
 | 
			
		||||
  Description: 'Use `String#include?` instead of a regex match with literal-only pattern.'
 | 
			
		||||
@ -304,7 +317,7 @@ Performance/TimesMap:
 | 
			
		||||
  Enabled: true
 | 
			
		||||
  VersionAdded: '0.36'
 | 
			
		||||
  VersionChanged: '0.50'
 | 
			
		||||
  SafeAutoCorrect: false # see https://github.com/rubocop-hq/rubocop/issues/4658
 | 
			
		||||
  SafeAutoCorrect: false # see https://github.com/rubocop/rubocop/issues/4658
 | 
			
		||||
 | 
			
		||||
Performance/UnfreezeString:
 | 
			
		||||
  Description: 'Use unary plus to get an unfrozen string literal.'
 | 
			
		||||
@ -6,7 +6,7 @@ module RuboCop
 | 
			
		||||
      # This cop identifies places where slicing arrays with semi-infinite ranges
 | 
			
		||||
      # can be replaced by `Array#take` and `Array#drop`.
 | 
			
		||||
      # This cop was created due to a mistake in microbenchmark and hence is disabled by default.
 | 
			
		||||
      # Refer https://github.com/rubocop-hq/rubocop-performance/pull/175#issuecomment-731892717
 | 
			
		||||
      # Refer https://github.com/rubocop/rubocop-performance/pull/175#issuecomment-731892717
 | 
			
		||||
      # This cop is also unsafe for string slices because strings do not have `#take` and `#drop` methods.
 | 
			
		||||
      #
 | 
			
		||||
      # @example
 | 
			
		||||
@ -33,7 +33,7 @@ module RuboCop
 | 
			
		||||
        def_node_matcher :bind_with_call_method?, <<~PATTERN
 | 
			
		||||
          (send
 | 
			
		||||
            $(send
 | 
			
		||||
              (send nil? _) :bind
 | 
			
		||||
              _ :bind
 | 
			
		||||
              $(...)) :call
 | 
			
		||||
            $...)
 | 
			
		||||
        PATTERN
 | 
			
		||||
@ -64,7 +64,7 @@ module RuboCop
 | 
			
		||||
 | 
			
		||||
        def correction_range(receiver, node)
 | 
			
		||||
          location_of_bind = receiver.loc.selector.begin_pos
 | 
			
		||||
          location_of_call = node.loc.end.end_pos
 | 
			
		||||
          location_of_call = node.source_range.end.end_pos
 | 
			
		||||
 | 
			
		||||
          range_between(location_of_bind, location_of_call)
 | 
			
		||||
        end
 | 
			
		||||
@ -6,9 +6,9 @@ module RuboCop
 | 
			
		||||
      # This cop finds regular expressions with dynamic components that are all constants.
 | 
			
		||||
      #
 | 
			
		||||
      # Ruby allocates a new Regexp object every time it executes a code containing such
 | 
			
		||||
      # a regular expression. It is more efficient to extract it into a constant
 | 
			
		||||
      # or add an `/o` option to perform `#{}` interpolation only once and reuse that
 | 
			
		||||
      # Regexp object.
 | 
			
		||||
      # a regular expression. It is more efficient to extract it into a constant,
 | 
			
		||||
      # memoize it, or add an `/o` option to perform `#{}` interpolation only once and
 | 
			
		||||
      # reuse that Regexp object.
 | 
			
		||||
      #
 | 
			
		||||
      # @example
 | 
			
		||||
      #
 | 
			
		||||
@ -28,13 +28,18 @@ module RuboCop
 | 
			
		||||
      #     pattern.scan(TOKEN).reject { |token| token.match?(/\A#{SEPARATORS}\Z/o) }
 | 
			
		||||
      #   end
 | 
			
		||||
      #
 | 
			
		||||
      #   # good
 | 
			
		||||
      #   def separators
 | 
			
		||||
      #     @separators ||= /\A#{SEPARATORS}\Z/
 | 
			
		||||
      #   end
 | 
			
		||||
      #
 | 
			
		||||
      class ConstantRegexp < Base
 | 
			
		||||
        extend AutoCorrector
 | 
			
		||||
 | 
			
		||||
        MSG = 'Extract this regexp into a constant or append an `/o` option to its options.'
 | 
			
		||||
        MSG = 'Extract this regexp into a constant, memoize it, or append an `/o` option to its options.'
 | 
			
		||||
 | 
			
		||||
        def on_regexp(node)
 | 
			
		||||
          return if within_const_assignment?(node) ||
 | 
			
		||||
          return if within_allowed_assignment?(node) ||
 | 
			
		||||
                    !include_interpolated_const?(node) ||
 | 
			
		||||
                    node.single_interpolation?
 | 
			
		||||
 | 
			
		||||
@ -45,8 +50,8 @@ module RuboCop
 | 
			
		||||
 | 
			
		||||
        private
 | 
			
		||||
 | 
			
		||||
        def within_const_assignment?(node)
 | 
			
		||||
          node.each_ancestor(:casgn).any?
 | 
			
		||||
        def within_allowed_assignment?(node)
 | 
			
		||||
          node.each_ancestor(:casgn, :or_asgn).any?
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        def_node_matcher :regexp_escape?, <<~PATTERN
 | 
			
		||||
@ -0,0 +1,72 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
module RuboCop
 | 
			
		||||
  module Cop
 | 
			
		||||
    module Performance
 | 
			
		||||
      # This cop checks for uses `Enumerable#all?`, `Enumerable#any?`, `Enumerable#one?`,
 | 
			
		||||
      # and `Enumerable#none?` are compared with `===` or similar methods in block.
 | 
			
		||||
      #
 | 
			
		||||
      # By default, `Object#===` behaves the same as `Object#==`, but this
 | 
			
		||||
      # behavior is appropriately overridden in subclass. For example,
 | 
			
		||||
      # `Range#===` returns `true` when argument is within the range.
 | 
			
		||||
      # Therefore, It is marked as unsafe by default because `===` and `==`
 | 
			
		||||
      # do not always behave the same.
 | 
			
		||||
      #
 | 
			
		||||
      # @example
 | 
			
		||||
      #   # bad
 | 
			
		||||
      #   items.all? { |item| pattern === item }
 | 
			
		||||
      #   items.all? { |item| item == other }
 | 
			
		||||
      #   items.all? { |item| item.is_a?(Klass) }
 | 
			
		||||
      #   items.all? { |item| item.kind_of?(Klass) }
 | 
			
		||||
      #
 | 
			
		||||
      #   # good
 | 
			
		||||
      #   items.all?(pattern)
 | 
			
		||||
      #
 | 
			
		||||
      class RedundantEqualityComparisonBlock < Base
 | 
			
		||||
        extend AutoCorrector
 | 
			
		||||
        extend TargetRubyVersion
 | 
			
		||||
 | 
			
		||||
        minimum_target_ruby_version 2.5
 | 
			
		||||
 | 
			
		||||
        MSG = 'Use `%<prefer>s` instead of block.'
 | 
			
		||||
 | 
			
		||||
        TARGET_METHODS = %i[all? any? one? none?].freeze
 | 
			
		||||
        COMPARISON_METHODS = %i[== === is_a? kind_of?].freeze
 | 
			
		||||
 | 
			
		||||
        def on_block(node)
 | 
			
		||||
          return unless TARGET_METHODS.include?(node.method_name)
 | 
			
		||||
 | 
			
		||||
          block_argument = node.arguments.first
 | 
			
		||||
          block_body = node.body
 | 
			
		||||
          return unless use_equality_comparison_block?(block_body)
 | 
			
		||||
          return unless (new_argument = new_argument(block_argument, block_body))
 | 
			
		||||
 | 
			
		||||
          range = offense_range(node)
 | 
			
		||||
          prefer = "#{node.method_name}(#{new_argument})"
 | 
			
		||||
 | 
			
		||||
          add_offense(range, message: format(MSG, prefer: prefer)) do |corrector|
 | 
			
		||||
            corrector.replace(range, prefer)
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        private
 | 
			
		||||
 | 
			
		||||
        def use_equality_comparison_block?(block_body)
 | 
			
		||||
          block_body.send_type? && COMPARISON_METHODS.include?(block_body.method_name)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        def new_argument(block_argument, block_body)
 | 
			
		||||
          if block_argument.source == block_body.receiver.source
 | 
			
		||||
            block_body.first_argument.source
 | 
			
		||||
          elsif block_argument.source == block_body.first_argument.source
 | 
			
		||||
            block_body.receiver.source
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        def offense_range(node)
 | 
			
		||||
          node.send_node.loc.selector.join(node.source_range.end)
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -0,0 +1,67 @@
 | 
			
		||||
# frozen_string_literal: true
 | 
			
		||||
 | 
			
		||||
module RuboCop
 | 
			
		||||
  module Cop
 | 
			
		||||
    module Performance
 | 
			
		||||
      # This cop identifies places where `split` argument can be replaced from
 | 
			
		||||
      # a deterministic regexp to a string.
 | 
			
		||||
      #
 | 
			
		||||
      # @example
 | 
			
		||||
      #   # bad
 | 
			
		||||
      #   'a,b,c'.split(/,/)
 | 
			
		||||
      #
 | 
			
		||||
      #   # good
 | 
			
		||||
      #   'a,b,c'.split(',')
 | 
			
		||||
      class RedundantSplitRegexpArgument < Base
 | 
			
		||||
        extend AutoCorrector
 | 
			
		||||
 | 
			
		||||
        MSG = 'Use string as argument instead of regexp.'
 | 
			
		||||
        RESTRICT_ON_SEND = %i[split].freeze
 | 
			
		||||
        DETERMINISTIC_REGEX = /\A(?:#{LITERAL_REGEX})+\Z/.freeze
 | 
			
		||||
        STR_SPECIAL_CHARS = %w[\n \" \' \\\\ \t \b \f \r].freeze
 | 
			
		||||
 | 
			
		||||
        def_node_matcher :split_call_with_regexp?, <<~PATTERN
 | 
			
		||||
          {(send !nil? :split {regexp})}
 | 
			
		||||
        PATTERN
 | 
			
		||||
 | 
			
		||||
        def on_send(node)
 | 
			
		||||
          return unless split_call_with_regexp?(node)
 | 
			
		||||
          return unless determinist_regexp?(node.first_argument)
 | 
			
		||||
 | 
			
		||||
          add_offense(node.first_argument) do |corrector|
 | 
			
		||||
            autocorrect(corrector, node)
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        private
 | 
			
		||||
 | 
			
		||||
        def determinist_regexp?(first_argument)
 | 
			
		||||
          DETERMINISTIC_REGEX.match?(first_argument.source)
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        def autocorrect(corrector, node)
 | 
			
		||||
          new_argument = replacement(node)
 | 
			
		||||
 | 
			
		||||
          corrector.replace(node.first_argument, "\"#{new_argument}\"")
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        def replacement(node)
 | 
			
		||||
          regexp_content = node.first_argument.content
 | 
			
		||||
          stack = []
 | 
			
		||||
          chars = regexp_content.chars.each_with_object([]) do |char, strings|
 | 
			
		||||
            if stack.empty? && char == '\\'
 | 
			
		||||
              stack.push(char)
 | 
			
		||||
            else
 | 
			
		||||
              strings << "#{stack.pop}#{char}"
 | 
			
		||||
            end
 | 
			
		||||
          end
 | 
			
		||||
          chars.map do |char|
 | 
			
		||||
            char = char.dup
 | 
			
		||||
            char.delete!('\\') unless STR_SPECIAL_CHARS.include?(char)
 | 
			
		||||
            char
 | 
			
		||||
          end.join
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
@ -150,7 +150,9 @@ module RuboCop
 | 
			
		||||
          replacement = build_good_method(init, block_pass)
 | 
			
		||||
 | 
			
		||||
          corrector.remove(sum_range)
 | 
			
		||||
          corrector.replace(map_range, ".#{replacement}")
 | 
			
		||||
 | 
			
		||||
          dot = '.' if map.receiver
 | 
			
		||||
          corrector.replace(map_range, "#{dot}#{replacement}")
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        def sum_method_range(node)
 | 
			
		||||
@ -228,7 +230,11 @@ module RuboCop
 | 
			
		||||
        end
 | 
			
		||||
 | 
			
		||||
        def method_call_with_args_range(node)
 | 
			
		||||
          node.receiver.source_range.end.join(node.source_range.end)
 | 
			
		||||
          if (receiver = node.receiver)
 | 
			
		||||
            receiver.source_range.end.join(node.source_range.end)
 | 
			
		||||
          else
 | 
			
		||||
            node.source_range
 | 
			
		||||
          end
 | 
			
		||||
        end
 | 
			
		||||
      end
 | 
			
		||||
    end
 | 
			
		||||
@ -28,9 +28,11 @@ require_relative 'performance/open_struct'
 | 
			
		||||
require_relative 'performance/range_include'
 | 
			
		||||
require_relative 'performance/io_readlines'
 | 
			
		||||
require_relative 'performance/redundant_block_call'
 | 
			
		||||
require_relative 'performance/redundant_equality_comparison_block'
 | 
			
		||||
require_relative 'performance/redundant_match'
 | 
			
		||||
require_relative 'performance/redundant_merge'
 | 
			
		||||
require_relative 'performance/redundant_sort_block'
 | 
			
		||||
require_relative 'performance/redundant_split_regexp_argument'
 | 
			
		||||
require_relative 'performance/redundant_string_chars'
 | 
			
		||||
require_relative 'performance/regexp_match'
 | 
			
		||||
require_relative 'performance/reverse_each'
 | 
			
		||||
@ -4,7 +4,7 @@ module RuboCop
 | 
			
		||||
  module Performance
 | 
			
		||||
    # This module holds the RuboCop Performance version information.
 | 
			
		||||
    module Version
 | 
			
		||||
      STRING = '1.9.2'
 | 
			
		||||
      STRING = '1.10.0'
 | 
			
		||||
 | 
			
		||||
      def self.document_version
 | 
			
		||||
        STRING.match('\d+\.\d+').to_s
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user