Fix Style/GuardClause.

This commit is contained in:
Markus Reiter 2016-09-22 20:12:28 +02:00
parent 6d3de5cf60
commit a5b11a6a5c
13 changed files with 150 additions and 175 deletions

View File

@ -1,6 +1,6 @@
# This configuration was generated by
# `rubocop --auto-gen-config --exclude-limit 100`
# on 2016-09-21 14:04:48 +0200 using RuboCop version 0.43.0.
# on 2016-09-22 20:07:41 +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
@ -74,7 +74,7 @@ Metrics/BlockNesting:
# Offense count: 20
# Configuration parameters: CountComments.
Metrics/ModuleLength:
Max: 373
Max: 370
# Offense count: 2
# Configuration parameters: CountKeywordArgs.
@ -119,13 +119,6 @@ Style/ConstantName:
Exclude:
- 'Homebrew/os/mac.rb'
# Offense count: 3
Style/DoubleNegation:
Exclude:
- 'Homebrew/os/mac/cctools_keg.rb'
- 'Homebrew/os/mac/ruby_keg.rb'
- 'Homebrew/os/mac/xcode.rb'
# Offense count: 1
# Configuration parameters: EnforcedStyle, SupportedStyles.
# SupportedStyles: format, sprintf, percent
@ -140,25 +133,14 @@ Style/GlobalVars:
- 'Homebrew/diagnostic.rb'
- 'Homebrew/utils.rb'
# Offense count: 97
# Offense count: 70
# 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'
@ -188,7 +170,7 @@ Style/GuardClause:
- 'Homebrew/utils/popen.rb'
- 'Homebrew/version.rb'
# Offense count: 52
# Offense count: 51
# Cop supports --auto-correct.
# Configuration parameters: MaxLineLength.
Style/IfUnlessModifier:
@ -221,7 +203,6 @@ Style/IfUnlessModifier:
- 'Homebrew/formulary.rb'
- 'Homebrew/language/haskell.rb'
- 'Homebrew/migrator.rb'
- 'Homebrew/os/mac/cctools_mach.rb'
- 'Homebrew/tab.rb'
- 'Homebrew/utils/git.rb'
@ -277,11 +258,3 @@ Style/OpMethod:
# 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'

View File

@ -37,9 +37,9 @@ begin
cmd = nil
ARGV.dup.each_with_index do |arg, i|
if help_flag && cmd
break
elsif help_flag_list.include?(arg)
break if help_flag && cmd
if help_flag_list.include?(arg)
# Option-style help: Both `--help <cmd>` and `<cmd> --help` are fine.
help_flag = true
elsif arg == "help" && !cmd

View File

@ -31,10 +31,9 @@ class Build
def post_superenv_hacks
# Only allow Homebrew-approved directories into the PATH, unless
# a formula opts-in to allowing the user's path.
if formula.env.userpaths? || reqs.any? { |rq| rq.env.userpaths? }
return unless formula.env.userpaths? || reqs.any? { |rq| rq.env.userpaths? }
ENV.userpaths!
end
end
def effective_build_options_for(dependent)
args = dependent.build.used_options

View File

@ -69,28 +69,35 @@ class Caveats
end
def bash_completion_caveats
if keg && keg.completion_installed?(:bash) then <<-EOS.undent
return unless keg
return unless keg.completion_installed?(:bash)
<<-EOS.undent
Bash completion has been installed to:
#{HOMEBREW_PREFIX}/etc/bash_completion.d
EOS
end
end
def zsh_completion_caveats
if keg && keg.completion_installed?(:zsh) then <<-EOS.undent
return unless keg
return unless keg.completion_installed?(:zsh)
<<-EOS.undent
zsh completion has been installed to:
#{HOMEBREW_PREFIX}/share/zsh/site-functions
EOS
end
end
def fish_completion_caveats
if keg && keg.completion_installed?(:fish) && which("fish") then <<-EOS.undent
return unless keg
return unless keg.completion_installed?(:fish)
return unless which("fish")
<<-EOS.undent
fish completion has been installed to:
#{HOMEBREW_PREFIX}/share/fish/vendor_completions.d
EOS
end
end
def python_caveats
return unless keg
@ -140,23 +147,25 @@ class Caveats
end
def app_caveats
if keg && keg.app_installed?
return unless keg
return unless keg.app_installed?
<<-EOS.undent
.app bundles were installed.
Run `brew linkapps #{keg.name}` to symlink these to /Applications.
EOS
end
end
def elisp_caveats
return if f.keg_only?
if keg && keg.elisp_installed?
return unless keg
return unless keg.elisp_installed?
<<-EOS.undent
Emacs Lisp files have been installed to:
#{HOMEBREW_PREFIX}/share/emacs/site-lisp/#{f.name}
EOS
end
end
def plist_caveats
s = []

View File

@ -87,9 +87,9 @@ class Cleaner
Find.prune if @f.skip_clean? path
if path.symlink? || path.directory?
next
elsif path.extname == ".la"
next if path.symlink? || path.directory?
if path.extname == ".la"
path.unlink
elsif path.basename.to_s == "perllocal.pod"
# Both this file & the .packlist one below are completely unnecessary

View File

@ -22,7 +22,8 @@ module Homebrew
ARGV.resolved_formulae.each { |f| Cleanup.cleanup_formula f }
end
if Cleanup.disk_cleanup_size > 0
return if Cleanup.disk_cleanup_size.zero?
disk_space = disk_usage_readable(Cleanup.disk_cleanup_size)
if ARGV.dry_run?
ohai "This operation would free approximately #{disk_space} of disk space."
@ -30,5 +31,4 @@ module Homebrew
ohai "This operation has freed approximately #{disk_space} of disk space."
end
end
end
end

View File

@ -31,12 +31,10 @@ module Homebrew
def detect_version(path)
version = path.version.to_s
if version.empty?
raise "Couldn't determine version, set it with --version=<version>"
else
raise "Couldn't determine version, set it with --version=<version>" if version.empty?
version
end
end
def detect_name(path, version)
basename = path.basename.to_s

View File

@ -54,11 +54,8 @@ module Homebrew
end
rescue FormulaUnavailableError
# No formula with this name, try a blacklist lookup
if (blacklist = blacklisted?(f))
raise unless (blacklist = blacklisted?(f))
puts blacklist
else
raise
end
end
end
end

View File

@ -245,12 +245,12 @@ module Homebrew
end
def check_macports
unless MacOS.macports_or_fink.empty?
return if MacOS.macports_or_fink.empty?
opoo "It appears you have MacPorts or Fink installed."
puts "Software installed with other package managers causes known problems for"
puts "Homebrew. If a formula fails to build, uninstall MacPorts/Fink and try again."
end
end
def check_cellar
FileUtils.mkdir_p HOMEBREW_CELLAR unless File.exist? HOMEBREW_CELLAR

View File

@ -58,11 +58,12 @@ module Homebrew
def restore_backup(keg, formula)
path = backup_path(keg)
if path.directory?
return unless path.directory?
path.rename keg
keg.link unless formula.keg_only?
end
end
def backup_path(path)
Pathname.new "#{path}.reinstall"

View File

@ -171,10 +171,11 @@ module Homebrew
rescue
canonical_name = canonical_full_name = name
end
# Ignore aliases from results when the full name was also found
if aliases.include?(name) && results.include?(canonical_full_name)
next
elsif (HOMEBREW_CELLAR/canonical_name).directory?
next if aliases.include?(name) && results.include?(canonical_full_name)
if (HOMEBREW_CELLAR/canonical_name).directory?
pretty_installed(name)
else
name

View File

@ -83,12 +83,12 @@ module Homebrew
end
end
unless problem_count.zero?
return if problem_count.zero?
problems = "problem" + plural(problem_count)
formulae = "formula" + plural(formula_count, "e")
ofail "#{problem_count} #{problems} in #{formula_count} #{formulae}"
end
end
end
class FormulaText
@ -279,9 +279,11 @@ class FormulaAuditor
end
end
end
if present.include?("head") && present.include?("head block")
problem "Should not have both `head` and `head do`"
end
if present.include?("bottle modifier") && present.include?("bottle block")
problem "Should not have `bottle :unneeded/:disable` and `bottle do`"
end
@ -668,7 +670,9 @@ class FormulaAuditor
end
revision_map = attributes_map[:revision]
if formula.revision.nonzero?
return if formula.revision.zero?
if formula.stable
if revision_map[formula.stable.version].empty? # check stable spec
problem "'revision #{formula.revision}' should be removed"
@ -677,16 +681,16 @@ class FormulaAuditor
problem "'revision #{formula.revision}' should be removed"
end
end
end
def audit_legacy_patches
return unless formula.respond_to?(:patches)
legacy_patches = Patch.normalize_legacy_patches(formula.patches).grep(LegacyPatch)
unless legacy_patches.empty?
return if legacy_patches.empty?
problem "Use the patch DSL instead of defining a 'patches' method"
legacy_patches.each { |p| audit_patch(p) }
end
end
def audit_patch(patch)
case patch.url
@ -961,7 +965,8 @@ class FormulaAuditor
problem "Use Language::Node for npm install args"
end
if @strict
return unless @strict
if line =~ /system ((["'])[^"' ]*(?:\s[^"' ]*)+\2)/
bad_system = $1
unless %w[| < > & ; *].any? { |c| bad_system.include? c }
@ -982,41 +987,35 @@ class FormulaAuditor
problem "Use pkgshare instead of (share#{$1}\"#{formula.name}\")"
end
end
end
def audit_caveats
caveats = formula.caveats.to_s
if caveats.include?("setuid")
return unless formula.caveats.to_s.include?("setuid")
problem "Don't recommend setuid in the caveats, suggest sudo instead."
end
end
def audit_reverse_migration
# Only enforce for new formula being re-added to core and official taps
return unless @strict
return unless formula.tap && formula.tap.official?
return unless formula.tap.tap_migrations.key?(formula.name)
if formula.tap.tap_migrations.key?(formula.name)
problem <<-EOS.undent
#{formula.name} seems to be listed in tap_migrations.json!
Please remove #{formula.name} from present tap & tap_migrations.json
before submitting it to Homebrew/homebrew-#{formula.tap.repo}.
EOS
end
end
def audit_prefix_has_contents
return unless formula.prefix.directory?
return unless Keg.new(formula.prefix).empty_installation?
if Keg.new(formula.prefix).empty_installation?
problem <<-EOS.undent
The installation seems to be empty. Please ensure the prefix
is set correctly and expected files are installed.
The prefix configure/make argument may be case-sensitive.
EOS
end
end
def audit_conditional_dep(dep, condition, line)
quoted_dep = quote_dep(dep)
@ -1184,9 +1183,7 @@ class ResourceAuditor
end
end
using_strategy = DownloadStrategyDetector.detect("", using)
if url_strategy == using_strategy
if url_strategy == DownloadStrategyDetector.detect("", using)
problem "Redundant :using value in URL"
end
end

View File

@ -51,11 +51,12 @@ module Homebrew
end
@put_filenames ||= []
unless @put_filenames.include? filename
return if @put_filenames.include? filename
puts "#{Tty.red}#{filename}#{Tty.reset}"
@put_filenames << filename
end
end
result = false
@ -137,11 +138,11 @@ module Homebrew
tap = f.tap
unless tap
if ARGV.include?("--force-core-tap")
tap = CoreTap.instance
else
unless ARGV.include?("--force-core-tap")
return ofail "Formula not from core or any taps: #{f.full_name}"
end
tap = CoreTap.instance
end
if f.bottle_disabled?
@ -323,7 +324,7 @@ module Homebrew
puts "./#{filename}"
puts output
if ARGV.include? "--json"
return unless ARGV.include? "--json"
json = {
f.full_name => {
"formula" => {
@ -352,7 +353,6 @@ module Homebrew
file.write Utils::JSON.dump json
end
end
end
def merge
write = ARGV.include? "--write"