Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rubocop: don’t allow special global variables. #2767

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 0 additions & 4 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,6 @@ Style/RaiseArgs:
Style/RegexpLiteral:
EnforcedStyle: slashes

# not a problem for typical shell users
Style/SpecialGlobalVars:
Enabled: false

# ruby style guide favorite
Style/StringLiterals:
EnforcedStyle: double_quotes
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@

require "pathname"
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent
$:.unshift(HOMEBREW_LIBRARY_PATH.to_s)
require "English"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are probably requiring this somewhere else down the line, these can be removed now that we have it at the very beginning.

$LOAD_PATH.unshift(HOMEBREW_LIBRARY_PATH.to_s)
require "global"
require "tap"

Expand Down
2 changes: 0 additions & 2 deletions Library/Homebrew/cask/lib/hbc/cli/style.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
require "English"

module Hbc
class CLI
class Style < AbstractCommand
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cmd/style.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def check_style_impl(files, output_type, options = {})
args << "--display-cop-names" if ARGV.include? "--display-cop-names"
args << "--format" << "simple" if files
system(cache_env, "rubocop", *args)
!$?.success?
!$CHILD_STATUS.success?
when :json
json, _, status = Open3.capture3(cache_env, "rubocop", "--format", "json", *args)
# exit status of 1 just means violations were found; other numbers mean
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dev-cmd/bump-formula-pr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,10 +265,10 @@ def bump_formula_pr
failed_audit = false
if ARGV.include? "--strict"
system HOMEBREW_BREW_FILE, "audit", "--strict", formula.path
failed_audit = !$?.success?
failed_audit = !$CHILD_STATUS.success?
elsif ARGV.include? "--audit"
system HOMEBREW_BREW_FILE, "audit", formula.path
failed_audit = !$?.success?
failed_audit = !$CHILD_STATUS.success?
end
if failed_audit
formula.path.atomic_write(backup_file)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/pull.rb
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ def initialize(info)
def self.lookup(name)
json = Utils.popen_read(HOMEBREW_BREW_FILE, "info", "--json=v1", name)

return nil unless $?.success?
return nil unless $CHILD_STATUS.success?

Homebrew.force_utf8!(json)
FormulaInfoFromJson.new(JSON.parse(json)[0])
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/tests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def tests
system "bundle", "exec", "rspec", *args, "--", *files
end

return if $?.success?
return if $CHILD_STATUS.success?
Homebrew.failed = true
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def fetch
rescue ErrorDuringExecution
# 33 == range not supported
# try wiping the incomplete download and retrying once
unless $?.exitstatus == 33 && had_incomplete_download
unless $CHILD_STATUS.exitstatus == 33 && had_incomplete_download
raise CurlDownloadStrategyError, @url
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/extend/os/mac/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def check_for_unsupported_curl_vars
def check_xcode_license_approved
# If the user installs Xcode-only, they have to approve the
# license or no "xc*" tool will work.
return unless `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$?.success?
return unless `/usr/bin/xcrun clang 2>&1` =~ /license/ && !$CHILD_STATUS.success?

<<-EOS.undent
You have not agreed to the Xcode license.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def java_home_cmd
args = %w[--failfast]
args << "--version" << @version.to_s if @version
java_home = Utils.popen_read("/usr/libexec/java_home", *args).chomp
return nil unless $?.success?
return nil unless $CHILD_STATUS.success?
Pathname.new(java_home)/"bin/java"
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1836,7 +1836,7 @@ def system(cmd, *args)

$stdout.flush

unless $?.success?
unless $CHILD_STATUS.success?
log_lines = ENV["HOMEBREW_FAIL_LOG_LINES"]
log_lines ||= "15"

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/formula_assertions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ module Assertions
def shell_output(cmd, result = 0)
ohai cmd
output = `#{cmd}`
assert_equal result, $?.exitstatus
assert_equal result, $CHILD_STATUS.exitstatus
output
end

Expand All @@ -40,7 +40,7 @@ def pipe_output(cmd, input = nil, result = nil)
pipe.close_write
pipe.read
end
assert_equal result, $?.exitstatus unless result.nil?
assert_equal result, $CHILD_STATUS.exitstatus unless result.nil?
output
end
end
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def klass
private

def load_file
$stderr.puts "#{$0} (#{self.class.name}): loading #{path}" if ARGV.debug?
$stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if ARGV.debug?
raise FormulaUnavailableError, name unless path.file?
Formulary.load_formula_from_path(name, path)
end
Expand Down Expand Up @@ -258,7 +258,7 @@ def initialize(name, path, contents)
end

def klass
$stderr.puts "#{$0} (#{self.class.name}): loading #{path}" if ARGV.debug?
$stderr.puts "#{$PROGRAM_NAME} (#{self.class.name}): loading #{path}" if ARGV.debug?
namespace = "FormulaNamespace#{Digest::MD5.hexdigest(contents)}"
Formulary.load_formula(name, path, contents, namespace)
end
Expand Down
1 change: 1 addition & 0 deletions Library/Homebrew/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
require "rbconfig"
require "official_taps"
require "pp"
require "English"

ARGV.extend(HomebrewArgvExtension)

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/language/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def self.pack_for_installation
# directory, consequently breaking that assumption. We require a tarball
# because npm install creates a "real" installation when fed a tarball.
output = Utils.popen_read("npm pack").chomp
raise "npm failed to pack #{Dir.pwd}" unless $?.exitstatus.zero?
raise "npm failed to pack #{Dir.pwd}" unless $CHILD_STATUS.exitstatus.zero?
output
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/os/mac/xcode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def uncached_version
].uniq.each do |xcodebuild_path|
next unless File.executable? xcodebuild_path
xcodebuild_output = Utils.popen_read(xcodebuild_path, "-version")
next unless $?.success?
next unless $CHILD_STATUS.success?

xcode_version = xcodebuild_output[/Xcode (\d(\.\d)*)/, 1]
return xcode_version if xcode_version
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def apply
cmd = "/usr/bin/patch"
args = %W[-g 0 -f -#{strip}]
IO.popen("#{cmd} #{args.join(" ")}", "w") { |p| p.write(data) }
raise ErrorDuringExecution.new(cmd, args) unless $?.success?
raise ErrorDuringExecution.new(cmd, args) unless $CHILD_STATUS.success?
end

def inspect
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/readall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def syntax_errors_or_warnings?(rb)

# Only syntax errors result in a non-zero status code. To detect syntax
# warnings we also need to inspect the output to `$stderr`.
!$?.success? || !messages.chomp.empty?
!$CHILD_STATUS.success? || !messages.chomp.empty?
end
end
end
2 changes: 1 addition & 1 deletion Library/Homebrew/system_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def describe_java
return "N/A" unless File.executable? "/usr/libexec/java_home"

java_xml = Utils.popen_read("/usr/libexec/java_home", "--xml", "--failfast")
return "N/A" unless $?.success?
return "N/A" unless $CHILD_STATUS.success?
javas = []
REXML::XPath.each(REXML::Document.new(java_xml), "//key[text()='JVMVersion']/following-sibling::string") do |item|
javas << item.text
Expand Down
1 change: 0 additions & 1 deletion Library/Homebrew/test/cask/cli/style_spec.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
require "English"
require "open3"
require "rubygems"

Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/test/utils/popen_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
describe "::popen_read" do
it "reads the standard output of a given command" do
expect(subject.popen_read("sh", "-c", "echo success").chomp).to eq("success")
expect($?).to be_a_success
expect($CHILD_STATUS).to be_a_success
end

it "can be given a block to manually read from the pipe" do
Expand All @@ -13,7 +13,7 @@
pipe.read.chomp
end,
).to eq("success")
expect($?).to be_a_success
expect($CHILD_STATUS).to be_a_success
end
end

Expand All @@ -22,7 +22,7 @@
subject.popen_write("grep", "-q", "success") do |pipe|
pipe.write("success\n")
end
expect($?).to be_a_success
expect($CHILD_STATUS).to be_a_success
end
end
end
8 changes: 4 additions & 4 deletions Library/Homebrew/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ def interactive_shell(f = nil)

Process.wait fork { exec ENV["SHELL"] }

return if $?.success?
raise "Aborted due to non-zero exit status (#{$?.exitstatus})" if $?.exited?
raise $?.inspect
return if $CHILD_STATUS.success?
raise "Aborted due to non-zero exit status (#{$CHILD_STATUS.exitstatus})" if $CHILD_STATUS.exited?
raise $CHILD_STATUS.inspect
end

module Homebrew
Expand All @@ -171,7 +171,7 @@ def _system(cmd, *args)
exit! 1 # never gets here unless exec failed
end
Process.wait(pid)
$?.success?
$CHILD_STATUS.success?
end

def system(cmd, *args)
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/utils/fork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ def self.safe_fork(&_block)
read.close
Process.wait(pid) unless socket.nil?
raise Marshal.load(data) unless data.nil? || data.empty?
raise Interrupt if $?.exitstatus == 130
raise "Suspicious failure" unless $?.success?
raise Interrupt if $CHILD_STATUS.exitstatus == 130
raise "Suspicious failure" unless $CHILD_STATUS.success?
end
end
end
Expand Down