Merge pull request #2767 from MikeMcQuaid/rubocop-no-special-global-vars

rubocop: don’t allow special global variables.
This commit is contained in:
Mike McQuaid 2017-06-12 16:16:37 +01:00 committed by GitHub
commit 22c431d221
23 changed files with 30 additions and 35 deletions

View File

@ -183,10 +183,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

View File

@ -10,7 +10,8 @@ raise "Homebrew must be run under Ruby 2!" unless RUBY_TWO
require "pathname"
HOMEBREW_LIBRARY_PATH = Pathname.new(__FILE__).realpath.parent
$:.unshift(HOMEBREW_LIBRARY_PATH.to_s)
require "English"
$LOAD_PATH.unshift(HOMEBREW_LIBRARY_PATH.to_s)
require "global"
require "tap"

View File

@ -1,5 +1,3 @@
require "English"
module Hbc
class CLI
class Style < AbstractCommand

View File

@ -112,7 +112,7 @@ module Homebrew
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

View File

@ -265,10 +265,10 @@ module Homebrew
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)

View File

@ -459,7 +459,7 @@ module Homebrew
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])

View File

@ -111,7 +111,7 @@ module Homebrew
system "bundle", "exec", "rspec", *args, "--", *files
end
return if $?.success?
return if $CHILD_STATUS.success?
Homebrew.failed = true
end
end

View File

@ -338,7 +338,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
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

View File

@ -271,7 +271,7 @@ module Homebrew
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.

View File

@ -23,7 +23,7 @@ class JavaRequirement < Requirement
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

View File

@ -1836,7 +1836,7 @@ class Formula
$stdout.flush
unless $?.success?
unless $CHILD_STATUS.success?
log_lines = ENV["HOMEBREW_FAIL_LOG_LINES"]
log_lines ||= "15"

View File

@ -27,7 +27,7 @@ module Homebrew
def shell_output(cmd, result = 0)
ohai cmd
output = `#{cmd}`
assert_equal result, $?.exitstatus
assert_equal result, $CHILD_STATUS.exitstatus
output
end
@ -40,7 +40,7 @@ module Homebrew
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

View File

@ -96,7 +96,7 @@ module Formulary
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
@ -258,7 +258,7 @@ module Formulary
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

View File

@ -12,6 +12,7 @@ require "set"
require "rbconfig"
require "official_taps"
require "pp"
require "English"
ARGV.extend(HomebrewArgvExtension)

View File

@ -11,7 +11,7 @@ module Language
# 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

View File

@ -118,7 +118,7 @@ module OS
].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

View File

@ -68,7 +68,7 @@ class EmbeddedPatch
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

View File

@ -82,7 +82,7 @@ module Readall
# 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

View File

@ -128,7 +128,7 @@ class SystemConfig
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

View File

@ -1,4 +1,3 @@
require "English"
require "open3"
require "rubygems"

View File

@ -4,7 +4,7 @@ describe Utils do
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
@ -13,7 +13,7 @@ describe Utils do
pipe.read.chomp
end,
).to eq("success")
expect($?).to be_a_success
expect($CHILD_STATUS).to be_a_success
end
end
@ -22,7 +22,7 @@ describe Utils do
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

View File

@ -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
@ -171,7 +171,7 @@ module Homebrew
exit! 1 # never gets here unless exec failed
end
Process.wait(pid)
$?.success?
$CHILD_STATUS.success?
end
def system(cmd, *args)

View File

@ -37,8 +37,8 @@ module Utils
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