From 84b2276fd866342cd84c6ada8ffc13c5c209c3cf Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 24 Oct 2016 17:07:57 +0200 Subject: [PATCH 1/6] Use guard clauses. --- Library/Homebrew/cask/lib/hbc/cli/search.rb | 15 +++---- Library/Homebrew/cask/lib/hbc/installer.rb | 25 ++++++------ Library/Homebrew/cask/lib/hbc/utils.rb | 14 +++---- Library/Homebrew/cleanup.rb | 7 ++-- Library/Homebrew/descriptions.rb | 45 ++++++++++----------- Library/Homebrew/extend/ENV/std.rb | 5 +-- Library/Homebrew/sandbox.rb | 7 ++-- 7 files changed, 57 insertions(+), 61 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cli/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 8e8f8fd7507b1..3f73fcd2e1c27 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -41,14 +41,15 @@ def self.render_results(exact_match, partial_matches, search_term) ohai "Exact match" puts exact_match end - unless partial_matches.empty? - if extract_regexp search_term - ohai "Regexp matches" - else - ohai "Partial matches" - end - puts Formatter.columns(partial_matches) + + return if partial_matches.empty? + + if extract_regexp search_term + ohai "Regexp matches" + else + ohai "Partial matches" end + puts Formatter.columns(partial_matches) end def self.help diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 183d1f14bae60..57efe97e959ea 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -28,22 +28,21 @@ def initialize(cask, command: SystemCommand, force: false, skip_cask_deps: false def self.print_caveats(cask) odebug "Printing caveats" - unless cask.caveats.empty? - output = capture_output do - cask.caveats.each do |caveat| - if caveat.respond_to?(:eval_and_print) - caveat.eval_and_print(cask) - else - puts caveat - end + return if cask.caveats.empty? + + output = capture_output do + cask.caveats.each do |caveat| + if caveat.respond_to?(:eval_and_print) + caveat.eval_and_print(cask) + else + puts caveat end end - - unless output.empty? - ohai "Caveats" - puts output - end end + + return if output.empty? + ohai "Caveats" + puts output end def self.capture_output(&block) diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index b442efd2f2d75..88b8a88c4bae0 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -137,13 +137,13 @@ def self.method_missing_message(method, token, section = nil) def self.nowstamp_metadata_path(container_path) @timenow ||= Time.now.gmtime - if container_path.respond_to?(:join) - precision = 3 - timestamp = @timenow.strftime("%Y%m%d%H%M%S") - fraction = format("%.#{precision}f", @timenow.to_f - @timenow.to_i)[1..-1] - timestamp.concat(fraction) - container_path.join(timestamp) - end + return unless container_path.respond_to?(:join) + + precision = 3 + timestamp = @timenow.strftime("%Y%m%d%H%M%S") + fraction = format("%.#{precision}f", @timenow.to_f - @timenow.to_i)[1..-1] + timestamp.concat(fraction) + container_path.join(timestamp) end def self.size_in_bytes(files) diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index f7db1c11f7ef4..615a7ce9e7232 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -10,10 +10,9 @@ def self.cleanup cleanup_cellar cleanup_cache cleanup_logs - unless ARGV.dry_run? - cleanup_lockfiles - rm_ds_store - end + return if ARGV.dry_run? + cleanup_lockfiles + rm_ds_store end def self.update_disk_cleanup_size(path_size) diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb index cc690c050e8cd..08860f7cf59b6 100644 --- a/Library/Homebrew/descriptions.rb +++ b/Library/Homebrew/descriptions.rb @@ -57,42 +57,41 @@ def self.ensure_cache # If it does exist, but the Report is empty, just touch the cache file. # Otherwise, use the report to update the cache. def self.update_cache(report) - if CACHE_FILE.exist? - if report.empty? - FileUtils.touch CACHE_FILE - else - renamings = report.select_formula(:R) - alterations = report.select_formula(:A) + report.select_formula(:M) + - renamings.map(&:last) - cache_formulae(alterations, save: false) - uncache_formulae(report.select_formula(:D) + - renamings.map(&:first)) - end + return unless CACHE_FILE.exist? + + if report.empty? + FileUtils.touch CACHE_FILE + else + renamings = report.select_formula(:R) + alterations = report.select_formula(:A) + report.select_formula(:M) + + renamings.map(&:last) + cache_formulae(alterations, save: false) + uncache_formulae(report.select_formula(:D) + + renamings.map(&:first)) end end # Given an array of formula names, add them and their descriptions to the # cache. Save the updated cache to disk, unless explicitly told not to. def self.cache_formulae(formula_names, options = { save: true }) - if cache - formula_names.each do |name| - begin - desc = Formulary.factory(name).desc - rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS - end - @cache[name] = desc + return unless cache + + formula_names.each do |name| + begin + desc = Formulary.factory(name).desc + rescue FormulaUnavailableError, *FormulaVersions::IGNORED_EXCEPTIONS end - save_cache if options[:save] + @cache[name] = desc end + save_cache if options[:save] end # Given an array of formula names, remove them and their descriptions from # the cache. Save the updated cache to disk, unless explicitly told not to. def self.uncache_formulae(formula_names, options = { save: true }) - if cache - formula_names.each { |name| @cache.delete(name) } - save_cache if options[:save] - end + return unless cache + formula_names.each { |name| @cache.delete(name) } + save_cache if options[:save] end # Given a regex, find all formulae whose specified fields contain a match. diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index 27dc95d29738d..14f9b81b8ef57 100644 --- a/Library/Homebrew/extend/ENV/std.rb +++ b/Library/Homebrew/extend/ENV/std.rb @@ -11,9 +11,8 @@ module Stdenv DEFAULT_FLAGS = "-march=core2 -msse4".freeze def self.extended(base) - unless ORIGINAL_PATHS.include? HOMEBREW_PREFIX/"bin" - base.prepend_path "PATH", "#{HOMEBREW_PREFIX}/bin" - end + return if ORIGINAL_PATHS.include? HOMEBREW_PREFIX/"bin" + base.prepend_path "PATH", "#{HOMEBREW_PREFIX}/bin" end # @private diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb index 4d0709cb4b286..9597dafa8142e 100644 --- a/Library/Homebrew/sandbox.rb +++ b/Library/Homebrew/sandbox.rb @@ -27,10 +27,9 @@ def self.test? end def self.print_sandbox_message - unless @printed_sandbox_message - ohai "Using the sandbox" - @printed_sandbox_message = true - end + return if @printed_sandbox_message + ohai "Using the sandbox" + @printed_sandbox_message = true end def initialize From e9391481a8fa6037e9fe70a3050a5a2226e3954e Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 24 Oct 2016 17:15:25 +0200 Subject: [PATCH 2/6] Update RuboCop to 0.45.0. --- Library/.rubocop.yml | 3 + Library/Homebrew/.rubocop_todo.yml | 86 +--------------------- Library/Homebrew/cask/lib/hbc/cli/style.rb | 2 +- Library/Homebrew/cmd/style.rb | 2 +- 4 files changed, 9 insertions(+), 84 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index c77d55f671b5d..2aba282c4511f 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -6,6 +6,9 @@ AllCops: Metrics/AbcSize: Enabled: false +Metrics/BlockLength: + Enabled: false + Metrics/ClassLength: Enabled: false diff --git a/Library/Homebrew/.rubocop_todo.yml b/Library/Homebrew/.rubocop_todo.yml index 6a31cdecd1955..867a61966f8aa 100644 --- a/Library/Homebrew/.rubocop_todo.yml +++ b/Library/Homebrew/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 100` -# on 2016-09-28 22:26:33 +0200 using RuboCop version 0.43.0. +# on 2016-10-24 17:14:14 +0200 using RuboCop version 0.44.1. # 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 @@ -66,7 +66,7 @@ Metrics/BlockNesting: # Offense count: 19 # Configuration parameters: CountComments. Metrics/ModuleLength: - Max: 400 + Max: 367 # Offense count: 2 # Configuration parameters: CountKeywordArgs. @@ -85,89 +85,12 @@ Style/BarePercentLiterals: - 'test/test_patch.rb' - 'test/test_string.rb' -# Offense count: 134 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods. -# SupportedStyles: line_count_based, semantic, braces_for_chaining -# ProceduralMethods: benchmark, bm, bmbm, create, each_with_object, measure, new, realtime, tap, with_object -# FunctionalMethods: let, let!, subject, watch -# IgnoredMethods: lambda, proc, it -Style/BlockDelimiters: - Exclude: - - 'caveats.rb' - - 'cleaner.rb' - - 'cleanup.rb' - - 'cmd/deps.rb' - - 'cmd/desc.rb' - - 'cmd/fetch.rb' - - 'cmd/help.rb' - - 'cmd/info.rb' - - 'cmd/linkapps.rb' - - 'cmd/list.rb' - - 'cmd/outdated.rb' - - 'cmd/reinstall.rb' - - 'cmd/search.rb' - - 'cmd/tap-info.rb' - - 'cmd/unlinkapps.rb' - - 'cmd/update-report.rb' - - 'cmd/upgrade.rb' - - 'cmd/uses.rb' - - 'compilers.rb' - - 'debrew.rb' - - 'descriptions.rb' - - 'dev-cmd/aspell-dictionaries.rb' - - 'dev-cmd/audit.rb' - - 'dev-cmd/bottle.rb' - - 'dev-cmd/edit.rb' - - 'dev-cmd/man.rb' - - 'diagnostic.rb' - - 'exceptions.rb' - - 'extend/ARGV.rb' - - 'extend/ENV/shared.rb' - - 'extend/ENV/std.rb' - - 'extend/fileutils.rb' - - 'extend/os/mac/formula_cellar_checks.rb' - - 'extend/pathname.rb' - - 'formula.rb' - - 'formula_assertions.rb' - - 'formula_cellar_checks.rb' - - 'formula_installer.rb' - - 'formulary.rb' - - 'global.rb' - - 'keg.rb' - - 'language/haskell.rb' - - 'language/node.rb' - - 'language/python.rb' - - 'migrator.rb' - - 'os/mac/linkage_checker.rb' - - 'os/mac/xquartz.rb' - - 'patch.rb' - - 'readall.rb' - - 'software_spec.rb' - - 'tap.rb' - - 'test/lib/config.rb' - - 'test/test_ARGV.rb' - - 'test/test_cleanup.rb' - - 'test/test_dependency_collector.rb' - - 'test/test_formula_installer.rb' - - 'test/test_formula_installer_bottle.rb' - - 'test/test_formulary.rb' - - 'test/test_gpg.rb' - - 'test/test_migrator.rb' - - 'test/test_pathname.rb' - - 'test/test_tap.rb' - - 'test/test_utils.rb' - - 'test/testing_env.rb' - - 'utils.rb' - - 'utils/github.rb' - -# Offense count: 7 +# Offense count: 6 Style/ClassVars: Exclude: - 'dev-cmd/audit.rb' - 'formula_installer.rb' - 'test/testing_env.rb' - - 'utils.rb' # Offense count: 13 # Configuration parameters: AllowedVariables. @@ -176,12 +99,11 @@ Style/GlobalVars: - 'diagnostic.rb' - 'utils.rb' -# Offense count: 2 +# Offense count: 1 # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: module_function, extend_self Style/ModuleFunction: Exclude: - - 'global.rb' - 'os/mac/xcode.rb' # Offense count: 8 diff --git a/Library/Homebrew/cask/lib/hbc/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb index 01ba394119f63..e036770abcf91 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/style.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb @@ -23,7 +23,7 @@ def run $CHILD_STATUS.success? end - RUBOCOP_CASK_VERSION = "~> 0.10.4".freeze + RUBOCOP_CASK_VERSION = "~> 0.10.5".freeze def install_rubocop Utils.capture_stderr do diff --git a/Library/Homebrew/cmd/style.rb b/Library/Homebrew/cmd/style.rb index 08eb111a50f82..8b6793e778bab 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -47,7 +47,7 @@ def check_style_json(files, options = {}) def check_style_impl(files, output_type, options = {}) fix = options[:fix] - Homebrew.install_gem_setup_path! "rubocop", "0.43.0" + Homebrew.install_gem_setup_path! "rubocop", "0.45.0" args = %w[ --force-exclusion From c648518f35611b16dfdd1355b2c8498d7f6d54d7 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 13 Nov 2016 23:36:04 +0100 Subject: [PATCH 3/6] Rename single line block parameters to `acc/elem`. --- Library/.rubocop.yml | 3 +++ Library/Homebrew/cask/lib/hbc/utils.rb | 2 +- Library/Homebrew/dev-cmd/boneyard-formula-pr.rb | 2 +- Library/Homebrew/diagnostic.rb | 2 +- 4 files changed, 6 insertions(+), 3 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 2aba282c4511f..be2fb4a67ae40 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -139,6 +139,9 @@ Style/RegexpLiteral: Style/SpaceAroundOperators: Enabled: false +Style/SingleLineBlockParams: + Enabled: false + # not a problem for typical shell users Style/SpecialGlobalVars: Enabled: false diff --git a/Library/Homebrew/cask/lib/hbc/utils.rb b/Library/Homebrew/cask/lib/hbc/utils.rb index 88b8a88c4bae0..ef3e5eda37179 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -147,7 +147,7 @@ def self.nowstamp_metadata_path(container_path) end def self.size_in_bytes(files) - Array(files).reduce(0) { |a, e| a + (File.size?(e) || 0) } + Array(files).reduce(0) { |acc, elem| acc + (File.size?(elem) || 0) } end def self.capture_stderr diff --git a/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb b/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb index 487f0c9dbeeb2..3d95f14b9f30d 100644 --- a/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb @@ -62,7 +62,7 @@ def boneyard_formula_pr end tap_migrations = Utils::JSON.load(File.read(tap_migrations_path)) tap_migrations[formula.name] = boneyard_tap.name - tap_migrations = tap_migrations.sort.inject({}) { |a, e| a.merge!(e[0] => e[1]) } + tap_migrations = tap_migrations.sort.inject({}) { |acc, elem| acc.merge!(elem[0] => elem[1]) } tap_migrations_path.atomic_write(JSON.pretty_generate(tap_migrations) + "\n") end unless which("hub") || local_only diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 0b32f64c7c12a..19148a6ae227c 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -69,7 +69,7 @@ def find_relative_paths(*relative_paths) end def inject_file_list(list, string) - list.inject(string) { |a, e| a << " #{e}\n" } + list.inject(string) { |acc, elem| acc << " #{elem}\n" } end ############# END HELPERS From 59e2d6772158d8df0735708ae78ddec6ccc68026 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 13 Nov 2016 23:37:40 +0100 Subject: [PATCH 4/6] No if/unless-modifier on multiline blocks. --- Library/Homebrew/cmd/gist-logs.rb | 16 ++++++++------ Library/Homebrew/extend/ENV/shared.rb | 3 ++- Library/Homebrew/extend/enumerable.rb | 18 +++++++++------- Library/Homebrew/extend/pathname.rb | 30 +++++++++++++++----------- Library/Homebrew/formula_installer.rb | 8 ++++--- Library/Homebrew/test/test_hardware.rb | 10 +++++---- 6 files changed, 50 insertions(+), 35 deletions(-) diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index 5cacd50b65617..fecdc25a05392 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -94,13 +94,15 @@ def login! def load_logs(dir) logs = {} - dir.children.sort.each do |file| - contents = file.size? ? file.read : "empty log" - # small enough to avoid GitHub "unicorn" page-load-timeout errors - max_file_size = 1_000_000 - contents = truncate_text_to_approximate_size(contents, max_file_size, front_weight: 0.2) - logs[file.basename.to_s] = { content: contents } - end if dir.exist? + if dir.exist? + dir.children.sort.each do |file| + contents = file.size? ? file.read : "empty log" + # small enough to avoid GitHub "unicorn" page-load-timeout errors + max_file_size = 1_000_000 + contents = truncate_text_to_approximate_size(contents, max_file_size, front_weight: 0.2) + logs[file.basename.to_s] = { content: contents } + end + end raise "No logs." if logs.empty? logs end diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index 909dc4f941412..a93c1ee1f660b 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -98,11 +98,12 @@ def prepend_create_path(key, path) end def remove(keys, value) + return if value.nil? Array(keys).each do |key| next unless self[key] self[key] = self[key].sub(value, "") delete(key) if self[key].empty? - end if value + end end def cc diff --git a/Library/Homebrew/extend/enumerable.rb b/Library/Homebrew/extend/enumerable.rb index fededbfcac1a1..65be7dc068ce1 100644 --- a/Library/Homebrew/extend/enumerable.rb +++ b/Library/Homebrew/extend/enumerable.rb @@ -1,11 +1,13 @@ module Enumerable - def flat_map - return to_enum(:flat_map) unless block_given? - r = [] - each do |*args| - result = yield(*args) - result.respond_to?(:to_ary) ? r.concat(result) : r.push(result) + unless method_defined?(:flat_map) + def flat_map + return to_enum(:flat_map) unless block_given? + r = [] + each do |*args| + result = yield(*args) + result.respond_to?(:to_ary) ? r.concat(result) : r.push(result) + end + r end - r - end unless method_defined?(:flat_map) + end end diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 3f73b6a1c7563..976ea7dd832d7 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -148,13 +148,17 @@ def append_lines(content, *open_args) open("a", *open_args) { |f| f.puts(content) } end - def binwrite(contents, *open_args) - open("wb", *open_args) { |f| f.write(contents) } - end unless method_defined?(:binwrite) + unless method_defined?(:binwrite) + def binwrite(contents, *open_args) + open("wb", *open_args) { |f| f.write(contents) } + end + end - def binread(*open_args) - open("rb", *open_args, &:read) - end unless method_defined?(:binread) + unless method_defined?(:binread) + def binread(*open_args) + open("rb", *open_args, &:read) + end + end # NOTE always overwrites def atomic_write(content) @@ -353,13 +357,15 @@ def make_relative_symlink(src) File.symlink(src.relative_path_from(dirname), self) end - def /(other) - unless other.respond_to?(:to_str) || other.respond_to?(:to_path) - opoo "Pathname#/ called on #{inspect} with #{other.inspect} as an argument" - puts "This behavior is deprecated, please pass either a String or a Pathname" + unless method_defined?(:/) + def /(other) + unless other.respond_to?(:to_str) || other.respond_to?(:to_path) + opoo "Pathname#/ called on #{inspect} with #{other.inspect} as an argument" + puts "This behavior is deprecated, please pass either a String or a Pathname" + end + self + other.to_s end - self + other.to_s - end unless method_defined?(:/) + end # @private def ensure_writable diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index f99f2f4ec4e08..c05b0da605e17 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -814,9 +814,11 @@ def hold_locks? def lock return unless (@@locked ||= []).empty? - formula.recursive_dependencies.each do |dep| - @@locked << dep.to_formula - end unless ignore_deps? + unless ignore_deps? + formula.recursive_dependencies.each do |dep| + @@locked << dep.to_formula + end + end @@locked.unshift(formula) @@locked.uniq! @@locked.each(&:lock) diff --git a/Library/Homebrew/test/test_hardware.rb b/Library/Homebrew/test/test_hardware.rb index 56d0980fa6c03..2bea5387d5212 100644 --- a/Library/Homebrew/test/test_hardware.rb +++ b/Library/Homebrew/test/test_hardware.rb @@ -6,8 +6,10 @@ def test_hardware_cpu_type assert_includes [:intel, :ppc, :dunno], Hardware::CPU.type end - def test_hardware_intel_family - families = [:core, :core2, :penryn, :nehalem, :arrandale, :sandybridge, :ivybridge, :haswell, :broadwell, :skylake, :dunno] - assert_includes families, Hardware::CPU.family - end if Hardware::CPU.intel? + if Hardware::CPU.intel? + def test_hardware_intel_family + families = [:core, :core2, :penryn, :nehalem, :arrandale, :sandybridge, :ivybridge, :haswell, :broadwell, :skylake, :dunno] + assert_includes families, Hardware::CPU.family + end + end end From 353b67a6b2bc5932a780e328291cb42e7e868dce Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 13 Nov 2016 23:37:51 +0100 Subject: [PATCH 5/6] No empty `when`s. --- Library/Homebrew/cmd/list.rb | 9 +++------ Library/Homebrew/compilers.rb | 2 +- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 3496580f48f59..7bbcb47999d2a 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -146,7 +146,7 @@ def initialize(path) (pnn.extname == ".dylib" || pnn.extname == ".pc") && !pnn.symlink? end when ".brew" - # Ignore .brew + next # Ignore .brew else if pn.directory? if pn.symlink? @@ -187,12 +187,9 @@ def print_dir(root) end def print_remaining_files(files, root, other = "") - case files.length - when 0 - # noop - when 1 + if files.length == 1 puts files - else + elsif files.length > 1 puts "#{root}/ (#{files.length} #{other}files)" end end diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb index 7503f1d77e737..6c3971984c269 100644 --- a/Library/Homebrew/compilers.rb +++ b/Library/Homebrew/compilers.rb @@ -118,7 +118,7 @@ def find_compiler yield Compiler.new(name, version) if version end when :llvm - # no-op. DSL supported, compiler is not. + next # no-op. DSL supported, compiler is not. else version = compiler_version(compiler) yield Compiler.new(compiler, version) if version From 6c1d42386df7994607f4b6096dd75323ff9bbb3a Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Sun, 13 Nov 2016 23:41:23 +0100 Subject: [PATCH 6/6] Remove `flat_map` compatibility layer. --- Library/Homebrew/extend/enumerable.rb | 13 ------------- Library/Homebrew/global.rb | 1 - 2 files changed, 14 deletions(-) delete mode 100644 Library/Homebrew/extend/enumerable.rb diff --git a/Library/Homebrew/extend/enumerable.rb b/Library/Homebrew/extend/enumerable.rb deleted file mode 100644 index 65be7dc068ce1..0000000000000 --- a/Library/Homebrew/extend/enumerable.rb +++ /dev/null @@ -1,13 +0,0 @@ -module Enumerable - unless method_defined?(:flat_map) - def flat_map - return to_enum(:flat_map) unless block_given? - r = [] - each do |*args| - result = yield(*args) - result.respond_to?(:to_ary) ? r.concat(result) : r.push(result) - end - r - end - end -end diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index bf700b095327b..eabc4c164c5b1 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -4,7 +4,6 @@ require "extend/git_repository" require "extend/ARGV" require "extend/string" -require "extend/enumerable" require "os" require "utils" require "exceptions"