RuboCop 0.53.0 manual fixes.

This commit is contained in:
Mike McQuaid 2018-03-07 16:14:55 +00:00
parent e03f07f302
commit 83cca40fc9
13 changed files with 28 additions and 24 deletions

View File

@ -1,3 +1,5 @@
require "uri"
module Hbc
module CaskLoader
class FromContentLoader

View File

@ -113,14 +113,14 @@ module Homebrew
url = "https://api.github.com/gists"
data = { "public" => true, "files" => files, "description" => description }
scopes = GitHub::CREATE_GIST_SCOPES
GitHub.open(url, data: data, scopes: scopes)["html_url"]
GitHub.open_api(url, data: data, scopes: scopes)["html_url"]
end
def create_issue(repo, title, body)
url = "https://api.github.com/repos/#{repo}/issues"
data = { "title" => title, "body" => body }
scopes = GitHub::CREATE_ISSUE_SCOPES
GitHub.open(url, data: data, scopes: scopes)["html_url"]
GitHub.open_api(url, data: data, scopes: scopes)["html_url"]
end
def gist_logs

View File

@ -13,7 +13,7 @@ module Homebrew
module_function
def update_preinstall_header
@header_already_printed ||= begin
@update_preinstall_header ||= begin
ohai "Auto-updated Homebrew!" if ARGV.include?("--preinstall")
true
end

View File

@ -604,7 +604,7 @@ class GitHubPrivateRepositoryReleaseDownloadStrategy < GitHubPrivateRepositoryDo
def fetch_release_metadata
release_url = "https://api.github.com/repos/#{@owner}/#{@repo}/releases/tags/#{@tag}"
GitHub.open(release_url)
GitHub.open_api(release_url)
end
end

View File

@ -4,6 +4,8 @@ require_relative "../../extend/string"
module RuboCop
module Cop
class FormulaCop < Cop
include RangeHelp
attr_accessor :file_path
@registry = Cop.registry

View File

@ -108,10 +108,10 @@ class Sandbox
unless logs.empty?
if @logfile
log = open(@logfile, "w")
log.write logs
log.write "\nWe use time to filter sandbox log. Therefore, unrelated logs may be recorded.\n"
log.close
File.open(@logfile, "w") do |log|
log.write logs
log.write "\nWe use time to filter sandbox log. Therefore, unrelated logs may be recorded.\n"
end
end
if @failed && ARGV.verbose?

View File

@ -16,7 +16,7 @@ describe Homebrew do
],
}
allow(GitHub).to receive(:open).and_yield(json_response)
allow(GitHub).to receive(:open_api).and_yield(json_response)
expect(described_class.search_taps("some-formula"))
.to match(["homebrew/foo/some-formula"])

View File

@ -116,7 +116,7 @@ describe GitHubPrivateRepositoryReleaseDownloadStrategy do
describe "#fetch_release_metadata" do
it "fetches release metadata from GitHub" do
expected_release_url = "https://api.github.com/repos/owner/repo/releases/tags/tag"
expect(GitHub).to receive(:open).with(expected_release_url).and_return({})
expect(GitHub).to receive(:open_api).with(expected_release_url).and_return({})
subject.send(:fetch_release_metadata)
end
end

View File

@ -3,9 +3,9 @@ require "formula_installer"
describe Utils::Analytics do
describe "::os_prefix_ci" do
context "when anonymous_os_prefix_ci is not set" do
context "when os_prefix_ci is not set" do
before(:each) do
described_class.clear_anonymous_os_prefix_ci_cache
described_class.clear_os_prefix_ci
end
it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is not /usr/local" do

View File

@ -3,13 +3,13 @@ require "erb"
module Utils
module Analytics
class << self
def clear_anonymous_os_prefix_ci_cache
return unless instance_variable_defined?(:@anonymous_os_prefix_ci)
remove_instance_variable(:@anonymous_os_prefix_ci)
def clear_os_prefix_ci
return unless instance_variable_defined?(:@os_prefix_ci)
remove_instance_variable(:@os_prefix_ci)
end
def os_prefix_ci
@anonymous_os_prefix_ci ||= begin
@os_prefix_ci ||= begin
os = OS_VERSION
prefix = ", non-/usr/local" if HOMEBREW_PREFIX.to_s != "/usr/local"
ci = ", CI" if ENV["CI"]

View File

@ -5,7 +5,7 @@ module Utils
class Bottles
class << self
def tag
@bottle_tag ||= "#{ENV["HOMEBREW_PROCESSOR"]}_#{ENV["HOMEBREW_SYSTEM"]}".downcase.to_sym
@tag ||= "#{ENV["HOMEBREW_PROCESSOR"]}_#{ENV["HOMEBREW_SYSTEM"]}".downcase.to_sym
end
def built_as?(f)

View File

@ -27,7 +27,7 @@ end
module Utils
def self.git_available?
@git ||= quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version"
@git_available ||= quiet_system HOMEBREW_SHIMS_PATH/"scm/git", "--version"
end
def self.git_path
@ -61,7 +61,7 @@ module Utils
end
def self.clear_git_available_cache
@git = nil
@git_available = nil
@git_path = nil
@git_version = nil
end

View File

@ -94,7 +94,7 @@ module GitHub
def api_credentials_error_message(response_headers, needed_scopes)
return if response_headers.empty?
@api_credentials_error_message_printed ||= begin
@api_credentials_error_message ||= begin
unauthorized = (response_headers["http/1.1"] == "401 Unauthorized")
scopes = response_headers["x-accepted-oauth-scopes"].to_s.split(", ")
needed_human_scopes = needed_scopes.join(", ")
@ -125,7 +125,7 @@ module GitHub
end
end
def open(url, data: nil, scopes: [].freeze)
def open_api(url, data: nil, scopes: [].freeze)
# This is a no-op if the user is opting out of using the GitHub API.
return block_given? ? yield({}) : {} if ENV["HOMEBREW_NO_GITHUB_API"]
@ -226,7 +226,7 @@ module GitHub
end
def repository(user, repo)
open(url_to("repos", user, repo))
open_api(url_to("repos", user, repo))
end
def search_code(**qualifiers)
@ -255,7 +255,7 @@ module GitHub
def private_repo?(full_name)
uri = url_to "repos", full_name
open(uri) { |json| json["private"] }
open_api(uri) { |json| json["private"] }
end
def query_string(*main_params, **qualifiers)
@ -275,6 +275,6 @@ module GitHub
def search(entity, *queries, **qualifiers)
uri = url_to "search", entity
uri.query = query_string(*queries, **qualifiers)
open(uri) { |json| json.fetch("items", []) }
open_api(uri) { |json| json.fetch("items", []) }
end
end