diff options
| author | Markus Reiter | 2016-11-14 16:50:24 +0100 |
|---|---|---|
| committer | GitHub | 2016-11-14 16:50:24 +0100 |
| commit | 3a01fbadcd14fb180635d6464f2c600a738d50b5 (patch) | |
| tree | e84414014d51503cf8dfa47e46ffec9fe26158ca /Library | |
| parent | ee143482e4323be29a60ee2965835a54eac2ace8 (diff) | |
| parent | 6c1d42386df7994607f4b6096dd75323ff9bbb3a (diff) | |
| download | brew-3a01fbadcd14fb180635d6464f2c600a738d50b5.tar.bz2 | |
Merge pull request #1362 from reitermarkus/rubocop
Update RuboCop to 0.45.0.
Diffstat (limited to 'Library')
22 files changed, 116 insertions, 194 deletions
diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index c77d55f67..be2fb4a67 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 @@ -136,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/.rubocop_todo.yml b/Library/Homebrew/.rubocop_todo.yml index 6a31cdecd..867a61966 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/search.rb b/Library/Homebrew/cask/lib/hbc/cli/search.rb index 8e8f8fd75..3f73fcd2e 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/search.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/search.rb @@ -41,14 +41,15 @@ module Hbc 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/cli/style.rb b/Library/Homebrew/cask/lib/hbc/cli/style.rb index 01ba39411..e036770ab 100644 --- a/Library/Homebrew/cask/lib/hbc/cli/style.rb +++ b/Library/Homebrew/cask/lib/hbc/cli/style.rb @@ -23,7 +23,7 @@ module Hbc $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/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index 183d1f14b..57efe97e9 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -28,22 +28,21 @@ module Hbc 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 b442efd2f..ef3e5eda3 100644 --- a/Library/Homebrew/cask/lib/hbc/utils.rb +++ b/Library/Homebrew/cask/lib/hbc/utils.rb @@ -137,17 +137,17 @@ module Hbc 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) - 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/cleanup.rb b/Library/Homebrew/cleanup.rb index f7db1c11f..615a7ce9e 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -10,10 +10,9 @@ module Homebrew 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/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index 5cacd50b6..fecdc25a0 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -94,13 +94,15 @@ module Homebrew 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/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 3496580f4..7bbcb4799 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -146,7 +146,7 @@ class PrettyListing (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 @@ class PrettyListing 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/cmd/style.rb b/Library/Homebrew/cmd/style.rb index 08eb111a5..8b6793e77 100644 --- a/Library/Homebrew/cmd/style.rb +++ b/Library/Homebrew/cmd/style.rb @@ -47,7 +47,7 @@ module Homebrew 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 diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb index 7503f1d77..6c3971984 100644 --- a/Library/Homebrew/compilers.rb +++ b/Library/Homebrew/compilers.rb @@ -118,7 +118,7 @@ class CompilerSelector 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 diff --git a/Library/Homebrew/descriptions.rb b/Library/Homebrew/descriptions.rb index cc690c050..08860f7cf 100644 --- a/Library/Homebrew/descriptions.rb +++ b/Library/Homebrew/descriptions.rb @@ -57,42 +57,41 @@ class Descriptions # 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/dev-cmd/boneyard-formula-pr.rb b/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb index 487f0c9db..3d95f14b9 100644 --- a/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/boneyard-formula-pr.rb @@ -62,7 +62,7 @@ module Homebrew 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 0b32f64c7..19148a6ae 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -69,7 +69,7 @@ module Homebrew 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 diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index 909dc4f94..a93c1ee1f 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -98,11 +98,12 @@ module SharedEnvExtension 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/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb index 27dc95d29..14f9b81b8 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/extend/enumerable.rb b/Library/Homebrew/extend/enumerable.rb deleted file mode 100644 index fededbfca..000000000 --- a/Library/Homebrew/extend/enumerable.rb +++ /dev/null @@ -1,11 +0,0 @@ -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) - end - r - end unless method_defined?(:flat_map) -end diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 3f73b6a1c..976ea7dd8 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -148,13 +148,17 @@ class Pathname 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 @@ class Pathname 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 f99f2f4ec..c05b0da60 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -814,9 +814,11 @@ class FormulaInstaller 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/global.rb b/Library/Homebrew/global.rb index bf700b095..eabc4c164 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -4,7 +4,6 @@ require "extend/pathname" require "extend/git_repository" require "extend/ARGV" require "extend/string" -require "extend/enumerable" require "os" require "utils" require "exceptions" diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb index 4d0709cb4..9597dafa8 100644 --- a/Library/Homebrew/sandbox.rb +++ b/Library/Homebrew/sandbox.rb @@ -27,10 +27,9 @@ class Sandbox 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 diff --git a/Library/Homebrew/test/test_hardware.rb b/Library/Homebrew/test/test_hardware.rb index 56d0980fa..2bea5387d 100644 --- a/Library/Homebrew/test/test_hardware.rb +++ b/Library/Homebrew/test/test_hardware.rb @@ -6,8 +6,10 @@ class HardwareTests < Homebrew::TestCase 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 |
