diff options
| author | Mike McQuaid | 2016-09-12 08:09:00 +0100 |
|---|---|---|
| committer | GitHub | 2016-09-12 08:09:00 +0100 |
| commit | 9a6999c30276a05c0bfc89f03b91dea4371ed407 (patch) | |
| tree | 80c15a5d370974edf5ed89e8b6b63c3f3045ebd2 /Library/Homebrew/utils | |
| parent | b93b60e6ca3d609267fd20f35c63527552f10f19 (diff) | |
| parent | 94f763e9c7c7efa1a22a28a2d4c74fa5fcbe4771 (diff) | |
| download | brew-9a6999c30276a05c0bfc89f03b91dea4371ed407.tar.bz2 | |
Merge pull request #925 from MikeMcQuaid/utils-rubocop
Fix Library/Homebrew/utils RuboCop warnings
Diffstat (limited to 'Library/Homebrew/utils')
| -rw-r--r-- | Library/Homebrew/utils/curl.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/utils/github.rb | 14 | ||||
| -rw-r--r-- | Library/Homebrew/utils/hash.rb | 4 | ||||
| -rw-r--r-- | Library/Homebrew/utils/inreplace.rb | 8 | ||||
| -rw-r--r-- | Library/Homebrew/utils/shell.rb | 6 |
5 files changed, 20 insertions, 16 deletions
diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 68474c976..00c3a591c 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -1,7 +1,7 @@ require "pathname" require "open3" -def curl_args(extra_args=[]) +def curl_args(extra_args = []) curl = Pathname.new ENV["HOMEBREW_CURL"] curl = Pathname.new "/usr/bin/curl" unless curl.exist? raise "#{curl} is not executable" unless curl.exist? && curl.executable? @@ -9,7 +9,7 @@ def curl_args(extra_args=[]) flags = HOMEBREW_CURL_ARGS flags -= ["--progress-bar"] if ARGV.verbose? - args = ["#{curl}"] + flags + extra_args + args = [curl.to_s] + flags + extra_args args << "--verbose" if ENV["HOMEBREW_CURL_VERBOSE"] args << "--silent" if !$stdout.tty? || ENV["TRAVIS"] args diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index fce89f1af..d3f304122 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -121,7 +121,7 @@ module GitHub end end - def open(url, data=nil) + def open(url, data = nil) # This is a no-op if the user is opting out of using the GitHub API. return if ENV["HOMEBREW_NO_GITHUB_API"] @@ -154,7 +154,7 @@ module GitHub args += ["--data", "@#{data_tmpfile.path}"] end - args += ["--dump-header", "#{headers_tmpfile.path}"] + args += ["--dump-header", headers_tmpfile.path.to_s] output, errors, status = curl_output(url.to_s, *args) output, _, http_code = output.rpartition("\n") @@ -203,11 +203,15 @@ module GitHub case http_code when "401", "403" - raise AuthenticationFailedError.new(output) + raise AuthenticationFailedError, output when "404" raise HTTPNotFoundError, output else - error = Utils::JSON.load(output)["message"] rescue nil + error = begin + Utils::JSON.load(output)["message"] + rescue + nil + end error ||= "curl failed! #{errors}" raise Error, error end @@ -232,7 +236,7 @@ module GitHub def build_search_qualifier_string(qualifiers) { :repo => "Homebrew/homebrew-core", - :in => "title" + :in => "title", }.update(qualifiers).map do |qualifier, value| "#{qualifier}:#{value}" end.join("+") diff --git a/Library/Homebrew/utils/hash.rb b/Library/Homebrew/utils/hash.rb index 63dd02c1a..2281ce311 100644 --- a/Library/Homebrew/utils/hash.rb +++ b/Library/Homebrew/utils/hash.rb @@ -1,6 +1,6 @@ def deep_merge_hashes(hash1, hash2) - merger = proc do |key, v1, v2| - if Hash === v1 && Hash === v2 + merger = proc do |_key, v1, v2| + if v1.is_a?(Hash) && v2.is_a?(Hash) v1.merge v2, &merger else v2 diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 9978b02fe..c7557ab41 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -1,9 +1,9 @@ module Utils class InreplaceError < RuntimeError def initialize(errors) - super errors.inject("inreplace failed\n") { |s, (path, errs)| + super errors.inject("inreplace failed\n") do |s, (path, errs)| s << "#{path}:\n" << errs.map { |e| " #{e}\n" }.join - } + end end end @@ -24,7 +24,7 @@ module Utils if before.nil? && after.nil? yield s else - after = after.to_s if Symbol === after + after = after.to_s if after.is_a? Symbol s.gsub!(before, after, audit_result) end @@ -33,7 +33,7 @@ module Utils Pathname(path).atomic_write(s) end - raise InreplaceError.new(errors) unless errors.empty? + raise InreplaceError, errors unless errors.empty? end module_function :inreplace end diff --git a/Library/Homebrew/utils/shell.rb b/Library/Homebrew/utils/shell.rb index c1a8f95b7..7f749186f 100644 --- a/Library/Homebrew/utils/shell.rb +++ b/Library/Homebrew/utils/shell.rb @@ -10,7 +10,7 @@ module Utils }.freeze module Shell - UNSAFE_SHELL_CHAR = /([^A-Za-z0-9_\-.,:\/@\n])/ + UNSAFE_SHELL_CHAR = %r{([^A-Za-z0-9_\-.,:/@\n])} # take a path and heuristically convert it # to a shell name, return nil if there's no match @@ -45,7 +45,7 @@ module Utils str end module_function :csh_quote - + def sh_quote(str) # ruby's implementation of shell_escape str = str.to_s @@ -81,7 +81,7 @@ module Utils module_function :shell_profile def prepend_path_in_shell_profile(path) - case preferred_shell + case preferred_shell when :bash, :ksh, :sh, :zsh, nil "echo 'export PATH=\"#{sh_quote(path)}:$PATH\"' >> #{shell_profile}" when :csh, :tcsh |
