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,7 +105,8 @@ 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?
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?
@ -114,9 +115,6 @@ begin
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
rescue UsageError => e
require "cmd/help"

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -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)}",

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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