Fix RuboCop CaseEquality.

This commit is contained in:
Markus Reiter 2016-09-20 22:03:08 +02:00
parent db37920fa7
commit 52ff988530
17 changed files with 155 additions and 60 deletions

View File

@ -1,6 +1,6 @@
# This configuration was generated by # This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 30` # `rubocop --auto-gen-config --exclude-limit 100`
# on 2016-09-18 15:15:22 +0100 using RuboCop version 0.41.2. # on 2016-09-20 22:03:20 +0200 using RuboCop version 0.43.0.
# The point is for the user to remove these configuration records # The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base. # one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new # Note that changes in the inspected code, or installation of new
@ -80,12 +80,7 @@ Lint/RescueException:
# Offense count: 1 # Offense count: 1
Lint/ShadowedException: Lint/ShadowedException:
Exclude: Exclude:
- 'Homebrew/brew.rb' - 'Homebrew/utils/fork.rb'
# Offense count: 2
Lint/UselessAssignment:
Exclude:
- 'Homebrew/requirements.rb'
# Offense count: 18 # Offense count: 18
Metrics/BlockNesting: Metrics/BlockNesting:
@ -94,9 +89,9 @@ Metrics/BlockNesting:
# Offense count: 20 # Offense count: 20
# Configuration parameters: CountComments. # Configuration parameters: CountComments.
Metrics/ModuleLength: Metrics/ModuleLength:
Max: 400 Max: 373
# Offense count: 1 # Offense count: 2
# Configuration parameters: CountKeywordArgs. # Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists: Metrics/ParameterLists:
Max: 6 Max: 6
@ -125,25 +120,10 @@ Style/Alias:
Exclude: Exclude:
- 'Homebrew/blacklist.rb' - 'Homebrew/blacklist.rb'
# Offense count: 26 # Offense count: 1
Style/CaseEquality: Style/CaseEquality:
Exclude: Exclude:
- 'Homebrew/cleanup.rb'
- 'Homebrew/cmd/search.rb'
- 'Homebrew/compilers.rb' - 'Homebrew/compilers.rb'
- 'Homebrew/cxxstdlib.rb'
- 'Homebrew/debrew.rb'
- 'Homebrew/dependencies.rb'
- 'Homebrew/dependency_collector.rb'
- 'Homebrew/download_strategy.rb'
- 'Homebrew/formula.rb'
- 'Homebrew/options.rb'
- 'Homebrew/patch.rb'
- 'Homebrew/pkg_version.rb'
- 'Homebrew/requirement.rb'
- 'Homebrew/requirements.rb'
- 'Homebrew/software_spec.rb'
- 'Homebrew/version.rb'
# Offense count: 1 # Offense count: 1
# Cop supports --auto-correct. # Cop supports --auto-correct.
@ -193,11 +173,103 @@ Style/GlobalVars:
- 'Homebrew/diagnostic.rb' - 'Homebrew/diagnostic.rb'
- 'Homebrew/utils.rb' - 'Homebrew/utils.rb'
# Offense count: 97
# Configuration parameters: MinBodyLength.
Style/GuardClause:
Exclude:
- 'Taps/**/*'
- 'Homebrew/brew.rb'
- 'Homebrew/build.rb'
- 'Homebrew/caveats.rb'
- 'Homebrew/cleaner.rb'
- 'Homebrew/cmd/cleanup.rb'
- 'Homebrew/cmd/diy.rb'
- 'Homebrew/cmd/info.rb'
- 'Homebrew/cmd/install.rb'
- 'Homebrew/cmd/reinstall.rb'
- 'Homebrew/cmd/search.rb'
- 'Homebrew/cmd/update-report.rb'
- 'Homebrew/dependency_collector.rb'
- 'Homebrew/dev-cmd/audit.rb'
- 'Homebrew/dev-cmd/bottle.rb'
- 'Homebrew/dev-cmd/pull.rb'
- 'Homebrew/dev-cmd/test-bot.rb'
- 'Homebrew/download_strategy.rb'
- 'Homebrew/extend/ARGV.rb'
- 'Homebrew/extend/ENV/shared.rb'
- 'Homebrew/extend/ENV/std.rb'
- 'Homebrew/extend/ENV/super.rb'
- 'Homebrew/extend/fileutils.rb'
- 'Homebrew/extend/os/mac/extend/ENV/std.rb'
- 'Homebrew/extend/os/mac/formula_cellar_checks.rb'
- 'Homebrew/extend/os/mac/utils/bottles.rb'
- 'Homebrew/extend/string.rb'
- 'Homebrew/formula.rb'
- 'Homebrew/formula_installer.rb'
- 'Homebrew/formula_lock.rb'
- 'Homebrew/formulary.rb'
- 'Homebrew/keg.rb'
- 'Homebrew/migrator.rb'
- 'Homebrew/os/mac/xcode.rb'
- 'Homebrew/patch.rb'
- 'Homebrew/requirement.rb'
- 'Homebrew/tap.rb'
- 'Homebrew/test/test_cmd_testbot.rb'
- 'Homebrew/test/test_integration_cmds.rb'
- 'Homebrew/test/testing_env.rb'
- 'Homebrew/utils.rb'
- 'Homebrew/utils/popen.rb'
- 'Homebrew/version.rb'
# Offense count: 2 # Offense count: 2
Style/IdenticalConditionalBranches: Style/IdenticalConditionalBranches:
Exclude: Exclude:
- 'Homebrew/formula_lock.rb' - 'Homebrew/formula_lock.rb'
# Offense count: 52
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
Exclude:
- 'Taps/**/*'
- 'Homebrew/dev-cmd/audit.rb'
- 'Homebrew/dev-cmd/bottle.rb'
- 'Homebrew/dev-cmd/edit.rb'
- 'Homebrew/dev-cmd/mirror.rb'
- 'Homebrew/dev-cmd/pull.rb'
- 'Homebrew/dev-cmd/test-bot.rb'
- 'Homebrew/extend/ENV/std.rb'
- 'Homebrew/extend/ENV/super.rb'
- 'Homebrew/extend/os/blacklist.rb'
- 'Homebrew/extend/os/bottles.rb'
- 'Homebrew/extend/os/cleaner.rb'
- 'Homebrew/extend/os/development_tools.rb'
- 'Homebrew/extend/os/diagnostic.rb'
- 'Homebrew/extend/os/emoji.rb'
- 'Homebrew/extend/os/extend/ENV/shared.rb'
- 'Homebrew/extend/os/extend/ENV/std.rb'
- 'Homebrew/extend/os/extend/ENV/super.rb'
- 'Homebrew/extend/os/formula_cellar_checks.rb'
- 'Homebrew/extend/os/keg_relocate.rb'
- 'Homebrew/extend/os/mac/extend/ENV/shared.rb'
- 'Homebrew/extend/os/system_config.rb'
- 'Homebrew/formula.rb'
- 'Homebrew/formula_installer.rb'
- 'Homebrew/formula_versions.rb'
- 'Homebrew/formulary.rb'
- 'Homebrew/language/haskell.rb'
- 'Homebrew/migrator.rb'
- 'Homebrew/os/mac/cctools_mach.rb'
- 'Homebrew/tab.rb'
- 'Homebrew/utils/git.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles, IndentationWidth.
# SupportedStyles: special_inside_parentheses, consistent, align_brackets
Style/IndentArray:
EnforcedStyle: special_inside_parentheses
# Offense count: 5 # Offense count: 5
# Configuration parameters: EnforcedStyle, SupportedStyles. # Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: snake_case, camelCase # SupportedStyles: snake_case, camelCase
@ -249,6 +321,11 @@ Style/Next:
Exclude: Exclude:
- 'Homebrew/dev-cmd/test-bot.rb' - 'Homebrew/dev-cmd/test-bot.rb'
# Offense count: 1
# Cop supports --auto-correct.
Style/NumericLiterals:
MinDigits: 6
# Offense count: 9 # Offense count: 9
Style/OpMethod: Style/OpMethod:
Exclude: Exclude:
@ -291,3 +368,18 @@ Style/Semicolon:
Style/SingleLineBlockParams: Style/SingleLineBlockParams:
Exclude: Exclude:
- 'Homebrew/diagnostic.rb' - 'Homebrew/diagnostic.rb'
# Offense count: 2
# Cop supports --auto-correct.
# Configuration parameters: SupportedStyles.
# SupportedStyles: use_perl_names, use_english_names
Style/SpecialGlobalVars:
EnforcedStyle: use_perl_names
# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles, AllowSafeAssignment.
# SupportedStyles: require_parentheses, require_no_parentheses
Style/TernaryParentheses:
Exclude:
- 'Homebrew/formula.rb'

View File

@ -1,6 +1,7 @@
AllCops: AllCops:
TargetRubyVersion: 2.0 TargetRubyVersion: 2.0
Exclude: Exclude:
- '**/.simplecov'
- '**/Casks/**/*' - '**/Casks/**/*'
- '**/vendor/**/*' - '**/vendor/**/*'

View File

@ -66,7 +66,7 @@ module Homebrew
next unless path.file? next unless path.file?
file = path file = path
if Pathname::BOTTLE_EXTNAME_RX === file.to_s if file.to_s =~ Pathname::BOTTLE_EXTNAME_RX
version = begin version = begin
Utils::Bottles.resolve_version(file) Utils::Bottles.resolve_version(file)
rescue rescue
@ -86,7 +86,7 @@ module Homebrew
next next
end end
file_is_stale = if PkgVersion === version file_is_stale = if version.is_a?(PkgVersion)
f.pkg_version > version f.pkg_version > version
else else
f.version > version f.version > version

View File

@ -150,7 +150,7 @@ module Homebrew
names = remote_tap_formulae["#{user}/#{repo}"] names = remote_tap_formulae["#{user}/#{repo}"]
user = user.downcase if user == "Homebrew" # special handling for the Homebrew organization user = user.downcase if user == "Homebrew" # special handling for the Homebrew organization
names.select { |name| rx === name }.map { |name| "#{user}/#{repo}/#{name}" } names.select { |name| name =~ rx }.map { |name| "#{user}/#{repo}/#{name}" }
rescue GitHub::HTTPNotFoundError rescue GitHub::HTTPNotFoundError
opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`" opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`"
[] []

View File

@ -16,7 +16,7 @@ class CxxStdlib
if type && ![:libstdcxx, :libcxx].include?(type) if type && ![:libstdcxx, :libcxx].include?(type)
raise ArgumentError, "Invalid C++ stdlib type: #{type}" raise ArgumentError, "Invalid C++ stdlib type: #{type}"
end end
klass = GNU_GCC_REGEXP === compiler.to_s ? GnuStdlib : AppleStdlib klass = compiler.to_s =~ GNU_GCC_REGEXP ? GnuStdlib : AppleStdlib
klass.new(type, compiler) klass.new(type, compiler)
end end

View File

@ -118,20 +118,22 @@ module Debrew
menu.prompt = "Choose an action: " menu.prompt = "Choose an action: "
menu.choice(:raise) { original_raise(e) } menu.choice(:raise) { original_raise(e) }
menu.choice(:ignore) { return :ignore } if Ignorable === e menu.choice(:ignore) { return :ignore } if e.is_a?(Ignorable)
menu.choice(:backtrace) { puts e.backtrace } menu.choice(:backtrace) { puts e.backtrace }
menu.choice(:irb) do if e.is_a?(Ignorable)
puts "When you exit this IRB session, execution will continue." menu.choice(:irb) do
set_trace_func proc { |event, _, _, id, binding, klass| puts "When you exit this IRB session, execution will continue."
if klass == Raise && id == :raise && event == "return" set_trace_func proc { |event, _, _, id, binding, klass|
set_trace_func(nil) if klass == Raise && id == :raise && event == "return"
synchronize { IRB.start_within(binding) } set_trace_func(nil)
end synchronize { IRB.start_within(binding) }
} end
}
return :ignore return :ignore
end if Ignorable === e end
end
menu.choice(:shell) do menu.choice(:shell) do
puts "When you exit this shell, you will return to the menu." puts "When you exit this shell, you will return to the menu."

View File

@ -69,7 +69,7 @@ class Requirements
end end
def <<(other) def <<(other)
if Comparable === other if other.is_a?(Comparable)
@reqs.grep(other.class) do |req| @reqs.grep(other.class) do |req|
return self if req > other return self if req > other
@reqs.delete(req) @reqs.delete(req)

View File

@ -49,7 +49,7 @@ class DependencyCollector
end end
def cache_key(spec) def cache_key(spec)
if Resource === spec && spec.download_strategy == CurlDownloadStrategy if spec.is_a?(Resource) && spec.download_strategy == CurlDownloadStrategy
File.extname(spec.url) File.extname(spec.url)
else else
spec spec
@ -57,7 +57,7 @@ class DependencyCollector
end end
def build(spec) def build(spec)
spec, tags = Hash === spec ? spec.first : spec spec, tags = spec.is_a?(Hash) ? spec.first : spec
parse_spec(spec, Array(tags)) parse_spec(spec, Array(tags))
end end
@ -81,7 +81,7 @@ class DependencyCollector
end end
def parse_string_spec(spec, tags) def parse_string_spec(spec, tags)
if HOMEBREW_TAP_FORMULA_REGEX === spec if spec =~ HOMEBREW_TAP_FORMULA_REGEX
TapDependency.new(spec, tags) TapDependency.new(spec, tags)
elsif tags.empty? elsif tags.empty?
Dependency.new(spec, tags) Dependency.new(spec, tags)

View File

@ -668,7 +668,7 @@ class GitDownloadStrategy < VCSDownloadStrategy
end end
def support_depth? def support_depth?
@ref_type != :revision && SHALLOW_CLONE_WHITELIST.any? { |rx| rx === @url } @ref_type != :revision && SHALLOW_CLONE_WHITELIST.any? { |regex| @url =~ regex }
end end
def git_dir def git_dir
@ -1021,9 +1021,9 @@ class DownloadStrategyDetector
def self.detect(url, strategy = nil) def self.detect(url, strategy = nil)
if strategy.nil? if strategy.nil?
detect_from_url(url) detect_from_url(url)
elsif Class === strategy && strategy < AbstractDownloadStrategy elsif strategy.is_a?(Class) && strategy < AbstractDownloadStrategy
strategy strategy
elsif Symbol === strategy elsif strategy.is_a?(Symbol)
detect_from_symbol(strategy) detect_from_symbol(strategy)
else else
raise TypeError, raise TypeError,

View File

@ -1052,7 +1052,7 @@ class Formula
self.class.link_overwrite_paths.any? do |p| self.class.link_overwrite_paths.any? do |p|
p == to_check || p == to_check ||
to_check.start_with?(p.chomp("/") + "/") || to_check.start_with?(p.chomp("/") + "/") ||
/^#{Regexp.escape(p).gsub('\*', ".*?")}$/ === to_check to_check =~ /^#{Regexp.escape(p).gsub('\*', ".*?")}$/
end end
end end
@ -1246,7 +1246,7 @@ class Formula
# @private # @private
def <=>(other) def <=>(other)
return unless Formula === other return unless other.is_a?(Formula)
name <=> other.name name <=> other.name
end end
@ -2226,7 +2226,7 @@ class Formula
# If this formula conflicts with another one. # If this formula conflicts with another one.
# <pre>conflicts_with "imagemagick", :because => "because this is just a stupid example"</pre> # <pre>conflicts_with "imagemagick", :because => "because this is just a stupid example"</pre>
def conflicts_with(*names) def conflicts_with(*names)
opts = Hash === names.last ? names.pop : {} opts = names.last.is_a?(Hash) ? names.pop : {}
names.each { |name| conflicts << FormulaConflict.new(name, opts[:because]) } names.each { |name| conflicts << FormulaConflict.new(name, opts[:because]) }
end end

View File

@ -14,7 +14,7 @@ class Option
end end
def <=>(other) def <=>(other)
return unless Option === other return unless other.is_a?(Option)
name <=> other.name name <=> other.name
end end

View File

@ -89,7 +89,7 @@ class DATAPatch < EmbeddedPatch
path.open("rb") do |f| path.open("rb") do |f|
begin begin
line = f.gets line = f.gets
end until line.nil? || /^__END__$/ === line end until line.nil? || line =~ /^__END__$/
data << line while line = f.gets data << line while line = f.gets
end end
data data

View File

@ -32,7 +32,7 @@ class PkgVersion
alias_method :to_str, :to_s alias_method :to_str, :to_s
def <=>(other) def <=>(other)
return unless PkgVersion === other return unless other.is_a?(PkgVersion)
(version <=> other.version).nonzero? || revision <=> other.revision (version <=> other.version).nonzero? || revision <=> other.revision
end end
alias_method :eql?, :== alias_method :eql?, :==

View File

@ -83,7 +83,7 @@ class Requirement
# PATH. # PATH.
# This is undocumented magic and it should be removed, but we need to add # This is undocumented magic and it should be removed, but we need to add
# a way to declare path-based requirements that work with superenv first. # a way to declare path-based requirements that work with superenv first.
if Pathname === @satisfied_result if @satisfied_result.is_a?(Pathname)
parent = @satisfied_result.parent parent = @satisfied_result.parent
unless ENV["PATH"].split(File::PATH_SEPARATOR).include?(parent.to_s) unless ENV["PATH"].split(File::PATH_SEPARATOR).include?(parent.to_s)
ENV.append_path("PATH", parent) ENV.append_path("PATH", parent)
@ -115,7 +115,7 @@ class Requirement
def to_dependency def to_dependency
f = self.class.default_formula f = self.class.default_formula
raise "No default formula defined for #{inspect}" if f.nil? raise "No default formula defined for #{inspect}" if f.nil?
if HOMEBREW_TAP_FORMULA_REGEX === f if f =~ HOMEBREW_TAP_FORMULA_REGEX
TapDependency.new(f, tags, method(:modify_build_environment), name) TapDependency.new(f, tags, method(:modify_build_environment), name)
else else
Dependency.new(f, tags, method(:modify_build_environment), name) Dependency.new(f, tags, method(:modify_build_environment), name)

View File

@ -22,7 +22,7 @@ class XcodeRequirement < Requirement
satisfy(build_env: false) { xcode_installed_version } satisfy(build_env: false) { xcode_installed_version }
def initialize(tags) def initialize(tags)
@version = tags.find { |t| tags.delete(t) if /(\d\.)+\d/ === t } @version = tags.find { |tag| tags.delete(tag) if tag =~ /(\d\.)+\d/ }
super super
end end

View File

@ -116,12 +116,12 @@ class SoftwareSpec
def option(name, description = "") def option(name, description = "")
opt = PREDEFINED_OPTIONS.fetch(name) do opt = PREDEFINED_OPTIONS.fetch(name) do
if Symbol === name if name.is_a?(Symbol)
opoo "Passing arbitrary symbols to `option` is deprecated: #{name.inspect}" opoo "Passing arbitrary symbols to `option` is deprecated: #{name.inspect}"
puts "Symbols are reserved for future use, please pass a string instead" puts "Symbols are reserved for future use, please pass a string instead"
name = name.to_s name = name.to_s
end end
unless String === name unless name.is_a?(String)
raise ArgumentError, "option name must be string or symbol; got a #{name.class}: #{name}" raise ArgumentError, "option name must be string or symbol; got a #{name.class}: #{name}"
end end
raise ArgumentError, "option name is required" if name.empty? raise ArgumentError, "option name is required" if name.empty?

View File

@ -208,7 +208,7 @@ class Version
end end
def <=>(other) def <=>(other)
return unless Version === other return unless other.is_a?(Version)
return 0 if version == other.version return 0 if version == other.version
return 1 if head? && !other.head? return 1 if head? && !other.head?
return -1 if !head? && other.head? return -1 if !head? && other.head?