aboutsummaryrefslogtreecommitdiffstats
path: root/Library
diff options
context:
space:
mode:
authorMike McQuaid2017-09-25 21:29:03 +0100
committerGitHub2017-09-25 21:29:03 +0100
commita5893036166b9708d705a5060aa85002d5a6be16 (patch)
tree03a254a34d12926540a0be677ffc8c9b9f32d5d0 /Library
parentac8b58537fe3dd71098a43afcc6a1785dcde1d39 (diff)
parentcf5fdeef1d8e9fd053121145882835b87eec2a43 (diff)
downloadbrew-a5893036166b9708d705a5060aa85002d5a6be16.tar.bz2
Merge pull request #3183 from MikeMcQuaid/rubocop-upgrade
Rubocop: 0.50.0 and Ruby 2.3
Diffstat (limited to 'Library')
-rw-r--r--Library/.rubocop.yml23
-rw-r--r--Library/Homebrew/.rubocop.yml4
-rw-r--r--Library/Homebrew/.rubocop_todo.yml9
-rw-r--r--Library/Homebrew/brew.rb20
-rw-r--r--Library/Homebrew/cask/lib/hbc/cask_loader.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/container/naked.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/dsl/version.rb2
-rw-r--r--Library/Homebrew/cask/lib/hbc/installer.rb4
-rw-r--r--Library/Homebrew/cask/lib/hbc/system_command.rb2
-rw-r--r--Library/Homebrew/caveats.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/cmd/unlinkapps.rb2
-rw-r--r--Library/Homebrew/constants.rb6
-rw-r--r--Library/Homebrew/debrew.rb2
-rw-r--r--Library/Homebrew/debrew/irb.rb2
-rw-r--r--Library/Homebrew/dependency.rb2
-rw-r--r--Library/Homebrew/dev-cmd/audit.rb6
-rw-r--r--Library/Homebrew/dev-cmd/bottle.rb6
-rw-r--r--Library/Homebrew/dev-cmd/bump-formula-pr.rb4
-rw-r--r--Library/Homebrew/dev-cmd/pull.rb6
-rw-r--r--Library/Homebrew/dev-cmd/release-notes.rb4
-rw-r--r--Library/Homebrew/diagnostic.rb4
-rw-r--r--Library/Homebrew/exceptions.rb2
-rw-r--r--Library/Homebrew/extend/ARGV.rb4
-rw-r--r--Library/Homebrew/extend/ENV.rb2
-rw-r--r--Library/Homebrew/extend/ENV/std.rb4
-rw-r--r--Library/Homebrew/formula.rb22
-rw-r--r--Library/Homebrew/formula_installer.rb4
-rw-r--r--Library/Homebrew/install_renamed.rb8
-rw-r--r--Library/Homebrew/keg.rb2
-rw-r--r--Library/Homebrew/language/python.rb2
-rw-r--r--Library/Homebrew/locale.rb2
-rw-r--r--Library/Homebrew/options.rb24
-rw-r--r--Library/Homebrew/os/mac.rb4
-rw-r--r--Library/Homebrew/pkg_version.rb2
-rw-r--r--Library/Homebrew/requirements/java_requirement.rb4
-rw-r--r--Library/Homebrew/requirements/ruby_requirement.rb4
-rw-r--r--Library/Homebrew/rubocops/components_order_cop.rb4
-rw-r--r--Library/Homebrew/sandbox.rb2
-rw-r--r--Library/Homebrew/software_spec.rb2
-rw-r--r--Library/Homebrew/tab.rb2
-rw-r--r--Library/Homebrew/tap.rb1
-rw-r--r--Library/Homebrew/utils/github.rb12
-rw-r--r--Library/Homebrew/utils/shell.rb4
47 files changed, 118 insertions, 123 deletions
diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml
index cb065a1a4..dd6e039b0 100644
--- a/Library/.rubocop.yml
+++ b/Library/.rubocop.yml
@@ -1,5 +1,5 @@
AllCops:
- TargetRubyVersion: 2.0
+ TargetRubyVersion: 2.3
Exclude:
- '**/Casks/**/*'
- '**/vendor/**/*'
@@ -119,7 +119,7 @@ Style/Encoding:
Enabled: true
# dashes in filenames are typical
-Style/FileName:
+Naming/FileName:
Regex: !ruby/regexp /^[\w\@\-\+\.]+(\.rb)?$/
# falsely flags e.g. curl formatting arguments as format strings
@@ -189,8 +189,25 @@ Style/TrailingCommaInArguments:
EnforcedStyleForMultiline: comma
# we have too many variables like sha256 where this harms readability
-Style/VariableNumber:
+Naming/VariableNumber:
Enabled: false
Style/WordArray:
MinSize: 4
+
+# we want to add this slowly and manually
+Style/FrozenStringLiteralComment:
+ Enabled: false
+
+# generally rescuing StandardError is fine
+Lint/RescueWithoutErrorClass:
+ Enabled: false
+
+# implicitly allow EOS as we use it everywhere
+Naming/HeredocDelimiterNaming:
+ Blacklist:
+ - END, EOD, EOF
+
+# we output how to use interpolated strings too often
+Lint/InterpolationCheck:
+ Enabled: false
diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml
index 26c944529..dc4406527 100644
--- a/Library/Homebrew/.rubocop.yml
+++ b/Library/Homebrew/.rubocop.yml
@@ -42,12 +42,12 @@ Style/HashSyntax:
EnforcedStyle: ruby19_no_mixed_keys
# we won't change backward compatible method names
-Style/MethodName:
+Naming/MethodName:
Exclude:
- 'compat/**/*'
# we won't change backward compatible predicate names
-Style/PredicateName:
+Naming/PredicateName:
Exclude:
- 'compat/**/*'
NameWhitelist: is_32_bit?, is_64_bit?
diff --git a/Library/Homebrew/.rubocop_todo.yml b/Library/Homebrew/.rubocop_todo.yml
index 37518a5f0..96c2f3676 100644
--- a/Library/Homebrew/.rubocop_todo.yml
+++ b/Library/Homebrew/.rubocop_todo.yml
@@ -81,7 +81,7 @@ Security/MarshalLoad:
- 'utils/fork.rb'
# Offense count: 1
-Style/AccessorMethodName:
+Naming/AccessorMethodName:
Exclude:
- 'extend/ENV/super.rb'
@@ -136,10 +136,3 @@ Style/MutableConstant:
- 'formulary.rb'
- 'tab.rb'
- 'tap.rb'
-
-# Offense count: 8
-Style/OpMethod:
- Exclude:
- - 'dependencies.rb'
- - 'install_renamed.rb'
- - 'options.rb'
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/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb
index 532d9f3c3..8fce9636a 100644
--- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb
+++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb
@@ -56,7 +56,7 @@ module Hbc
class FromURILoader < FromPathLoader
def self.can_load?(ref)
- ref.to_s.match?(::URI.regexp)
+ ref.to_s.match?(::URI::DEFAULT_PARSER.make_regexp)
end
attr_reader :url
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.rb b/Library/Homebrew/cask/lib/hbc/dsl.rb
index 2dda47627..3824b9761 100644
--- a/Library/Homebrew/cask/lib/hbc/dsl.rb
+++ b/Library/Homebrew/cask/lib/hbc/dsl.rb
@@ -161,7 +161,7 @@ module Hbc
begin
DSL::Container.new(*args).tap do |container|
# TODO: remove this backward-compatibility section after removing nested_container
- if container && container.nested
+ if container&.nested
artifacts[:nested_container] << Artifact::NestedContainer.new(cask, container.nested)
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/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb
index b9c34e3a1..01aae935d 100644
--- a/Library/Homebrew/cask/lib/hbc/installer.rb
+++ b/Library/Homebrew/cask/lib/hbc/installer.rb
@@ -159,7 +159,7 @@ module Hbc
odebug "Extracting primary container"
FileUtils.mkdir_p @cask.staged_path
- container = if @cask.container && @cask.container.type
+ container = if @cask.container&.type
Container.from_type(@cask.container.type)
else
Container.for_path(@downloaded_path, @command)
@@ -361,7 +361,7 @@ module Hbc
savedir = @cask.metadata_subdir("Casks", timestamp: :now, create: true)
FileUtils.copy @cask.sourcefile_path, savedir
- old_savedir.rmtree unless old_savedir.nil?
+ old_savedir&.rmtree
end
def uninstall
diff --git a/Library/Homebrew/cask/lib/hbc/system_command.rb b/Library/Homebrew/cask/lib/hbc/system_command.rb
index b735ae4f9..be083c29e 100644
--- a/Library/Homebrew/cask/lib/hbc/system_command.rb
+++ b/Library/Homebrew/cask/lib/hbc/system_command.rb
@@ -61,7 +61,7 @@ module Hbc
end
def assert_success
- return if processed_status && processed_status.success?
+ return if processed_status&.success?
raise CaskCommandFailedError.new(command, processed_output[:stdout], processed_output[:stderr], processed_status)
end
diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb
index 578b292fa..1849ea79b 100644
--- a/Library/Homebrew/caveats.rb
+++ b/Library/Homebrew/caveats.rb
@@ -163,7 +163,7 @@ class Caveats
def plist_caveats
s = []
- if f.plist || (keg && keg.plist_installed?)
+ if f.plist || (keg&.plist_installed?)
plist_domain = f.plist_path.basename(".plist")
# we readlink because this path probably doesn't exist since caveats
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/cmd/unlinkapps.rb b/Library/Homebrew/cmd/unlinkapps.rb
index 7cae97e27..56dba3603 100644
--- a/Library/Homebrew/cmd/unlinkapps.rb
+++ b/Library/Homebrew/cmd/unlinkapps.rb
@@ -77,7 +77,7 @@ module Homebrew
def unlinkapps_unlink?(target_app, opts = {})
# Skip non-symlinks and symlinks that don't point into the Homebrew prefix.
app = target_app.readlink.to_s if target_app.symlink?
- return false unless app && app.start_with?(*UNLINKAPPS_PREFIXES)
+ return false unless app&.start_with?(*UNLINKAPPS_PREFIXES)
if opts.fetch(:prune, false)
!File.exist?(app) # Remove only broken symlinks in prune mode.
diff --git a/Library/Homebrew/constants.rb b/Library/Homebrew/constants.rb
index 23be70bcc..b122946c8 100644
--- a/Library/Homebrew/constants.rb
+++ b/Library/Homebrew/constants.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
# RuboCop version used for `brew style` and `brew cask style`
-HOMEBREW_RUBOCOP_VERSION = "0.49.1".freeze
-HOMEBREW_RUBOCOP_CASK_VERSION = "~> 0.13.1".freeze # has to be updated when RuboCop version changes
+HOMEBREW_RUBOCOP_VERSION = "0.50.0"
+HOMEBREW_RUBOCOP_CASK_VERSION = "~> 0.14.2" # has to be updated when RuboCop version changes
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/debrew/irb.rb b/Library/Homebrew/debrew/irb.rb
index f97403782..069dbe676 100644
--- a/Library/Homebrew/debrew/irb.rb
+++ b/Library/Homebrew/debrew/irb.rb
@@ -16,7 +16,7 @@ module IRB
workspace = WorkSpace.new(binding)
irb = Irb.new(workspace)
- @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
+ @CONF[:IRB_RC]&.call(irb.context)
@CONF[:MAIN_CONTEXT] = irb.context
trap("SIGINT") do
diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb
index d7d5ec59c..0fbc2625b 100644
--- a/Library/Homebrew/dependency.rb
+++ b/Library/Homebrew/dependency.rb
@@ -51,7 +51,7 @@ class Dependency
end
def modify_build_environment
- env_proc.call unless env_proc.nil?
+ env_proc&.call
end
def inspect
diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb
index 743b9484e..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
@@ -707,7 +707,7 @@ class FormulaAuditor
end
stable = formula.stable
- case stable && stable.url
+ case stable&.url
when /[\d\._-](alpha|beta|rc\d)/
matched = Regexp.last_match(1)
version_prefix = stable.version.to_s.sub(/\d+$/, "")
@@ -1018,7 +1018,7 @@ class FormulaAuditor
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&.official?
return unless formula.tap.tap_migrations.key?(formula.name)
problem <<-EOS.undent
diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb
index d8aefc4c0..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
@@ -283,7 +283,7 @@ module Homebrew
raise
ensure
ignore_interrupts do
- original_tab.write if original_tab
+ original_tab&.write
unless ARGV.include? "--skip-relocation"
keg.replace_placeholders_with_locations changed_files
end
diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb
index 521c76302..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")}
@@ -124,7 +124,7 @@ module Homebrew
Formula.each do |f|
if is_devel && f.devel && f.devel.url && f.devel.url.match(base_url)
guesses << f
- elsif f.stable && f.stable.url && f.stable.url.match(base_url)
+ elsif f.stable&.url && f.stable.url.match(base_url)
guesses << f
end
end
diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb
index a8f35531f..cd0d6fbd0 100644
--- a/Library/Homebrew/dev-cmd/pull.rb
+++ b/Library/Homebrew/dev-cmd/pull.rb
@@ -69,13 +69,13 @@ 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
elsif (testing_match = arg.match %r{/job/Homebrew.*Testing/(\d+)/})
tap = ARGV.value("tap")
- tap = if tap && tap.start_with?("homebrew/")
+ tap = if tap&.start_with?("homebrew/")
Tap.fetch("homebrew", tap.strip_prefix("homebrew/"))
elsif tap
odie "Tap option did not start with \"homebrew/\": #{tap}"
@@ -350,7 +350,7 @@ module Homebrew
files << Regexp.last_match(1) if line =~ %r{^\+\+\+ b/(.*)}
end
files.each do |file|
- if tap && tap.formula_file?(file)
+ if tap&.formula_file?(file)
formula_name = File.basename(file, ".rb")
formulae << formula_name unless formulae.include?(formula_name)
else
diff --git a/Library/Homebrew/dev-cmd/release-notes.rb b/Library/Homebrew/dev-cmd/release-notes.rb
index e578869bf..496023956 100644
--- a/Library/Homebrew/dev-cmd/release-notes.rb
+++ b/Library/Homebrew/dev-cmd/release-notes.rb
@@ -10,10 +10,8 @@ module Homebrew
def release_notes
previous_tag = ARGV.named.first
- unless previous_tag
- previous_tag = Utils.popen_read("git tag --list --sort=-version:refname")
+ previous_tag ||= Utils.popen_read("git tag --list --sort=-version:refname")
.lines.first.chomp
- end
odie "Could not find any previous tags!" unless previous_tag
end_ref = ARGV.named[1] || "origin/master"
diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb
index ceb6ad4d1..88aa4dbc9 100644
--- a/Library/Homebrew/diagnostic.rb
+++ b/Library/Homebrew/diagnostic.rb
@@ -522,7 +522,7 @@ module Homebrew
homebrew_owned = @found.all? do |path|
Pathname.new(path).realpath.to_s.start_with? "#{HOMEBREW_CELLAR}/gettext"
end
- return if gettext && gettext.linked_keg.directory? && homebrew_owned
+ return if gettext&.linked_keg&.directory? && homebrew_owned
inject_file_list @found, <<-EOS.undent
gettext files detected at a system prefix.
@@ -540,7 +540,7 @@ module Homebrew
rescue
nil
end
- if libiconv && libiconv.linked_keg.directory?
+ if libiconv&.linked_keg&.directory?
unless libiconv.keg_only?
<<-EOS.undent
A libiconv formula is installed and linked.
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/ARGV.rb b/Library/Homebrew/extend/ARGV.rb
index daa5306fa..63a0f3e40 100644
--- a/Library/Homebrew/extend/ARGV.rb
+++ b/Library/Homebrew/extend/ARGV.rb
@@ -144,7 +144,7 @@ module HomebrewArgvExtension
def value(name)
arg_prefix = "--#{name}="
flag_with_value = find { |arg| arg.start_with?(arg_prefix) }
- flag_with_value.strip_prefix(arg_prefix) if flag_with_value
+ flag_with_value&.strip_prefix(arg_prefix)
end
# Returns an array of values that were given as a comma-separated list.
@@ -236,7 +236,7 @@ module HomebrewArgvExtension
def bottle_arch
arch = value "bottle-arch"
- arch.to_sym if arch
+ arch&.to_sym
end
def build_from_source?
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 2f0c913c2..d999b9c5f 100644
--- a/Library/Homebrew/formula.rb
+++ b/Library/Homebrew/formula.rb
@@ -472,7 +472,7 @@ class Formula
return true if devel && tab.devel_version && tab.devel_version < devel.version
if options[:fetch_head]
- return false unless head && head.downloader.is_a?(VCSDownloadStrategy)
+ return false unless head&.downloader.is_a?(VCSDownloadStrategy)
downloader = head.downloader
downloader.shutup! unless ARGV.verbose?
downloader.commit_outdated?(version.version.commit)
@@ -1115,8 +1115,8 @@ class Formula
# @private
def unlock
- @lock.unlock unless @lock.nil?
- @oldname_lock.unlock unless @oldname_lock.nil?
+ @lock&.unlock
+ @oldname_lock&.unlock
end
def migration_needed?
@@ -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?
@@ -1440,13 +1441,14 @@ class Formula
# True if this formula is provided by Homebrew itself
# @private
def core_formula?
- tap && tap.core_tap?
+ tap&.core_tap?
end
# 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
@@ -1525,10 +1527,10 @@ class Formula
"oldname" => oldname,
"aliases" => aliases,
"versions" => {
- "stable" => (stable.version.to_s if stable),
+ "stable" => stable&.version.to_s,
"bottle" => bottle ? true : false,
- "devel" => (devel.version.to_s if devel),
- "head" => (head.version.to_s if head),
+ "devel" => devel&.version.to_s,
+ "head" => head&.version.to_s,
},
"revision" => revision,
"version_scheme" => version_scheme,
@@ -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 e955dcf07..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)
@@ -560,7 +560,7 @@ class FormulaInstaller
end
raise
else
- ignore_interrupts { tmp_keg.rmtree if tmp_keg && tmp_keg.directory? }
+ ignore_interrupts { tmp_keg.rmtree if tmp_keg&.directory? }
end
def caveats
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/keg.rb b/Library/Homebrew/keg.rb
index 92eab7ad3..677a97c85 100644
--- a/Library/Homebrew/keg.rb
+++ b/Library/Homebrew/keg.rb
@@ -338,7 +338,7 @@ class Keg
dir if dir.directory? && dir.children.any? { |f| f.basename.to_s.start_with?("_") }
when :fish then path/"share/fish/vendor_completions.d"
end
- dir && dir.directory? && !dir.children.empty?
+ dir&.directory? && !dir.children.empty?
end
def functions_installed?(shell)
diff --git a/Library/Homebrew/language/python.rb b/Library/Homebrew/language/python.rb
index 0f8e3a4e6..bfec556d0 100644
--- a/Library/Homebrew/language/python.rb
+++ b/Library/Homebrew/language/python.rb
@@ -23,7 +23,7 @@ module Language
else
homebrew_site_packages(version)
end
- block.call python, version if block
+ block&.call python, version
end
ENV["PYTHONPATH"] = original_pythonpath
end
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/os/mac.rb b/Library/Homebrew/os/mac.rb
index 52fa2a187..15c301f99 100644
--- a/Library/Homebrew/os/mac.rb
+++ b/Library/Homebrew/os/mac.rb
@@ -11,7 +11,7 @@ module OS
module Mac
module_function
- ::MacOS = self # rubocop:disable Style/ConstantName
+ ::MacOS = self # rubocop:disable Naming/ConstantName
raise "Loaded OS::Mac on generic OS!" if ENV["HOMEBREW_TEST_GENERIC_OS"]
@@ -104,7 +104,7 @@ module OS
# Returns the path to an SDK or nil, following the rules set by #sdk.
def sdk_path(v = nil)
s = sdk(v)
- s.path unless s.nil?
+ s&.path
end
# See these issues for some history:
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/requirements/java_requirement.rb b/Library/Homebrew/requirements/java_requirement.rb
index ab6dca51d..de3a33eb4 100644
--- a/Library/Homebrew/requirements/java_requirement.rb
+++ b/Library/Homebrew/requirements/java_requirement.rb
@@ -69,14 +69,14 @@ class JavaRequirement < Requirement
rescue FormulaUnavailableError
nil
end
- javas << jdk.bin/"java" if jdk && jdk.installed?
+ javas << jdk.bin/"java" if jdk&.installed?
javas << which("java")
javas
end
def preferred_java
possible_javas.detect do |java|
- next false unless java && java.executable?
+ next false unless java&.executable?
next true unless @version
next true if satisfies_version(java)
end
diff --git a/Library/Homebrew/requirements/ruby_requirement.rb b/Library/Homebrew/requirements/ruby_requirement.rb
index acc655924..a9ec8c42d 100644
--- a/Library/Homebrew/requirements/ruby_requirement.rb
+++ b/Library/Homebrew/requirements/ruby_requirement.rb
@@ -41,9 +41,7 @@ class RubyRequirement < Requirement
def rubies
rubies = which_all("ruby")
ruby_formula = Formula["ruby"]
- if ruby_formula && ruby_formula.installed?
- rubies.unshift ruby_formula.bin/"ruby"
- end
+ rubies.unshift ruby_formula.bin/"ruby" if ruby_formula&.installed?
rubies.uniq
end
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/sandbox.rb b/Library/Homebrew/sandbox.rb
index 8c662857e..7d23e5966 100644
--- a/Library/Homebrew/sandbox.rb
+++ b/Library/Homebrew/sandbox.rb
@@ -167,7 +167,7 @@ class Sandbox
def add_rule(rule)
s = "("
- s << ((rule[:allow]) ? "allow" : "deny")
+ s << (rule[:allow] ? "allow" : "deny")
s << " #{rule[:operation]}"
s << " (#{rule[:filter]})" if rule[:filter]
s << " (with #{rule[:modifier]})" if rule[:modifier]
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/tab.rb b/Library/Homebrew/tab.rb
index e7df88356..af19cabe6 100644
--- a/Library/Homebrew/tab.rb
+++ b/Library/Homebrew/tab.rb
@@ -324,7 +324,7 @@ class Tab < OpenStruct
"poured_from_bottle" => poured_from_bottle,
"installed_as_dependency" => installed_as_dependency,
"installed_on_request" => installed_on_request,
- "changed_files" => changed_files && changed_files.map(&:to_s),
+ "changed_files" => changed_files&.map(&:to_s),
"time" => time,
"source_modified_time" => source_modified_time.to_i,
"HEAD" => self.HEAD,
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