diff --git a/Library/Homebrew/cask/artifact/abstract_artifact.rb b/Library/Homebrew/cask/artifact/abstract_artifact.rb index 84275ec58a..1a6b019002 100644 --- a/Library/Homebrew/cask/artifact/abstract_artifact.rb +++ b/Library/Homebrew/cask/artifact/abstract_artifact.rb @@ -45,7 +45,7 @@ module Cask def <=>(other) return unless other.class < AbstractArtifact - return 0 if self.class == other.class + return 0 if instance_of?(other.class) @@sort_order ||= [ # rubocop:disable Style/ClassVars PreflightBlock, diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb index e4514dfabd..6cbc3709e5 100644 --- a/Library/Homebrew/config.rb +++ b/Library/Homebrew/config.rb @@ -54,8 +54,7 @@ HOMEBREW_CACHE_FORMULA = (HOMEBREW_CACHE/"Formula").freeze HOMEBREW_LOGS = Pathname.new(get_env_or_raise("HOMEBREW_LOGS")).expand_path.freeze # Must use `/tmp` instead of `TMPDIR` because long paths break Unix domain sockets -HOMEBREW_TEMP = begin - tmp = Pathname.new(get_env_or_raise("HOMEBREW_TEMP")) +HOMEBREW_TEMP = Pathname.new(get_env_or_raise("HOMEBREW_TEMP")).yield_self do |tmp| tmp.mkpath unless tmp.exist? tmp.realpath end.freeze diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 8b10df0220..4bc1e446ca 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -218,8 +218,7 @@ module Formulary end def load_file(flags:) - if url =~ %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(/Formula)?/([\w+-.@]+).rb} - formula_name = Regexp.last_match(2) + if %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(?:/Formula)?/(?[\w+-.@]+).rb} =~ url # rubocop:disable Style/CaseLikeIf odisabled "Installation of #{formula_name} from a GitHub commit URL", "'brew extract #{formula_name}' to stable tap on GitHub" elsif url.match?(%r{^(https?|ftp)://}) @@ -232,8 +231,8 @@ module Formulary curl_download url, to: path super rescue MethodDeprecatedError => e - if url =~ %r{github.com/([\w-]+)/([\w-]+)/} - e.issues_url = "https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/issues/new" + if %r{github.com/(?[\w-]+)/(?[\w-]+)/} =~ url + e.issues_url = "https://github.com/#{user}/#{repo}/issues/new" end raise end diff --git a/Library/Homebrew/rubocops/extend/formula.rb b/Library/Homebrew/rubocops/extend/formula.rb index 80819e92f2..eddbac5b6c 100644 --- a/Library/Homebrew/rubocops/extend/formula.rb +++ b/Library/Homebrew/rubocops/extend/formula.rb @@ -395,7 +395,7 @@ module RuboCop @offense_source_range = method_node.source_range params.all? do |given_param| method_params.any? do |method_param| - if given_param.class == Regexp + if given_param.instance_of?(Regexp) regex_match_group(method_param, given_param) else node_equals?(method_param, given_param) diff --git a/Library/Homebrew/rubocops/uses_from_macos.rb b/Library/Homebrew/rubocops/uses_from_macos.rb index 903faebb8a..a71b6666ef 100644 --- a/Library/Homebrew/rubocops/uses_from_macos.rb +++ b/Library/Homebrew/rubocops/uses_from_macos.rb @@ -79,9 +79,9 @@ module RuboCop def audit_formula(_node, _class_node, _parent_class_node, body_node) find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method| - dep = if parameters(method).first.class == RuboCop::AST::StrNode + dep = if parameters(method).first.instance_of?(RuboCop::AST::StrNode) parameters(method).first - elsif parameters(method).first.class == RuboCop::AST::HashNode + elsif parameters(method).first.instance_of?(RuboCop::AST::HashNode) parameters(method).first.keys.first end