Fix RuboCop offenses.

This commit is contained in:
Markus Reiter 2020-10-09 11:12:06 +02:00
parent 2c893b94fa
commit b4e8bfe716
5 changed files with 8 additions and 10 deletions

View File

@ -45,7 +45,7 @@ module Cask
def <=>(other) def <=>(other)
return unless other.class < AbstractArtifact 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 @@sort_order ||= [ # rubocop:disable Style/ClassVars
PreflightBlock, PreflightBlock,

View File

@ -54,8 +54,7 @@ HOMEBREW_CACHE_FORMULA = (HOMEBREW_CACHE/"Formula").freeze
HOMEBREW_LOGS = Pathname.new(get_env_or_raise("HOMEBREW_LOGS")).expand_path.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 # Must use `/tmp` instead of `TMPDIR` because long paths break Unix domain sockets
HOMEBREW_TEMP = begin HOMEBREW_TEMP = Pathname.new(get_env_or_raise("HOMEBREW_TEMP")).yield_self do |tmp|
tmp = Pathname.new(get_env_or_raise("HOMEBREW_TEMP"))
tmp.mkpath unless tmp.exist? tmp.mkpath unless tmp.exist?
tmp.realpath tmp.realpath
end.freeze end.freeze

View File

@ -218,8 +218,7 @@ module Formulary
end end
def load_file(flags:) def load_file(flags:)
if url =~ %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(/Formula)?/([\w+-.@]+).rb} if %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(?:/Formula)?/(?<formula_name>[\w+-.@]+).rb} =~ url # rubocop:disable Style/CaseLikeIf
formula_name = Regexp.last_match(2)
odisabled "Installation of #{formula_name} from a GitHub commit URL", odisabled "Installation of #{formula_name} from a GitHub commit URL",
"'brew extract #{formula_name}' to stable tap on GitHub" "'brew extract #{formula_name}' to stable tap on GitHub"
elsif url.match?(%r{^(https?|ftp)://}) elsif url.match?(%r{^(https?|ftp)://})
@ -232,8 +231,8 @@ module Formulary
curl_download url, to: path curl_download url, to: path
super super
rescue MethodDeprecatedError => e rescue MethodDeprecatedError => e
if url =~ %r{github.com/([\w-]+)/([\w-]+)/} if %r{github.com/(?<user>[\w-]+)/(?<repo>[\w-]+)/} =~ url
e.issues_url = "https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/issues/new" e.issues_url = "https://github.com/#{user}/#{repo}/issues/new"
end end
raise raise
end end

View File

@ -395,7 +395,7 @@ module RuboCop
@offense_source_range = method_node.source_range @offense_source_range = method_node.source_range
params.all? do |given_param| params.all? do |given_param|
method_params.any? do |method_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) regex_match_group(method_param, given_param)
else else
node_equals?(method_param, given_param) node_equals?(method_param, given_param)

View File

@ -79,9 +79,9 @@ module RuboCop
def audit_formula(_node, _class_node, _parent_class_node, body_node) def audit_formula(_node, _class_node, _parent_class_node, body_node)
find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method| 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 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 parameters(method).first.keys.first
end end