Rubocop: manual rule fixes.

This commit is contained in:
Mike McQuaid 2017-09-24 20:12:58 +01:00
parent 01e9ec9a9f
commit cf5fdeef1d
25 changed files with 54 additions and 67 deletions

View File

@ -105,18 +105,16 @@ begin
possible_tap = OFFICIAL_CMD_TAPS.find { |_, cmds| cmds.include?(cmd) } possible_tap = OFFICIAL_CMD_TAPS.find { |_, cmds| cmds.include?(cmd) }
possible_tap = Tap.fetch(possible_tap.first) if possible_tap possible_tap = Tap.fetch(possible_tap.first) if possible_tap
if possible_tap && !possible_tap.installed? odie "Unknown command: #{cmd}" if !possible_tap || possible_tap.installed?
brew_uid = HOMEBREW_BREW_FILE.stat.uid
tap_commands = [] brew_uid = HOMEBREW_BREW_FILE.stat.uid
if Process.uid.zero? && !brew_uid.zero? tap_commands = []
tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero?
end tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}]
tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap}]
safe_system(*tap_commands)
exec HOMEBREW_BREW_FILE, cmd, *ARGV
else
odie "Unknown command: #{cmd}"
end end
tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap}]
safe_system(*tap_commands)
exec HOMEBREW_BREW_FILE, cmd, *ARGV
end end
rescue UsageError => e rescue UsageError => e
require "cmd/help" require "cmd/help"

View File

@ -16,7 +16,7 @@ module Hbc
def target_file def target_file
return @path.basename if @nested return @path.basename if @nested
URI.decode(File.basename(@cask.url.path)) CGI.unescape(File.basename(@cask.url.path))
end end
end end
end end

View File

@ -49,7 +49,7 @@ module Hbc
end end
end end
DIVIDERS.keys.each do |divider| DIVIDERS.each_key do |divider|
define_divider_methods(divider) define_divider_methods(divider)
end end

View File

@ -55,7 +55,7 @@ module Homebrew
else else
n, d = ObserverPathnameExtension.counts n, d = ObserverPathnameExtension.counts
print "Pruned #{n} symbolic links " print "Pruned #{n} symbolic links "
print "and #{d} directories " if d > 0 print "and #{d} directories " if d.positive?
puts "from #{HOMEBREW_PREFIX}" puts "from #{HOMEBREW_PREFIX}"
end end
end end

View File

@ -67,7 +67,7 @@ module Homebrew
ohai "Searching blacklisted, migrated and deleted formulae..." ohai "Searching blacklisted, migrated and deleted formulae..."
if reason = Homebrew::MissingFormula.reason(query, silent: true) if reason = Homebrew::MissingFormula.reason(query, silent: true)
if count > 0 if count.positive?
puts puts
puts "If you meant #{query.inspect} specifically:" puts "If you meant #{query.inspect} specifically:"
end end

View File

@ -64,10 +64,10 @@ module Homebrew
if tap.installed? if tap.installed?
info += tap.pinned? ? "pinned" : "unpinned" info += tap.pinned? ? "pinned" : "unpinned"
info += ", private" if tap.private? 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")}" info += ", #{Formatter.pluralize(formula_count, "formula")}"
end end
if (command_count = tap.command_files.size) > 0 if (command_count = tap.command_files.size).positive?
info += ", #{Formatter.pluralize(command_count, "command")}" info += ", #{Formatter.pluralize(command_count, "command")}"
end end
info += ", no formulae/commands" if (formula_count + command_count).zero? info += ", no formulae/commands" if (formula_count + command_count).zero?

View File

@ -57,7 +57,7 @@ module Debrew
input.chomp! input.chomp!
i = input.to_i i = input.to_i
if i > 0 if i.positive?
choice = menu.entries[i - 1] choice = menu.entries[i - 1]
else else
possible = menu.entries.find_all { |e| e.name.start_with?(input) } possible = menu.entries.find_all { |e| e.name.start_with?(input) }

View File

@ -358,7 +358,7 @@ class FormulaAuditor
end end
valid_alias_names = [alias_name_major, alias_name_major_minor] 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}" } versioned_aliases.map! { |a| "#{formula.tap}/#{a}" }
valid_alias_names.map! { |a| "#{formula.tap}/#{a}" } valid_alias_names.map! { |a| "#{formula.tap}/#{a}" }
end end

View File

@ -47,7 +47,7 @@ BOTTLE_ERB = <<-EOS.freeze
<% elsif cellar != BottleSpecification::DEFAULT_CELLAR %> <% elsif cellar != BottleSpecification::DEFAULT_CELLAR %>
cellar "<%= cellar %>" cellar "<%= cellar %>"
<% end %> <% end %>
<% if rebuild > 0 %> <% if rebuild.positive? %>
rebuild <%= rebuild %> rebuild <%= rebuild %>
<% end %> <% end %>
<% checksums.each do |checksum_type, checksum_values| %> <% checksums.each do |checksum_type, checksum_values| %>
@ -186,7 +186,7 @@ module Homebrew
ohai "Determining #{f.full_name} bottle rebuild..." ohai "Determining #{f.full_name} bottle rebuild..."
versions = FormulaVersions.new(f) versions = FormulaVersions.new(f)
rebuilds = versions.bottle_version_map("origin/master")[f.pkg_version] 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 rebuild = rebuilds.empty? ? 0 : rebuilds.max.to_i + 1
end end

View File

@ -89,7 +89,7 @@ module Homebrew
def check_for_duplicate_pull_requests(formula) def check_for_duplicate_pull_requests(formula)
pull_requests = fetch_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 duplicates_message = <<-EOS.undent
These open pull requests may be duplicates: These open pull requests may be duplicates:
#{pull_requests.map { |pr| "#{pr["title"]} #{pr["html_url"]}" }.join("\n")} #{pull_requests.map { |pr| "#{pr["title"]} #{pr["html_url"]}" }.join("\n")}

View File

@ -69,7 +69,7 @@ module Homebrew
tap = nil tap = nil
ARGV.named.each do |arg| ARGV.named.each do |arg|
if arg.to_i > 0 if arg.to_i.positive?
issue = arg issue = arg
url = "https://github.com/Homebrew/homebrew-core/pull/#{arg}" url = "https://github.com/Homebrew/homebrew-core/pull/#{arg}"
tap = CoreTap.instance tap = CoreTap.instance

View File

@ -416,7 +416,7 @@ class BuildError < RuntimeError
puts puts
if issues && !issues.empty? unless issues&.empty?
puts "These open issues may also help:" puts "These open issues may also help:"
puts issues.map { |i| "#{i["title"]} #{i["html_url"]}" }.join("\n") puts issues.map { |i| "#{i["title"]} #{i["html_url"]}" }.join("\n")
end end

View File

@ -28,7 +28,7 @@ module EnvActivation
end end
def clear_sensitive_environment! def clear_sensitive_environment!
ENV.keys.each do |key| ENV.each_key do |key|
next unless /(cookie|key|token)/i =~ key next unless /(cookie|key|token)/i =~ key
ENV.delete key ENV.delete key
end end

View File

@ -233,8 +233,8 @@ module Stdenv
def make_jobs def make_jobs
# '-j' requires a positive integral argument # '-j' requires a positive integral argument
if self["HOMEBREW_MAKE_JOBS"].to_i > 0 if (jobs = self["HOMEBREW_MAKE_JOBS"].to_i).positive?
self["HOMEBREW_MAKE_JOBS"].to_i jobs
else else
Hardware::CPU.cores Hardware::CPU.cores
end end

View File

@ -1182,7 +1182,8 @@ class Formula
# Returns false if the formula wasn't installed with an alias. # Returns false if the formula wasn't installed with an alias.
def installed_alias_target_changed? def installed_alias_target_changed?
target = current_installed_alias_target target = current_installed_alias_target
target && target.name != name return false unless target
target.name != name
end end
# Is this formula the target of an alias used to install an old formula? # 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 # True if this formula is provided by external Tap
# @private # @private
def tap? def tap?
tap && !tap.core_tap? return false unless tap
!tap.core_tap?
end end
# @private # @private
@ -1570,7 +1572,7 @@ class Formula
"root_url" => bottle_spec.root_url, "root_url" => bottle_spec.root_url,
} }
bottle_info["files"] = {} 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] checksum = bottle_spec.collector[os]
bottle_info["files"][os] = { bottle_info["files"][os] = {
"url" => "#{bottle_spec.root_url}/#{Bottle::Filename.create(self, os, bottle_spec.rebuild)}", "url" => "#{bottle_spec.root_url}/#{Bottle::Filename.create(self, os, bottle_spec.rebuild)}",

View File

@ -269,7 +269,7 @@ class FormulaInstaller
oh1 "Installing #{Formatter.identifier(formula.full_name)} #{options}".strip oh1 "Installing #{Formatter.identifier(formula.full_name)} #{options}".strip
end end
if formula.tap && !formula.tap.private? unless formula.tap&.private?
action = "#{formula.full_name} #{options}".strip action = "#{formula.full_name} #{options}".strip
Utils::Analytics.report_event("install", action) Utils::Analytics.report_event("install", action)

View File

@ -16,12 +16,12 @@ module InstallRenamed
end end
end end
def +(path) def +(other)
super(path).extend(InstallRenamed) super(other).extend(InstallRenamed)
end end
def /(path) def /(other)
super(path).extend(InstallRenamed) super(other).extend(InstallRenamed)
end end
private private

View File

@ -44,8 +44,6 @@ class Locale
raise ParserError, "'#{value}' does not match #{regex}" unless value =~ regex raise ParserError, "'#{value}' does not match #{regex}" unless value =~ regex
instance_variable_set(:"@#{key}", value) instance_variable_set(:"@#{key}", value)
end end
self
end end
def include?(other) def include?(other)

View File

@ -69,29 +69,29 @@ class Options
@options.each(*args, &block) @options.each(*args, &block)
end end
def <<(o) def <<(other)
@options << o @options << other
self self
end end
def +(o) def +(other)
self.class.new(@options + o) self.class.new(@options + other)
end end
def -(o) def -(other)
self.class.new(@options - o) self.class.new(@options - other)
end end
def &(o) def &(other)
self.class.new(@options & o) self.class.new(@options & other)
end end
def |(o) def |(other)
self.class.new(@options | o) self.class.new(@options | other)
end end
def *(arg) def *(other)
@options.to_a * arg @options.to_a * other
end end
def empty? def empty?

View File

@ -23,7 +23,7 @@ class PkgVersion
end end
def to_s def to_s
if revision > 0 if revision.positive?
"#{version}_#{revision}" "#{version}_#{revision}"
else else
version.to_s version.to_s

View File

@ -87,8 +87,8 @@ module RuboCop
# preceding_comp_arr: array containing components of same type # preceding_comp_arr: array containing components of same type
order_idx, curr_p_idx, preceding_comp_arr = get_state(node1) 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 # curr_p_idx.positive? means node1 needs to be grouped with its own kind
if curr_p_idx > 0 if curr_p_idx.positive?
node2 = preceding_comp_arr[curr_p_idx - 1] node2 = preceding_comp_arr[curr_p_idx - 1]
indentation = " " * (start_column(node2) - line_start_column(node2)) indentation = " " * (start_column(node2) - line_start_column(node2))
line_breaks = node2.multiline? ? "\n\n" : "\n" line_breaks = node2.multiline? ? "\n\n" : "\n"

View File

@ -267,7 +267,7 @@ class Bottle
end end
def suffix def suffix
s = (rebuild > 0) ? ".#{rebuild}" : "" s = rebuild.positive? ? ".#{rebuild}" : ""
".bottle#{s}.tar.gz" ".bottle#{s}.tar.gz"
end end
end end

View File

@ -648,6 +648,5 @@ class TapConfig
tap.path.cd do tap.path.cd do
safe_system "git", "config", "--local", "--replace-all", "homebrew.#{key}", value.to_s safe_system "git", "config", "--local", "--replace-all", "homebrew.#{key}", value.to_s
end end
value
end end
end end

View File

@ -86,15 +86,9 @@ module GitHub
def api_credentials_type def api_credentials_type
token, username = api_credentials token, username = api_credentials
if token && !token.empty? return :none if !token || token.empty?
if username && !username.empty? return :keychain if !username || username.empty?
:keychain :environment
else
:environment
end
else
:none
end
end end
def api_credentials_error_message(response_headers, needed_scopes) def api_credentials_error_message(response_headers, needed_scopes)

View File

@ -51,8 +51,6 @@ module Utils
end end
end end
private
SHELL_PROFILE_MAP = { SHELL_PROFILE_MAP = {
bash: "~/.bash_profile", bash: "~/.bash_profile",
csh: "~/.cshrc", csh: "~/.cshrc",
@ -65,8 +63,6 @@ module Utils
UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@\n])} UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@\n])}
module_function
def csh_quote(str) def csh_quote(str)
# ruby's implementation of shell_escape # ruby's implementation of shell_escape
str = str.to_s str = str.to_s