diff --git a/Library/.rubocop_todo.yml b/Library/.rubocop_todo.yml index a898d2f799..4be619071c 100644 --- a/Library/.rubocop_todo.yml +++ b/Library/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by -# `rubocop --auto-gen-config --exclude-limit 30` -# on 2016-09-18 15:15:22 +0100 using RuboCop version 0.41.2. +# `rubocop --auto-gen-config --exclude-limit 100` +# 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 # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -80,12 +80,7 @@ Lint/RescueException: # Offense count: 1 Lint/ShadowedException: Exclude: - - 'Homebrew/brew.rb' - -# Offense count: 2 -Lint/UselessAssignment: - Exclude: - - 'Homebrew/requirements.rb' + - 'Homebrew/utils/fork.rb' # Offense count: 18 Metrics/BlockNesting: @@ -94,9 +89,9 @@ Metrics/BlockNesting: # Offense count: 20 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 400 + Max: 373 -# Offense count: 1 +# Offense count: 2 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: Max: 6 @@ -125,25 +120,10 @@ Style/Alias: Exclude: - 'Homebrew/blacklist.rb' -# Offense count: 26 +# Offense count: 1 Style/CaseEquality: Exclude: - - 'Homebrew/cleanup.rb' - - 'Homebrew/cmd/search.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 # Cop supports --auto-correct. @@ -193,11 +173,103 @@ Style/GlobalVars: - 'Homebrew/diagnostic.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 Style/IdenticalConditionalBranches: Exclude: - '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 # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: snake_case, camelCase @@ -249,6 +321,11 @@ Style/Next: Exclude: - 'Homebrew/dev-cmd/test-bot.rb' +# Offense count: 1 +# Cop supports --auto-correct. +Style/NumericLiterals: + MinDigits: 6 + # Offense count: 9 Style/OpMethod: Exclude: @@ -291,3 +368,18 @@ Style/Semicolon: Style/SingleLineBlockParams: Exclude: - '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' diff --git a/Library/Homebrew/cask/.rubocop.yml b/Library/Homebrew/cask/.rubocop.yml index cc505c812b..1f473e07b8 100644 --- a/Library/Homebrew/cask/.rubocop.yml +++ b/Library/Homebrew/cask/.rubocop.yml @@ -1,6 +1,7 @@ AllCops: TargetRubyVersion: 2.0 Exclude: + - '**/.simplecov' - '**/Casks/**/*' - '**/vendor/**/*' diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 265f06d26a..42be339a0e 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -66,7 +66,7 @@ module Homebrew next unless path.file? file = path - if Pathname::BOTTLE_EXTNAME_RX === file.to_s + if file.to_s =~ Pathname::BOTTLE_EXTNAME_RX version = begin Utils::Bottles.resolve_version(file) rescue @@ -86,7 +86,7 @@ module Homebrew next end - file_is_stale = if PkgVersion === version + file_is_stale = if version.is_a?(PkgVersion) f.pkg_version > version else f.version > version diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 50d9f5f744..3f00e8a104 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -150,7 +150,7 @@ module Homebrew names = remote_tap_formulae["#{user}/#{repo}"] 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 opoo "Failed to search tap: #{user}/#{repo}. Please run `brew update`" [] diff --git a/Library/Homebrew/cxxstdlib.rb b/Library/Homebrew/cxxstdlib.rb index 1f629a8b28..ad859badd3 100644 --- a/Library/Homebrew/cxxstdlib.rb +++ b/Library/Homebrew/cxxstdlib.rb @@ -16,7 +16,7 @@ class CxxStdlib if type && ![:libstdcxx, :libcxx].include?(type) raise ArgumentError, "Invalid C++ stdlib type: #{type}" end - klass = GNU_GCC_REGEXP === compiler.to_s ? GnuStdlib : AppleStdlib + klass = compiler.to_s =~ GNU_GCC_REGEXP ? GnuStdlib : AppleStdlib klass.new(type, compiler) end diff --git a/Library/Homebrew/debrew.rb b/Library/Homebrew/debrew.rb index 48d449f4a2..8e371e4e79 100644 --- a/Library/Homebrew/debrew.rb +++ b/Library/Homebrew/debrew.rb @@ -118,20 +118,22 @@ module Debrew menu.prompt = "Choose an action: " 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(:irb) do - puts "When you exit this IRB session, execution will continue." - set_trace_func proc { |event, _, _, id, binding, klass| - if klass == Raise && id == :raise && event == "return" - set_trace_func(nil) - synchronize { IRB.start_within(binding) } - end - } + if e.is_a?(Ignorable) + menu.choice(:irb) do + puts "When you exit this IRB session, execution will continue." + set_trace_func proc { |event, _, _, id, binding, klass| + if klass == Raise && id == :raise && event == "return" + set_trace_func(nil) + synchronize { IRB.start_within(binding) } + end + } - return :ignore - end if Ignorable === e + return :ignore + end + end menu.choice(:shell) do puts "When you exit this shell, you will return to the menu." diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb index b55d35c2eb..51e5521029 100644 --- a/Library/Homebrew/dependencies.rb +++ b/Library/Homebrew/dependencies.rb @@ -69,7 +69,7 @@ class Requirements end def <<(other) - if Comparable === other + if other.is_a?(Comparable) @reqs.grep(other.class) do |req| return self if req > other @reqs.delete(req) diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index ef3a712e96..99aa2db9a8 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -49,7 +49,7 @@ class DependencyCollector end def cache_key(spec) - if Resource === spec && spec.download_strategy == CurlDownloadStrategy + if spec.is_a?(Resource) && spec.download_strategy == CurlDownloadStrategy File.extname(spec.url) else spec @@ -57,7 +57,7 @@ class DependencyCollector end def build(spec) - spec, tags = Hash === spec ? spec.first : spec + spec, tags = spec.is_a?(Hash) ? spec.first : spec parse_spec(spec, Array(tags)) end @@ -81,7 +81,7 @@ class DependencyCollector end def parse_string_spec(spec, tags) - if HOMEBREW_TAP_FORMULA_REGEX === spec + if spec =~ HOMEBREW_TAP_FORMULA_REGEX TapDependency.new(spec, tags) elsif tags.empty? Dependency.new(spec, tags) diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index cabb22c228..048153c16c 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -668,7 +668,7 @@ class GitDownloadStrategy < VCSDownloadStrategy end def support_depth? - @ref_type != :revision && SHALLOW_CLONE_WHITELIST.any? { |rx| rx === @url } + @ref_type != :revision && SHALLOW_CLONE_WHITELIST.any? { |regex| @url =~ regex } end def git_dir @@ -1021,9 +1021,9 @@ class DownloadStrategyDetector def self.detect(url, strategy = nil) if strategy.nil? detect_from_url(url) - elsif Class === strategy && strategy < AbstractDownloadStrategy + elsif strategy.is_a?(Class) && strategy < AbstractDownloadStrategy strategy - elsif Symbol === strategy + elsif strategy.is_a?(Symbol) detect_from_symbol(strategy) else raise TypeError, diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 4b3ef33f27..cd1890a43d 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -1052,7 +1052,7 @@ class Formula self.class.link_overwrite_paths.any? do |p| p == to_check || to_check.start_with?(p.chomp("/") + "/") || - /^#{Regexp.escape(p).gsub('\*', ".*?")}$/ === to_check + to_check =~ /^#{Regexp.escape(p).gsub('\*', ".*?")}$/ end end @@ -1246,7 +1246,7 @@ class Formula # @private def <=>(other) - return unless Formula === other + return unless other.is_a?(Formula) name <=> other.name end @@ -2226,7 +2226,7 @@ class Formula # If this formula conflicts with another one. #
conflicts_with "imagemagick", :because => "because this is just a stupid example"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]) } end diff --git a/Library/Homebrew/options.rb b/Library/Homebrew/options.rb index 1d92fbf47b..947ce5acd5 100644 --- a/Library/Homebrew/options.rb +++ b/Library/Homebrew/options.rb @@ -14,7 +14,7 @@ class Option end def <=>(other) - return unless Option === other + return unless other.is_a?(Option) name <=> other.name end diff --git a/Library/Homebrew/patch.rb b/Library/Homebrew/patch.rb index 1148389cfe..74e58e526d 100644 --- a/Library/Homebrew/patch.rb +++ b/Library/Homebrew/patch.rb @@ -89,7 +89,7 @@ class DATAPatch < EmbeddedPatch path.open("rb") do |f| begin line = f.gets - end until line.nil? || /^__END__$/ === line + end until line.nil? || line =~ /^__END__$/ data << line while line = f.gets end data diff --git a/Library/Homebrew/pkg_version.rb b/Library/Homebrew/pkg_version.rb index 4bf701f357..2868508e39 100644 --- a/Library/Homebrew/pkg_version.rb +++ b/Library/Homebrew/pkg_version.rb @@ -32,7 +32,7 @@ class PkgVersion alias_method :to_str, :to_s def <=>(other) - return unless PkgVersion === other + return unless other.is_a?(PkgVersion) (version <=> other.version).nonzero? || revision <=> other.revision end alias_method :eql?, :== diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index 4ea15774db..7ab3aaeed8 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -83,7 +83,7 @@ class Requirement # PATH. # 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. - if Pathname === @satisfied_result + if @satisfied_result.is_a?(Pathname) parent = @satisfied_result.parent unless ENV["PATH"].split(File::PATH_SEPARATOR).include?(parent.to_s) ENV.append_path("PATH", parent) @@ -115,7 +115,7 @@ class Requirement def to_dependency f = self.class.default_formula 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) else Dependency.new(f, tags, method(:modify_build_environment), name) diff --git a/Library/Homebrew/requirements.rb b/Library/Homebrew/requirements.rb index 3774319eea..274ba5c9b8 100644 --- a/Library/Homebrew/requirements.rb +++ b/Library/Homebrew/requirements.rb @@ -22,7 +22,7 @@ class XcodeRequirement < Requirement satisfy(build_env: false) { xcode_installed_version } 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 end diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 986dc5354d..8e42e20dac 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -116,12 +116,12 @@ class SoftwareSpec def option(name, description = "") opt = PREDEFINED_OPTIONS.fetch(name) do - if Symbol === name + if name.is_a?(Symbol) opoo "Passing arbitrary symbols to `option` is deprecated: #{name.inspect}" puts "Symbols are reserved for future use, please pass a string instead" name = name.to_s end - unless String === name + unless name.is_a?(String) raise ArgumentError, "option name must be string or symbol; got a #{name.class}: #{name}" end raise ArgumentError, "option name is required" if name.empty? diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index 520db66268..b15fc3693a 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -208,7 +208,7 @@ class Version end def <=>(other) - return unless Version === other + return unless other.is_a?(Version) return 0 if version == other.version return 1 if head? && !other.head? return -1 if !head? && other.head?