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 Hbc
module CaskLoader module CaskLoader
class FromContentLoader class FromContentLoader

View File

@ -113,14 +113,14 @@ module Homebrew
url = "https://api.github.com/gists" url = "https://api.github.com/gists"
data = { "public" => true, "files" => files, "description" => description } data = { "public" => true, "files" => files, "description" => description }
scopes = GitHub::CREATE_GIST_SCOPES 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 end
def create_issue(repo, title, body) def create_issue(repo, title, body)
url = "https://api.github.com/repos/#{repo}/issues" url = "https://api.github.com/repos/#{repo}/issues"
data = { "title" => title, "body" => body } data = { "title" => title, "body" => body }
scopes = GitHub::CREATE_ISSUE_SCOPES 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 end
def gist_logs def gist_logs

View File

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

View File

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

View File

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

View File

@ -108,10 +108,10 @@ class Sandbox
unless logs.empty? unless logs.empty?
if @logfile if @logfile
log = open(@logfile, "w") File.open(@logfile, "w") do |log|
log.write logs log.write logs
log.write "\nWe use time to filter sandbox log. Therefore, unrelated logs may be recorded.\n" log.write "\nWe use time to filter sandbox log. Therefore, unrelated logs may be recorded.\n"
log.close end
end end
if @failed && ARGV.verbose? 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")) expect(described_class.search_taps("some-formula"))
.to match(["homebrew/foo/some-formula"]) .to match(["homebrew/foo/some-formula"])

View File

@ -116,7 +116,7 @@ describe GitHubPrivateRepositoryReleaseDownloadStrategy do
describe "#fetch_release_metadata" do describe "#fetch_release_metadata" do
it "fetches release metadata from GitHub" do it "fetches release metadata from GitHub" do
expected_release_url = "https://api.github.com/repos/owner/repo/releases/tags/tag" 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) subject.send(:fetch_release_metadata)
end end
end end

View File

@ -3,9 +3,9 @@ require "formula_installer"
describe Utils::Analytics do describe Utils::Analytics do
describe "::os_prefix_ci" 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 before(:each) do
described_class.clear_anonymous_os_prefix_ci_cache described_class.clear_os_prefix_ci
end end
it "returns OS_VERSION and prefix when HOMEBREW_PREFIX is not /usr/local" do 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 Utils
module Analytics module Analytics
class << self class << self
def clear_anonymous_os_prefix_ci_cache def clear_os_prefix_ci
return unless instance_variable_defined?(:@anonymous_os_prefix_ci) return unless instance_variable_defined?(:@os_prefix_ci)
remove_instance_variable(:@anonymous_os_prefix_ci) remove_instance_variable(:@os_prefix_ci)
end end
def os_prefix_ci def os_prefix_ci
@anonymous_os_prefix_ci ||= begin @os_prefix_ci ||= begin
os = OS_VERSION os = OS_VERSION
prefix = ", non-/usr/local" if HOMEBREW_PREFIX.to_s != "/usr/local" prefix = ", non-/usr/local" if HOMEBREW_PREFIX.to_s != "/usr/local"
ci = ", CI" if ENV["CI"] ci = ", CI" if ENV["CI"]

View File

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

View File

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

View File

@ -94,7 +94,7 @@ module GitHub
def api_credentials_error_message(response_headers, needed_scopes) def api_credentials_error_message(response_headers, needed_scopes)
return if response_headers.empty? return if response_headers.empty?
@api_credentials_error_message_printed ||= begin @api_credentials_error_message ||= begin
unauthorized = (response_headers["http/1.1"] == "401 Unauthorized") unauthorized = (response_headers["http/1.1"] == "401 Unauthorized")
scopes = response_headers["x-accepted-oauth-scopes"].to_s.split(", ") scopes = response_headers["x-accepted-oauth-scopes"].to_s.split(", ")
needed_human_scopes = needed_scopes.join(", ") needed_human_scopes = needed_scopes.join(", ")
@ -125,7 +125,7 @@ module GitHub
end end
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. # 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"] return block_given? ? yield({}) : {} if ENV["HOMEBREW_NO_GITHUB_API"]
@ -226,7 +226,7 @@ module GitHub
end end
def repository(user, repo) def repository(user, repo)
open(url_to("repos", user, repo)) open_api(url_to("repos", user, repo))
end end
def search_code(**qualifiers) def search_code(**qualifiers)
@ -255,7 +255,7 @@ module GitHub
def private_repo?(full_name) def private_repo?(full_name)
uri = url_to "repos", full_name uri = url_to "repos", full_name
open(uri) { |json| json["private"] } open_api(uri) { |json| json["private"] }
end end
def query_string(*main_params, **qualifiers) def query_string(*main_params, **qualifiers)
@ -275,6 +275,6 @@ module GitHub
def search(entity, *queries, **qualifiers) def search(entity, *queries, **qualifiers)
uri = url_to "search", entity uri = url_to "search", entity
uri.query = query_string(*queries, **qualifiers) uri.query = query_string(*queries, **qualifiers)
open(uri) { |json| json.fetch("items", []) } open_api(uri) { |json| json.fetch("items", []) }
end end
end end