From 83cca40fc9cd921af229e5861fa78b2388fbc344 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Wed, 7 Mar 2018 16:14:55 +0000 Subject: [PATCH] RuboCop 0.53.0 manual fixes. --- Library/Homebrew/cask/lib/hbc/cask_loader.rb | 2 ++ Library/Homebrew/cmd/gist-logs.rb | 4 ++-- Library/Homebrew/cmd/update-report.rb | 2 +- Library/Homebrew/download_strategy.rb | 2 +- Library/Homebrew/rubocops/extend/formula_cop.rb | 2 ++ Library/Homebrew/sandbox.rb | 8 ++++---- Library/Homebrew/test/cmd/search_remote_tap_spec.rb | 2 +- Library/Homebrew/test/download_strategies_spec.rb | 2 +- Library/Homebrew/test/utils/analytics_spec.rb | 4 ++-- Library/Homebrew/utils/analytics.rb | 8 ++++---- Library/Homebrew/utils/bottles.rb | 2 +- Library/Homebrew/utils/git.rb | 4 ++-- Library/Homebrew/utils/github.rb | 10 +++++----- 13 files changed, 28 insertions(+), 24 deletions(-) diff --git a/Library/Homebrew/cask/lib/hbc/cask_loader.rb b/Library/Homebrew/cask/lib/hbc/cask_loader.rb index 74c39176d3..640282ec36 100644 --- a/Library/Homebrew/cask/lib/hbc/cask_loader.rb +++ b/Library/Homebrew/cask/lib/hbc/cask_loader.rb @@ -1,3 +1,5 @@ +require "uri" + module Hbc module CaskLoader class FromContentLoader diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index ab81a017e2..c30ee85cd9 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -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 diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index 2c4d3de0c5..d241d17b06 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -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 diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index e85661d76d..6e750806f0 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -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 diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index e53c02a449..2c20e62dec 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -4,6 +4,8 @@ require_relative "../../extend/string" module RuboCop module Cop class FormulaCop < Cop + include RangeHelp + attr_accessor :file_path @registry = Cop.registry diff --git a/Library/Homebrew/sandbox.rb b/Library/Homebrew/sandbox.rb index ea74fae098..e59e2a5500 100644 --- a/Library/Homebrew/sandbox.rb +++ b/Library/Homebrew/sandbox.rb @@ -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? diff --git a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb index eb256b9245..49678f3ace 100644 --- a/Library/Homebrew/test/cmd/search_remote_tap_spec.rb +++ b/Library/Homebrew/test/cmd/search_remote_tap_spec.rb @@ -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"]) diff --git a/Library/Homebrew/test/download_strategies_spec.rb b/Library/Homebrew/test/download_strategies_spec.rb index 7ad070fc44..f1c64db717 100644 --- a/Library/Homebrew/test/download_strategies_spec.rb +++ b/Library/Homebrew/test/download_strategies_spec.rb @@ -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 diff --git a/Library/Homebrew/test/utils/analytics_spec.rb b/Library/Homebrew/test/utils/analytics_spec.rb index bb6cda0b12..4526194d81 100644 --- a/Library/Homebrew/test/utils/analytics_spec.rb +++ b/Library/Homebrew/test/utils/analytics_spec.rb @@ -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 diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index adef3e811d..7636789c53 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -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"] diff --git a/Library/Homebrew/utils/bottles.rb b/Library/Homebrew/utils/bottles.rb index 3a61cf215e..f67ace4c19 100644 --- a/Library/Homebrew/utils/bottles.rb +++ b/Library/Homebrew/utils/bottles.rb @@ -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) diff --git a/Library/Homebrew/utils/git.rb b/Library/Homebrew/utils/git.rb index ac17967c53..0ffcab7b1d 100644 --- a/Library/Homebrew/utils/git.rb +++ b/Library/Homebrew/utils/git.rb @@ -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 diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 0166763234..b6a27b3283 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -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