Skip to content

Commit

Permalink
Merge pull request Homebrew#1362 from reitermarkus/rubocop
Browse files Browse the repository at this point in the history
Update RuboCop to 0.45.0.
  • Loading branch information
reitermarkus committed Nov 14, 2016
2 parents ee14348 + 6c1d423 commit 3a01fba
Show file tree
Hide file tree
Showing 22 changed files with 116 additions and 194 deletions.
6 changes: 6 additions & 0 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ AllCops:
Metrics/AbcSize:
Enabled: false

Metrics/BlockLength:
Enabled: false

Metrics/ClassLength:
Enabled: false

Expand Down Expand Up @@ -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
Expand Down
86 changes: 4 additions & 82 deletions Library/Homebrew/.rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -66,7 +66,7 @@ Metrics/BlockNesting:
# Offense count: 19
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 400
Max: 367

# Offense count: 2
# Configuration parameters: CountKeywordArgs.
Expand All @@ -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.
Expand All @@ -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
Expand Down
15 changes: 8 additions & 7 deletions Library/Homebrew/cask/lib/hbc/cli/search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/lib/hbc/cli/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 12 additions & 13 deletions Library/Homebrew/cask/lib/hbc/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 8 additions & 8 deletions Library/Homebrew/cask/lib/hbc/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,17 +137,17 @@ 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)
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
Expand Down
7 changes: 3 additions & 4 deletions Library/Homebrew/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
16 changes: 9 additions & 7 deletions Library/Homebrew/cmd/gist-logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 3 additions & 6 deletions Library/Homebrew/cmd/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/compilers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 22 additions & 23 deletions Library/Homebrew/descriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/boneyard-formula-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading

0 comments on commit 3a01fba

Please sign in to comment.