rubocop-rails: make fixes.

This commit is contained in:
Mike McQuaid 2020-12-01 17:04:59 +00:00
parent 64ed163fb0
commit 9216d8abe6
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
29 changed files with 46 additions and 54 deletions

View File

@ -64,7 +64,7 @@ class Bintray
url = "#{API_URL}/content/#{@bintray_org}/#{repo}/#{package}/#{version}/#{remote_file}" url = "#{API_URL}/content/#{@bintray_org}/#{repo}/#{package}/#{version}/#{remote_file}"
args = ["--upload-file", local_file] args = ["--upload-file", local_file]
args += ["--header", "X-Checksum-Sha2: #{sha256}"] unless sha256.blank? args += ["--header", "X-Checksum-Sha2: #{sha256}"] if sha256.present?
args << "--fail" unless warn_on_error args << "--fail" unless warn_on_error
result = T.unsafe(self).open_api(url, *args) result = T.unsafe(self).open_api(url, *args)
@ -167,7 +167,7 @@ class Bintray
.select { |type,| type == :stderr } .select { |type,| type == :stderr }
.map { |_, line| line } .map { |_, line| line }
.join .join
raise if e.status.exitstatus != 22 && !stderr.include?("404 Not Found") raise if e.status.exitstatus != 22 && stderr.exclude?("404 Not Found")
false false
else else
@ -185,7 +185,7 @@ class Bintray
if result.success? if result.success?
result.stdout.match(/^X-Checksum-Sha2:\s+(\h{64})\b/i)&.values_at(1)&.first || "" result.stdout.match(/^X-Checksum-Sha2:\s+(\h{64})\b/i)&.values_at(1)&.first || ""
else else
raise Error if result.status.exitstatus != 22 && !result.stderr.include?("404 Not Found") raise Error if result.status.exitstatus != 22 && result.stderr.exclude?("404 Not Found")
nil nil
end end

View File

@ -59,7 +59,7 @@ begin
# Command-style help: `help <cmd>` is fine, but `<cmd> help` is not. # Command-style help: `help <cmd>` is fine, but `<cmd> help` is not.
help_flag = true help_flag = true
help_cmd_index = i help_cmd_index = i
elsif !cmd && !help_flag_list.include?(arg) elsif !cmd && help_flag_list.exclude?(arg)
cmd = ARGV.delete_at(i) cmd = ARGV.delete_at(i)
cmd = Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd) cmd = Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd)
end end

View File

@ -483,7 +483,7 @@ module Cask
add_warning "cask token mentions architecture" if token.end_with? "x86", "32_bit", "x86_64", "64_bit" add_warning "cask token mentions architecture" if token.end_with? "x86", "32_bit", "x86_64", "64_bit"
return unless token.end_with?("cocoa", "qt", "gtk", "wx", "java") && !%w[cocoa qt gtk wx java].include?(token) return unless token.end_with?("cocoa", "qt", "gtk", "wx", "java") && %w[cocoa qt gtk wx java].exclude?(token)
add_warning "cask token mentions framework" add_warning "cask token mentions framework"
end end
@ -525,11 +525,7 @@ module Cask
end end
version_stanza = cask.version.to_s version_stanza = cask.version.to_s
adjusted_version_stanza = if cask.appcast.must_contain.blank? adjusted_version_stanza = cask.appcast.must_contain.presence || version_stanza.match(/^[[:alnum:].]+/)[0]
version_stanza.match(/^[[:alnum:].]+/)[0]
else
cask.appcast.must_contain
end
return if appcast_contents.include? adjusted_version_stanza return if appcast_contents.include? adjusted_version_stanza
add_error "appcast at URL '#{appcast_stanza}' does not contain"\ add_error "appcast at URL '#{appcast_stanza}' does not contain"\

View File

@ -35,7 +35,7 @@ module Cask
end end
def self.commands def self.commands
Cmd.command_classes.select(&:visible?).map { |klass| [klass.command_name, klass] }.to_h Cmd.command_classes.select(&:visible?).index_by(&:command_name)
end end
end end
end end

View File

@ -144,7 +144,7 @@ module Cask
def language_eval def language_eval
return @language_eval if defined?(@language_eval) return @language_eval if defined?(@language_eval)
return @language_eval = nil if @language_blocks.nil? || @language_blocks.empty? return @language_eval = nil if @language_blocks.blank?
raise CaskInvalidError.new(cask, "No default language specified.") if @language_blocks.default.nil? raise CaskInvalidError.new(cask, "No default language specified.") if @language_blocks.default.nil?

View File

@ -122,7 +122,7 @@ module Homebrew
return true unless basename.to_s.match?(/\A#{Regexp.escape(name)}--#{Regexp.escape(cask.version)}\b/) return true unless basename.to_s.match?(/\A#{Regexp.escape(name)}--#{Regexp.escape(cask.version)}\b/)
return true if scrub && !cask.versions.include?(cask.version) return true if scrub && cask.versions.exclude?(cask.version)
if cask.version.latest? if cask.version.latest?
return mtime < CLEANUP_DEFAULT_DAYS.days.ago && return mtime < CLEANUP_DEFAULT_DAYS.days.ago &&
@ -444,7 +444,7 @@ module Homebrew
path.unlink path.unlink
end end
end end
elsif path.directory? && !Keg::MUST_EXIST_SUBDIRECTORIES.include?(path) elsif path.directory? && Keg::MUST_EXIST_SUBDIRECTORIES.exclude?(path)
dirs << path dirs << path
end end
end end

View File

@ -63,7 +63,7 @@ module Homebrew
end end
out = checks.send(method) out = checks.send(method)
next if out.nil? || out.empty? next if out.blank?
if first_warning if first_warning
$stderr.puts <<~EOS $stderr.puts <<~EOS

View File

@ -79,12 +79,12 @@ module Homebrew
only = :cask if args.cask? && !args.formula? only = :cask if args.cask? && !args.formula?
if args.analytics? if args.analytics?
if args.days.present? && !VALID_DAYS.include?(args.days) if args.days.present? && VALID_DAYS.exclude?(args.days)
raise UsageError, "--days must be one of #{VALID_DAYS.join(", ")}" raise UsageError, "--days must be one of #{VALID_DAYS.join(", ")}"
end end
if args.category.present? if args.category.present?
if args.named.present? && !VALID_FORMULA_CATEGORIES.include?(args.category) if args.named.present? && VALID_FORMULA_CATEGORIES.exclude?(args.category)
raise UsageError, "--category must be one of #{VALID_FORMULA_CATEGORIES.join(", ")} when querying formulae" raise UsageError, "--category must be one of #{VALID_FORMULA_CATEGORIES.join(", ")} when querying formulae"
end end

View File

@ -89,7 +89,7 @@ module Homebrew
formula_names = args.no_named? ? Formula.installed : args.named.to_resolved_formulae formula_names = args.no_named? ? Formula.installed : args.named.to_resolved_formulae
full_formula_names = formula_names.map(&:full_name).sort(&tap_and_name_comparison) full_formula_names = formula_names.map(&:full_name).sort(&tap_and_name_comparison)
full_formula_names = Formatter.columns(full_formula_names) unless args.public_send(:'1?') full_formula_names = Formatter.columns(full_formula_names) unless args.public_send(:'1?')
puts full_formula_names unless full_formula_names.blank? puts full_formula_names if full_formula_names.present?
end end
if args.cask? || (!args.formula? && args.no_named?) if args.cask? || (!args.formula? && args.no_named?)
cask_names = if args.no_named? cask_names = if args.no_named?
@ -99,7 +99,7 @@ module Homebrew
end end
full_cask_names = cask_names.map(&:full_name).sort(&tap_and_name_comparison) full_cask_names = cask_names.map(&:full_name).sort(&tap_and_name_comparison)
full_cask_names = Formatter.columns(full_cask_names) unless args.public_send(:'1?') full_cask_names = Formatter.columns(full_cask_names) unless args.public_send(:'1?')
puts full_cask_names unless full_cask_names.blank? puts full_cask_names if full_cask_names.present?
end end
elsif args.cask? elsif args.cask?
list_casks(args: args) list_casks(args: args)

View File

@ -119,7 +119,7 @@ module Homebrew
count = all_formulae.count + all_casks.count count = all_formulae.count + all_casks.count
if $stdout.tty? && (reason = MissingFormula.reason(query, silent: true)) && !local_casks.include?(query) if $stdout.tty? && (reason = MissingFormula.reason(query, silent: true)) && local_casks.exclude?(query)
if count.positive? if count.positive?
puts puts
puts "If you meant #{query.inspect} specifically:" puts "If you meant #{query.inspect} specifically:"

View File

@ -80,7 +80,7 @@ module Homebrew
end end
info += ", private" if tap.private? info += ", private" if tap.private?
info += "\n#{tap.path} (#{tap.path.abv})" info += "\n#{tap.path} (#{tap.path.abv})"
info += "\nFrom: #{tap.remote.blank? ? "N/A" : tap.remote}" info += "\nFrom: #{tap.remote.presence || "N/A"}"
else else
info += "Not installed" info += "Not installed"
end end

View File

@ -20,7 +20,7 @@ class CxxStdlib
end end
def self.create(type, compiler) def self.create(type, compiler)
raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && ![:libstdcxx, :libcxx].include?(type) raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && [:libstdcxx, :libcxx].exclude?(type)
apple_compiler = compiler.to_s.match?(GNU_GCC_REGEXP) ? false : true apple_compiler = compiler.to_s.match?(GNU_GCC_REGEXP) ? false : true
CxxStdlib.new(type, compiler, apple_compiler) CxxStdlib.new(type, compiler, apple_compiler)

View File

@ -47,7 +47,7 @@ module DependenciesHelpers
if dep.recommended? if dep.recommended?
klass.prune if ignores.include?("recommended?") || dependent.build.without?(dep) klass.prune if ignores.include?("recommended?") || dependent.build.without?(dep)
elsif dep.optional? elsif dep.optional?
klass.prune if !includes.include?("optional?") && !dependent.build.with?(dep) klass.prune if includes.exclude?("optional?") && !dependent.build.with?(dep)
elsif dep.build? || dep.test? elsif dep.build? || dep.test?
keep = false keep = false
keep ||= dep.test? && includes.include?("test?") && dependent == root_dependent keep ||= dep.test? && includes.include?("test?") && dependent == root_dependent

View File

@ -82,7 +82,7 @@ module SharedEnvExtension
value = value.to_s value = value.to_s
Array(keys).each do |key| Array(keys).each do |key|
old_value = self[key] old_value = self[key]
self[key] = if old_value.nil? || old_value.empty? self[key] = if old_value.blank?
value value
else else
old_value + separator + value old_value + separator + value
@ -95,7 +95,7 @@ module SharedEnvExtension
value = value.to_s value = value.to_s
Array(keys).each do |key| Array(keys).each do |key|
old_value = self[key] old_value = self[key]
self[key] = if old_value.nil? || old_value.empty? self[key] = if old_value.blank?
value value
else else
value + separator + old_value value + separator + old_value

View File

@ -301,7 +301,7 @@ class Pathname
sig { params(expected: T.nilable(Checksum)).void } sig { params(expected: T.nilable(Checksum)).void }
def verify_checksum(expected) def verify_checksum(expected)
raise ChecksumMissingError if expected.nil? || expected.empty? raise ChecksumMissingError if expected.blank?
actual = Checksum.new(expected.hash_type, send(expected.hash_type).downcase) actual = Checksum.new(expected.hash_type, send(expected.hash_type).downcase)
raise ChecksumMismatchError.new(self, expected, actual) unless expected == actual raise ChecksumMismatchError.new(self, expected, actual) unless expected == actual

View File

@ -260,13 +260,13 @@ class Formula
end end
def validate_attributes! def validate_attributes!
raise FormulaValidationError.new(full_name, :name, name) if name.nil? || name.empty? || name =~ /\s/ raise FormulaValidationError.new(full_name, :name, name) if name.blank? || name =~ /\s/
url = active_spec.url url = active_spec.url
raise FormulaValidationError.new(full_name, :url, url) if url.nil? || url.empty? || url =~ /\s/ raise FormulaValidationError.new(full_name, :url, url) if url.blank? || url =~ /\s/
val = version.respond_to?(:to_str) ? version.to_str : version val = version.respond_to?(:to_str) ? version.to_str : version
return unless val.nil? || val.empty? || val =~ /\s/ return unless val.blank? || val =~ /\s/
raise FormulaValidationError.new(full_name, :version, val) raise FormulaValidationError.new(full_name, :version, val)
end end

View File

@ -367,7 +367,7 @@ module Homebrew
def audit_homepage def audit_homepage
homepage = formula.homepage homepage = formula.homepage
return if homepage.nil? || homepage.empty? return if homepage.blank?
return unless @online return unless @online

View File

@ -364,7 +364,7 @@ class FormulaInstaller
return if only_deps? return if only_deps?
if build_bottle? && (arch = @bottle_arch) && !Hardware::CPU.optimization_flags.include?(arch.to_sym) if build_bottle? && (arch = @bottle_arch) && Hardware::CPU.optimization_flags.exclude?(arch.to_sym)
raise CannotInstallFormulaError, "Unrecognized architecture for --bottle-arch: #{arch}" raise CannotInstallFormulaError, "Unrecognized architecture for --bottle-arch: #{arch}"
end end
@ -537,9 +537,7 @@ class FormulaInstaller
req_deps = [] req_deps = []
formulae = [formula] formulae = [formula]
formula_deps_map = Dependency.expand(formula) formula_deps_map = Dependency.expand(formula)
.each_with_object({}) do |dep, hash| .index_by(&:name)
hash[dep.name] = dep
end
while f = formulae.pop while f = formulae.pop
runtime_requirements = runtime_requirements(f) runtime_requirements = runtime_requirements(f)
@ -594,9 +592,9 @@ class FormulaInstaller
end end
if pour_bottle && !Keg.bottle_dependencies.empty? if pour_bottle && !Keg.bottle_dependencies.empty?
bottle_deps = if !Keg.bottle_dependencies.include?(formula.name) bottle_deps = if Keg.bottle_dependencies.exclude?(formula.name)
Keg.bottle_dependencies Keg.bottle_dependencies
elsif !Keg.relocation_formulae.include?(formula.name) elsif Keg.relocation_formulae.exclude?(formula.name)
Keg.relocation_formulae Keg.relocation_formulae
else else
[] []

View File

@ -248,7 +248,7 @@ module Formulary
attr_reader :tap attr_reader :tap
def initialize(tapped_name, from: nil) def initialize(tapped_name, from: nil)
warn = ![:keg, :rack].include?(from) warn = [:keg, :rack].exclude?(from)
name, path = formula_name_path(tapped_name, warn: warn) name, path = formula_name_path(tapped_name, warn: warn)
super name, path super name, path
end end

View File

@ -171,7 +171,7 @@ class Keg
libtool_files = [] libtool_files = []
path.find do |pn| path.find do |pn|
next if pn.symlink? || pn.directory? || !Keg::LIBTOOL_EXTENSIONS.include?(pn.extname) next if pn.symlink? || pn.directory? || Keg::LIBTOOL_EXTENSIONS.exclude?(pn.extname)
libtool_files << pn libtool_files << pn
end end

View File

@ -270,9 +270,9 @@ class LinkageChecker
def sort_by_formula_full_name!(arr) def sort_by_formula_full_name!(arr)
arr.sort! do |a, b| arr.sort! do |a, b|
if a.include?("/") && !b.include?("/") if a.include?("/") && b.exclude?("/")
1 1
elsif !a.include?("/") && b.include?("/") elsif a.exclude?("/") && b.include?("/")
-1 -1
else else
a <=> b a <=> b

View File

@ -407,7 +407,7 @@ module Homebrew
next next
end end
if livecheck_strategy.present? && !strategies.include?(strategy) if livecheck_strategy.present? && strategies.exclude?(strategy)
odebug "#{strategy_name} strategy does not apply to this URL" odebug "#{strategy_name} strategy does not apply to this URL"
next next
end end

View File

@ -50,7 +50,7 @@ module Homebrew
# @param url [String] the URL to match against # @param url [String] the URL to match against
# @return [Boolean] # @return [Boolean]
def self.match?(url) def self.match?(url)
URL_MATCH_REGEX.match?(url) && !url.include?("savannah.") URL_MATCH_REGEX.match?(url) && url.exclude?("savannah.")
end end
# Generates a URL and regex (if one isn't provided) and passes them # Generates a URL and regex (if one isn't provided) and passes them

View File

@ -185,7 +185,7 @@ module OS
path = mdfind(*ids) path = mdfind(*ids)
.reject { |p| p.include?("/Backups.backupdb/") } .reject { |p| p.include?("/Backups.backupdb/") }
.first .first
Pathname.new(path) unless path.nil? || path.empty? Pathname.new(path) if path.present?
end end
def mdfind(*ids) def mdfind(*ids)

View File

@ -514,9 +514,9 @@ module Kernel
def tap_and_name_comparison def tap_and_name_comparison
proc do |a, b| proc do |a, b|
if a.include?("/") && !b.include?("/") if a.include?("/") && b.exclude?("/")
1 1
elsif !a.include?("/") && b.include?("/") elsif a.exclude?("/") && b.include?("/")
-1 -1
else else
a <=> b a <=> b

View File

@ -71,7 +71,7 @@ module Utils
env: { "SSL_CERT_FILE" => nil }.merge(env), env: { "SSL_CERT_FILE" => nil }.merge(env),
**command_options **command_options
if !result.success? && !args.include?("--http1.1") if !result.success? && args.exclude?("--http1.1")
# This is a workaround for https://github.com/curl/curl/issues/1618. # This is a workaround for https://github.com/curl/curl/issues/1618.
if result.status.exitstatus == 56 # Unexpected EOF if result.status.exitstatus == 56 # Unexpected EOF
out = curl_output("-V").stdout out = curl_output("-V").stdout

View File

@ -79,7 +79,7 @@ module Utils
# without writing its Interrupt exception to the error pipe. # without writing its Interrupt exception to the error pipe.
raise Interrupt if $CHILD_STATUS.exitstatus == 130 raise Interrupt if $CHILD_STATUS.exitstatus == 130
if data && !data.empty? if data.present?
error_hash = JSON.parse(T.must(data.lines.first)) error_hash = JSON.parse(T.must(data.lines.first))
e = ChildProcessError.new(error_hash) e = ChildProcessError.new(error_hash)

View File

@ -451,13 +451,11 @@ module GitHub
next if commit.present? && commit != r["commit"]["oid"] next if commit.present? && commit != r["commit"]["oid"]
next unless valid_associations.include? r["authorAssociation"] next unless valid_associations.include? r["authorAssociation"]
email = if r["author"]["email"].blank? email = r["author"]["email"].presence ||
"#{r["author"]["databaseId"]}+#{r["author"]["login"]}@users.noreply.github.com" "#{r["author"]["databaseId"]}+#{r["author"]["login"]}@users.noreply.github.com"
else
r["author"]["email"]
end
name = r["author"]["name"].presence || r["author"]["login"] name = r["author"]["name"].presence ||
r["author"]["login"]
{ {
"email" => email, "email" => email,

View File

@ -107,7 +107,7 @@ module SharedAudits
return if metadata.nil? return if metadata.nil?
if metadata["fork"] && !GITHUB_FORK_ALLOWLIST.include?("#{user}/#{repo}") if metadata["fork"] && GITHUB_FORK_ALLOWLIST.exclude?("#{user}/#{repo}")
return "GitHub fork (not canonical repository)" return "GitHub fork (not canonical repository)"
end end