aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMike McQuaid2017-09-24 20:12:58 +0100
committerMike McQuaid2017-09-24 21:23:59 +0100
commitcf5fdeef1d8e9fd053121145882835b87eec2a43 (patch)
tree1b116e75a955f10925619f11db947f0917a55bf9 /Library
parent01e9ec9a9f723b2ef89c7adfaea39f9e4db9aede (diff)
downloadbrew-cf5fdeef1d8e9fd053121145882835b87eec2a43.tar.bz2
Rubocop: manual rule fixes.
Diffstat (limited to 'Library')
-rw-r--r--Library/Homebrew/brew.rb20
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/naked.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl/version.rb2
-rw-r--r--Library/Homebrew/cmd/prune.rb2
-rw-r--r--Library/Homebrew/cmd/search.rb2
-rw-r--r--Library/Homebrew/cmd/tap-info.rb4
-rw-r--r--Library/Homebrew/debrew.rb2
-rw-r--r--Library/Homebrew/dev-cmd/audit.rb2
-rw-r--r--Library/Homebrew/dev-cmd/bottle.rb4
-rw-r--r--Library/Homebrew/dev-cmd/bump-formula-pr.rb2
-rw-r--r--Library/Homebrew/dev-cmd/pull.rb2
-rw-r--r--Library/Homebrew/exceptions.rb2
-rw-r--r--Library/Homebrew/extend/ENV.rb2
-rw-r--r--Library/Homebrew/extend/ENV/std.rb4
-rw-r--r--Library/Homebrew/formula.rb8
-rw-r--r--Library/Homebrew/formula_installer.rb2
-rw-r--r--Library/Homebrew/install_renamed.rb8
-rw-r--r--Library/Homebrew/locale.rb2
-rw-r--r--Library/Homebrew/options.rb24
-rw-r--r--Library/Homebrew/pkg_version.rb2
-rw-r--r--Library/Homebrew/rubocops/components_order_cop.rb4
-rw-r--r--Library/Homebrew/software_spec.rb2
-rw-r--r--Library/Homebrew/tap.rb1
-rw-r--r--Library/Homebrew/utils/github.rb12
-rw-r--r--Library/Homebrew/utils/shell.rb4
25 files changed, 54 insertions, 67 deletions
diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb
index ec86bd794..2906fd93d 100644
--- a/Library/Homebrew/brew.rb
+++ b/Library/Homebrew/brew.rb
@@ -105,18 +105,16 @@ begin
possible_tap = OFFICIAL_CMD_TAPS.find { |_, cmds| cmds.include?(cmd) }
possible_tap = Tap.fetch(possible_tap.first) if possible_tap
- if possible_tap && !possible_tap.installed?
- brew_uid = HOMEBREW_BREW_FILE.stat.uid
- tap_commands = []
- if Process.uid.zero? && !brew_uid.zero?
- tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}]
- end
- tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap}]
- safe_system(*tap_commands)
- exec HOMEBREW_BREW_FILE, cmd, *ARGV
- else
- odie "Unknown command: #{cmd}"
+ odie "Unknown command: #{cmd}" if !possible_tap || possible_tap.installed?
+
+ brew_uid = HOMEBREW_BREW_FILE.stat.uid
+ tap_commands = []
+ if Process.uid.zero? && !brew_uid.zero?
+ tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}]
end
+ tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap}]
+ safe_system(*tap_commands)
+ exec HOMEBREW_BREW_FILE, cmd, *ARGV
end
rescue UsageError => e
require "cmd/help"
diff --git a/Library/Homebrew/cask/lib/hbc/container/naked.rb b/Library/Homebrew/cask/lib/hbc/container/naked.rb
index 375d62f7a..dc265c402 100644
--- a/Library/Homebrew/cask/lib/hbc/container/naked.rb
+++ b/Library/Homebrew/cask/lib/hbc/container/naked.rb
@@ -16,7 +16,7 @@ module Hbc
def target_file
return @path.basename if @nested
- URI.decode(File.basename(@cask.url.path))
+ CGI.unescape(File.basename(@cask.url.path))
end
end
end
diff --git a/Library/Homebrew/cask/lib/hbc/dsl/version.rb b/Library/Homebrew/cask/lib/hbc/dsl/version.rb
index d73205f52..9605feb57 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl/version.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl/version.rb
@@ -49,7 +49,7 @@ module Hbc
end
end
- DIVIDERS.keys.each do |divider|
+ DIVIDERS.each_key do |divider|
define_divider_methods(divider)
end
diff --git a/Library/Homebrew/cmd/prune.rb b/Library/Homebrew/cmd/prune.rb
index 9fc6dbcd9..7ec2838ba 100644
--- a/Library/Homebrew/cmd/prune.rb
+++ b/Library/Homebrew/cmd/prune.rb
@@ -55,7 +55,7 @@ module Homebrew
else
n, d = ObserverPathnameExtension.counts
print "Pruned #{n} symbolic links "
- print "and #{d} directories " if d > 0
+ print "and #{d} directories " if d.positive?
puts "from #{HOMEBREW_PREFIX}"
end
end
diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb
index acee9817f..c01a11c10 100644
--- a/Library/Homebrew/cmd/search.rb
+++ b/Library/Homebrew/cmd/search.rb
@@ -67,7 +67,7 @@ module Homebrew
ohai "Searching blacklisted, migrated and deleted formulae..."
if reason = Homebrew::MissingFormula.reason(query, silent: true)
- if count > 0
+ if count.positive?
puts
puts "If you meant #{query.inspect} specifically:"
end
diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb
index af087645d..cb0e0b387 100644
--- a/Library/Homebrew/cmd/tap-info.rb
+++ b/Library/Homebrew/cmd/tap-info.rb
@@ -64,10 +64,10 @@ module Homebrew
if tap.installed?
info += tap.pinned? ? "pinned" : "unpinned"
info += ", private" if tap.private?
- if (formula_count = tap.formula_files.size) > 0
+ if (formula_count = tap.formula_files.size).positive?
info += ", #{Formatter.pluralize(formula_count, "formula")}"
end
- if (command_count = tap.command_files.size) > 0
+ if (command_count = tap.command_files.size).positive?
info += ", #{Formatter.pluralize(command_count, "command")}"
end
info += ", no formulae/commands" if (formula_count + command_count).zero?
diff --git a/Library/Homebrew/debrew.rb b/Library/Homebrew/debrew.rb
index c2662c9ee..5bc3d2daa 100644
--- a/Library/Homebrew/debrew.rb
+++ b/Library/Homebrew/debrew.rb
@@ -57,7 +57,7 @@ module Debrew
input.chomp!
i = input.to_i
- if i > 0
+ if i.positive?
choice = menu.entries[i - 1]
else
possible = menu.entries.find_all { |e| e.name.start_with?(input) }
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb
index 1fb89c3a4..a7d498c0d 100644
--- a/Library/Homebrew/dev-cmd/audit.rb
+++ b/Library/Homebrew/dev-cmd/audit.rb
@@ -358,7 +358,7 @@ class FormulaAuditor
end
valid_alias_names = [alias_name_major, alias_name_major_minor]
- if formula.tap && !formula.tap.core_tap?
+ unless formula.tap&.core_tap?
versioned_aliases.map! { |a| "#{formula.tap}/#{a}" }
valid_alias_names.map! { |a| "#{formula.tap}/#{a}" }
end
diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb
index 577924a34..8dfd0d12c 100644
--- a/Library/Homebrew/dev-cmd/bottle.rb
+++ b/Library/Homebrew/dev-cmd/bottle.rb
@@ -47,7 +47,7 @@ BOTTLE_ERB = <<-EOS.freeze
<% elsif cellar != BottleSpecification::DEFAULT_CELLAR %>
cellar "<%= cellar %>"
<% end %>
- <% if rebuild > 0 %>
+ <% if rebuild.positive? %>
rebuild <%= rebuild %>
<% end %>
<% checksums.each do |checksum_type, checksum_values| %>
@@ -186,7 +186,7 @@ module Homebrew
ohai "Determining #{f.full_name} bottle rebuild..."
versions = FormulaVersions.new(f)
rebuilds = versions.bottle_version_map("origin/master")[f.pkg_version]
- rebuilds.pop if rebuilds.last.to_i > 0
+ rebuilds.pop if rebuilds.last.to_i.positive?
rebuild = rebuilds.empty? ? 0 : rebuilds.max.to_i + 1
end
diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb
index 87a239b98..21abed7d9 100644
--- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb
+++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb
@@ -89,7 +89,7 @@ module Homebrew
def check_for_duplicate_pull_requests(formula)
pull_requests = fetch_pull_requests(formula)
- return unless pull_requests && !pull_requests.empty?
+ return unless pull_requests&.empty?
duplicates_message = <<-EOS.undent
These open pull requests may be duplicates:
#{pull_requests.map { |pr| "#{pr["title"]} #{pr["html_url"]}" }.join("\n")}
diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb
index 931cba07f..cd0d6fbd0 100644
--- a/Library/Homebrew/dev-cmd/pull.rb
+++ b/Library/Homebrew/dev-cmd/pull.rb
@@ -69,7 +69,7 @@ module Homebrew
tap = nil
ARGV.named.each do |arg|
- if arg.to_i > 0
+ if arg.to_i.positive?
issue = arg
url = "https://github.com/Homebrew/homebrew-core/pull/#{arg}"
tap = CoreTap.instance
diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb
index 8b4cddc59..5418f9331 100644
--- a/Library/Homebrew/exceptions.rb
+++ b/Library/Homebrew/exceptions.rb
@@ -416,7 +416,7 @@ class BuildError < RuntimeError
puts
- if issues && !issues.empty?
+ unless issues&.empty?
puts "These open issues may also help:"
puts issues.map { |i| "#{i["title"]} #{i["html_url"]}" }.join("\n")
end
diff --git a/Library/Homebrew/extend/ENV.rb b/Library/Homebrew/extend/ENV.rb
index 283e90b69..ea1b99501 100644
--- a/Library/Homebrew/extend/ENV.rb
+++ b/Library/Homebrew/extend/ENV.rb
@@ -28,7 +28,7 @@ module EnvActivation
end
def clear_sensitive_environment!
- ENV.keys.each do |key|
+ ENV.each_key do |key|
next unless /(cookie|key|token)/i =~ key
ENV.delete key
end
diff --git a/Library/Homebrew/extend/ENV/std.rb b/Library/Homebrew/extend/ENV/std.rb
index a2e800803..4e5d0683a 100644
--- a/Library/Homebrew/extend/ENV/std.rb
+++ b/Library/Homebrew/extend/ENV/std.rb
@@ -233,8 +233,8 @@ module Stdenv
def make_jobs
# '-j' requires a positive integral argument
- if self["HOMEBREW_MAKE_JOBS"].to_i > 0
- self["HOMEBREW_MAKE_JOBS"].to_i
+ if (jobs = self["HOMEBREW_MAKE_JOBS"].to_i).positive?
+ jobs
else
Hardware::CPU.cores
end
diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb
index 69a4cd5aa..d999b9c5f 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -1182,7 +1182,8 @@ class Formula
# Returns false if the formula wasn't installed with an alias.
def installed_alias_target_changed?
target = current_installed_alias_target
- target && target.name != name
+ return false unless target
+ target.name != name
end
# Is this formula the target of an alias used to install an old formula?
@@ -1446,7 +1447,8 @@ class Formula
# True if this formula is provided by external Tap
# @private
def tap?
- tap && !tap.core_tap?
+ return false unless tap
+ !tap.core_tap?
end
# @private
@@ -1570,7 +1572,7 @@ class Formula
"root_url" => bottle_spec.root_url,
}
bottle_info["files"] = {}
- bottle_spec.collector.keys.each do |os|
+ bottle_spec.collector.keys.each do |os| # rubocop:disable Performance/HashEachMethods
checksum = bottle_spec.collector[os]
bottle_info["files"][os] = {
"url" => "#{bottle_spec.root_url}/#{Bottle::Filename.create(self, os, bottle_spec.rebuild)}",
diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb
index 68816a782..b4f9db845 100644
--- a/Library/Homebrew/formula_installer.rb
+++ b/Library/Homebrew/formula_installer.rb
@@ -269,7 +269,7 @@ class FormulaInstaller
oh1 "Installing #{Formatter.identifier(formula.full_name)} #{options}".strip
end
- if formula.tap && !formula.tap.private?
+ unless formula.tap&.private?
action = "#{formula.full_name} #{options}".strip
Utils::Analytics.report_event("install", action)
diff --git a/Library/Homebrew/install_renamed.rb b/Library/Homebrew/install_renamed.rb
index 5e200244f..dc5d4cda8 100644
--- a/Library/Homebrew/install_renamed.rb
+++ b/Library/Homebrew/install_renamed.rb
@@ -16,12 +16,12 @@ module InstallRenamed
end
end
- def +(path)
- super(path).extend(InstallRenamed)
+ def +(other)
+ super(other).extend(InstallRenamed)
end
- def /(path)
- super(path).extend(InstallRenamed)
+ def /(other)
+ super(other).extend(InstallRenamed)
end
private
diff --git a/Library/Homebrew/locale.rb b/Library/Homebrew/locale.rb
index 5e778f3b4..d918e2a2a 100644
--- a/Library/Homebrew/locale.rb
+++ b/Library/Homebrew/locale.rb
@@ -44,8 +44,6 @@ class Locale
raise ParserError, "'#{value}' does not match #{regex}" unless value =~ regex
instance_variable_set(:"@#{key}", value)
end
-
- self
end
def include?(other)
diff --git a/Library/Homebrew/options.rb b/Library/Homebrew/options.rb
index 9f1253531..05dd643ff 100644
--- a/Library/Homebrew/options.rb
+++ b/Library/Homebrew/options.rb
@@ -69,29 +69,29 @@ class Options
@options.each(*args, &block)
end
- def <<(o)
- @options << o
+ def <<(other)
+ @options << other
self
end
- def +(o)
- self.class.new(@options + o)
+ def +(other)
+ self.class.new(@options + other)
end
- def -(o)
- self.class.new(@options - o)
+ def -(other)
+ self.class.new(@options - other)
end
- def &(o)
- self.class.new(@options & o)
+ def &(other)
+ self.class.new(@options & other)
end
- def |(o)
- self.class.new(@options | o)
+ def |(other)
+ self.class.new(@options | other)
end
- def *(arg)
- @options.to_a * arg
+ def *(other)
+ @options.to_a * other
end
def empty?
diff --git a/Library/Homebrew/pkg_version.rb b/Library/Homebrew/pkg_version.rb
index 761a349fd..b68d78cf8 100644
--- a/Library/Homebrew/pkg_version.rb
+++ b/Library/Homebrew/pkg_version.rb
@@ -23,7 +23,7 @@ class PkgVersion
end
def to_s
- if revision > 0
+ if revision.positive?
"#{version}_#{revision}"
else
version.to_s
diff --git a/Library/Homebrew/rubocops/components_order_cop.rb b/Library/Homebrew/rubocops/components_order_cop.rb
index f1179d9a4..3bf2ede16 100644
--- a/Library/Homebrew/rubocops/components_order_cop.rb
+++ b/Library/Homebrew/rubocops/components_order_cop.rb
@@ -87,8 +87,8 @@ module RuboCop
# preceding_comp_arr: array containing components of same type
order_idx, curr_p_idx, preceding_comp_arr = get_state(node1)
- # curr_p_idx > 0 means node1 needs to be grouped with its own kind
- if curr_p_idx > 0
+ # curr_p_idx.positive? means node1 needs to be grouped with its own kind
+ if curr_p_idx.positive?
node2 = preceding_comp_arr[curr_p_idx - 1]
indentation = " " * (start_column(node2) - line_start_column(node2))
line_breaks = node2.multiline? ? "\n\n" : "\n"
diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb
index 49d818f0f..dd6026fcf 100644
--- a/Library/Homebrew/software_spec.rb
+++ b/Library/Homebrew/software_spec.rb
@@ -267,7 +267,7 @@ class Bottle
end
def suffix
- s = (rebuild > 0) ? ".#{rebuild}" : ""
+ s = rebuild.positive? ? ".#{rebuild}" : ""
".bottle#{s}.tar.gz"
end
end
diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb
index f6246aad9..f4e7631b4 100644
--- a/Library/Homebrew/tap.rb
+++ b/Library/Homebrew/tap.rb
@@ -648,6 +648,5 @@ class TapConfig
tap.path.cd do
safe_system "git", "config", "--local", "--replace-all", "homebrew.#{key}", value.to_s
end
- value
end
end
diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb
index a50d6d8e5..df0811e95 100644
--- a/Library/Homebrew/utils/github.rb
+++ b/Library/Homebrew/utils/github.rb
@@ -86,15 +86,9 @@ module GitHub
def api_credentials_type
token, username = api_credentials
- if token && !token.empty?
- if username && !username.empty?
- :keychain
- else
- :environment
- end
- else
- :none
- end
+ return :none if !token || token.empty?
+ return :keychain if !username || username.empty?
+ :environment
end
def api_credentials_error_message(response_headers, needed_scopes)
diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb
index 5327f6ecf..8c1c5f984 100644
--- a/Library/Homebrew/utils/shell.rb
+++ b/Library/Homebrew/utils/shell.rb
@@ -51,8 +51,6 @@ module Utils
end
end
- private
-
SHELL_PROFILE_MAP = {
bash: "~/.bash_profile",
csh: "~/.cshrc",
@@ -65,8 +63,6 @@ module Utils
UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@\n])}
- module_function
-
def csh_quote(str)
# ruby's implementation of shell_escape
str = str.to_s