diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index f43fbe54c0..c94b248a3b 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -26,6 +26,9 @@ Layout/CaseIndentation: Layout/EmptyLineBetweenDefs: AllowAdjacentOneLineDefs: true +Layout/EndAlignment: + EnforcedStyleAlignWith: variable + Layout/IndentArray: EnforcedStyle: special_inside_parentheses @@ -52,9 +55,6 @@ Lint/AmbiguousBlockAssociation: Lint/AssignmentInCondition: Enabled: false -Lint/EndAlignment: - EnforcedStyleAlignWith: variable - # so many of these in formulae and can't be autocorrected Lint/ParenthesesAsGroupedExpression: Enabled: false @@ -205,7 +205,10 @@ Style/TernaryParentheses: EnforcedStyle: require_parentheses_when_complex # makes diffs nicer -Style/TrailingCommaInLiteral: +Style/TrailingCommaInArrayLiteral: + EnforcedStyleForMultiline: comma + +Style/TrailingCommaInHashLiteral: EnforcedStyleForMultiline: comma Style/TrailingCommaInArguments: @@ -215,6 +218,10 @@ Style/TrailingCommaInArguments: Naming/VariableNumber: Enabled: false +# doesn't make sense for Homebrew/brew but does for taps +Naming/UncommunicativeMethodParamName: + Enabled: true + Style/WordArray: MinSize: 4 diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index e0089e0500..58b911ca9f 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -68,6 +68,10 @@ Naming/PredicateName: - 'compat/**/*' NameWhitelist: is_32_bit?, is_64_bit? +# f meaning formulae is pretty standard +Naming/UncommunicativeMethodParamName: + Enabled: false + Style/BlockDelimiters: Exclude: - '**/*_spec.rb' 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/install.rb b/Library/Homebrew/cmd/install.rb index e1e4712ea1..bacdb18f02 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -344,7 +344,7 @@ module Homebrew rescue FormulaInstallationAlreadyAttemptedError # We already attempted to install f as part of the dependency tree of # another formula. In that case, don't generate an error, just move on. - return + nil rescue CannotInstallFormulaError => e ofail e.message end diff --git a/Library/Homebrew/cmd/reinstall.rb b/Library/Homebrew/cmd/reinstall.rb index 7c62d8092a..420c08dfe8 100644 --- a/Library/Homebrew/cmd/reinstall.rb +++ b/Library/Homebrew/cmd/reinstall.rb @@ -47,7 +47,7 @@ module Homebrew fi.install fi.finish rescue FormulaInstallationAlreadyAttemptedError - return + nil rescue Exception # rubocop:disable Lint/RescueException ignore_interrupts { restore_backup(keg, keg_was_linked) } raise 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/cmd/upgrade.rb b/Library/Homebrew/cmd/upgrade.rb index 1446025805..4e6dd04631 100644 --- a/Library/Homebrew/cmd/upgrade.rb +++ b/Library/Homebrew/cmd/upgrade.rb @@ -139,7 +139,7 @@ module Homebrew rescue FormulaInstallationAlreadyAttemptedError # We already attempted to upgrade f as part of the dependency tree of # another formula. In that case, don't generate an error, just move on. - return + nil rescue CannotInstallFormulaError => e ofail e rescue BuildError => e diff --git a/Library/Homebrew/constants.rb b/Library/Homebrew/constants.rb index 9514320abe..77c69f3e43 100644 --- a/Library/Homebrew/constants.rb +++ b/Library/Homebrew/constants.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true # RuboCop version used for `brew style` and `brew cask style` -HOMEBREW_RUBOCOP_VERSION = "0.52.1" -HOMEBREW_RUBOCOP_CASK_VERSION = "~> 0.16.0" # has to be updated when RuboCop version changes +HOMEBREW_RUBOCOP_VERSION = "0.53.0" +HOMEBREW_RUBOCOP_CASK_VERSION = "~> 0.17.0" # has to be updated when RuboCop version changes diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 79f5b2f1d0..1b779f226b 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -966,7 +966,7 @@ module Homebrew Putting non-prefixed coreutils in your path can cause gmp builds to fail. EOS rescue FormulaUnavailableError - return + nil end def check_for_non_prefixed_findutils @@ -981,7 +981,7 @@ module Homebrew Putting non-prefixed findutils in your path can cause python builds to fail. EOS rescue FormulaUnavailableError - return + nil end def check_for_pydistutils_cfg_in_home 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/extend/os/linux/system_config.rb b/Library/Homebrew/extend/os/linux/system_config.rb index cf01765623..47eca7697e 100644 --- a/Library/Homebrew/extend/os/linux/system_config.rb +++ b/Library/Homebrew/extend/os/linux/system_config.rb @@ -31,7 +31,7 @@ class SystemConfig return "N/A" unless CoreTap.instance.installed? Formulary.factory(formula).linked_version || "N/A" rescue FormulaUnavailableError - return "N/A" + "N/A" end def dump_verbose_config(out = $stdout) diff --git a/Library/Homebrew/formula_versions.rb b/Library/Homebrew/formula_versions.rb index c10c69e674..67edba9c5e 100644 --- a/Library/Homebrew/formula_versions.rb +++ b/Library/Homebrew/formula_versions.rb @@ -44,7 +44,7 @@ class FormulaVersions # continue walking the history ohai "#{e} in #{name} at revision #{rev}", e.backtrace if ARGV.debug? rescue FormulaUnavailableError - return + nil ensure Homebrew.raise_deprecation_exceptions = false 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/tab.rb b/Library/Homebrew/tab.rb index aa0208d51a..0fed724a8d 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -326,8 +326,8 @@ class Tab < OpenStruct "time" => time, "source_modified_time" => source_modified_time.to_i, "HEAD" => self.HEAD, - "stdlib" => (stdlib.to_s if stdlib), - "compiler" => (compiler.to_s if compiler), + "stdlib" => (stdlib&.to_s), + "compiler" => (compiler&.to_s), "aliases" => aliases, "runtime_dependencies" => runtime_dependencies, "source" => source, diff --git a/Library/Homebrew/test/Gemfile.lock b/Library/Homebrew/test/Gemfile.lock index 0d43174e98..b69a5f0a71 100644 --- a/Library/Homebrew/test/Gemfile.lock +++ b/Library/Homebrew/test/Gemfile.lock @@ -36,9 +36,9 @@ GEM rspec-support (3.7.1) rspec-wait (0.0.9) rspec (>= 3, < 4) - rubocop (0.52.1) + rubocop (0.53.0) parallel (~> 1.10) - parser (>= 2.4.0.2, < 3.0) + parser (>= 2.5) powerpack (~> 0.1) rainbow (>= 2.2.2, < 4.0) ruby-progressbar (~> 1.7) @@ -62,7 +62,7 @@ DEPENDENCIES rspec-its rspec-retry rspec-wait - rubocop (= 0.52.1) + rubocop (= 0.53.0) simplecov BUNDLED WITH 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/support/lib/config.rb b/Library/Homebrew/test/support/lib/config.rb index e54fc111fa..a59d80c995 100644 --- a/Library/Homebrew/test/support/lib/config.rb +++ b/Library/Homebrew/test/support/lib/config.rb @@ -16,9 +16,9 @@ TEST_TMPDIR = ENV.fetch("HOMEBREW_TEST_TMPDIR") do |k| end # Paths pointing into the Homebrew code base that persist across test runs -HOMEBREW_LIBRARY_PATH = Pathname.new(File.expand_path("../../../..", __FILE__)) +HOMEBREW_LIBRARY_PATH = Pathname.new(File.expand_path("../../..", __dir__)) HOMEBREW_SHIMS_PATH = HOMEBREW_LIBRARY_PATH.parent+"Homebrew/shims" -HOMEBREW_LOAD_PATH = [File.expand_path("..", __FILE__), HOMEBREW_LIBRARY_PATH].join(":") +HOMEBREW_LOAD_PATH = [File.expand_path(__dir__), HOMEBREW_LIBRARY_PATH].join(":") # Paths redirected to a temporary directory and wiped at the end of the test run HOMEBREW_PREFIX = Pathname.new(TEST_TMPDIR).join("prefix") 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