Merge pull request #1362 from reitermarkus/rubocop

Update RuboCop to 0.45.0.
This commit is contained in:
Markus Reiter 2016-11-14 16:50:24 +01:00 committed by GitHub
commit 3a01fbadcd
22 changed files with 116 additions and 194 deletions

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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)

View File

@ -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"

View File

@ -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

View File

@ -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