From 9216d8abe681ce90e6b1d515eee0f313714e9782 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 1 Dec 2020 17:04:59 +0000 Subject: [PATCH] rubocop-rails: make fixes. --- Library/Homebrew/bintray.rb | 6 +++--- Library/Homebrew/brew.rb | 2 +- Library/Homebrew/cask/audit.rb | 8 ++------ Library/Homebrew/cask/cmd/help.rb | 2 +- Library/Homebrew/cask/dsl.rb | 2 +- Library/Homebrew/cleanup.rb | 4 ++-- Library/Homebrew/cmd/doctor.rb | 2 +- Library/Homebrew/cmd/info.rb | 4 ++-- Library/Homebrew/cmd/list.rb | 4 ++-- Library/Homebrew/cmd/search.rb | 2 +- Library/Homebrew/cmd/tap-info.rb | 2 +- Library/Homebrew/cxxstdlib.rb | 2 +- Library/Homebrew/dependencies_helpers.rb | 2 +- Library/Homebrew/extend/ENV/shared.rb | 4 ++-- Library/Homebrew/extend/pathname.rb | 2 +- Library/Homebrew/formula.rb | 6 +++--- Library/Homebrew/formula_auditor.rb | 2 +- Library/Homebrew/formula_installer.rb | 10 ++++------ Library/Homebrew/formulary.rb | 2 +- Library/Homebrew/keg_relocate.rb | 2 +- Library/Homebrew/linkage_checker.rb | 4 ++-- Library/Homebrew/livecheck/livecheck.rb | 2 +- Library/Homebrew/livecheck/strategy/gnu.rb | 2 +- Library/Homebrew/os/mac.rb | 2 +- Library/Homebrew/utils.rb | 4 ++-- Library/Homebrew/utils/curl.rb | 2 +- Library/Homebrew/utils/fork.rb | 2 +- Library/Homebrew/utils/github.rb | 10 ++++------ Library/Homebrew/utils/shared_audits.rb | 2 +- 29 files changed, 46 insertions(+), 54 deletions(-) diff --git a/Library/Homebrew/bintray.rb b/Library/Homebrew/bintray.rb index c925c1260d..5b9f8dee91 100644 --- a/Library/Homebrew/bintray.rb +++ b/Library/Homebrew/bintray.rb @@ -64,7 +64,7 @@ class Bintray url = "#{API_URL}/content/#{@bintray_org}/#{repo}/#{package}/#{version}/#{remote_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 result = T.unsafe(self).open_api(url, *args) @@ -167,7 +167,7 @@ class Bintray .select { |type,| type == :stderr } .map { |_, line| line } .join - raise if e.status.exitstatus != 22 && !stderr.include?("404 Not Found") + raise if e.status.exitstatus != 22 && stderr.exclude?("404 Not Found") false else @@ -185,7 +185,7 @@ class Bintray if result.success? result.stdout.match(/^X-Checksum-Sha2:\s+(\h{64})\b/i)&.values_at(1)&.first || "" 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 end diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index 43ab29a917..a9c619c360 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -59,7 +59,7 @@ begin # Command-style help: `help ` is fine, but ` help` is not. help_flag = true help_cmd_index = i - elsif !cmd && !help_flag_list.include?(arg) + elsif !cmd && help_flag_list.exclude?(arg) cmd = ARGV.delete_at(i) cmd = Commands::HOMEBREW_INTERNAL_COMMAND_ALIASES.fetch(cmd, cmd) end diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 22980038aa..279bbad1f8 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -483,7 +483,7 @@ module Cask 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" end @@ -525,11 +525,7 @@ module Cask end version_stanza = cask.version.to_s - adjusted_version_stanza = if cask.appcast.must_contain.blank? - version_stanza.match(/^[[:alnum:].]+/)[0] - else - cask.appcast.must_contain - end + adjusted_version_stanza = cask.appcast.must_contain.presence || version_stanza.match(/^[[:alnum:].]+/)[0] return if appcast_contents.include? adjusted_version_stanza add_error "appcast at URL '#{appcast_stanza}' does not contain"\ diff --git a/Library/Homebrew/cask/cmd/help.rb b/Library/Homebrew/cask/cmd/help.rb index 7a3a2cba4d..df5fcf3c97 100644 --- a/Library/Homebrew/cask/cmd/help.rb +++ b/Library/Homebrew/cask/cmd/help.rb @@ -35,7 +35,7 @@ module Cask end 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 diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index b9f0ca2064..25e753ec2f 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -144,7 +144,7 @@ module Cask def 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? diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 3eac30a117..2a8f57c92d 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -122,7 +122,7 @@ module Homebrew 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? return mtime < CLEANUP_DEFAULT_DAYS.days.ago && @@ -444,7 +444,7 @@ module Homebrew path.unlink end end - elsif path.directory? && !Keg::MUST_EXIST_SUBDIRECTORIES.include?(path) + elsif path.directory? && Keg::MUST_EXIST_SUBDIRECTORIES.exclude?(path) dirs << path end end diff --git a/Library/Homebrew/cmd/doctor.rb b/Library/Homebrew/cmd/doctor.rb index 5a3136f147..b243cd802f 100644 --- a/Library/Homebrew/cmd/doctor.rb +++ b/Library/Homebrew/cmd/doctor.rb @@ -63,7 +63,7 @@ module Homebrew end out = checks.send(method) - next if out.nil? || out.empty? + next if out.blank? if first_warning $stderr.puts <<~EOS diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 7e23762270..5c3715a02e 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -79,12 +79,12 @@ module Homebrew only = :cask if args.cask? && !args.formula? 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(", ")}" end 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" end diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 7b1008e8ff..5589ed7dd1 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -89,7 +89,7 @@ module Homebrew 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 = 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 if args.cask? || (!args.formula? && args.no_named?) cask_names = if args.no_named? @@ -99,7 +99,7 @@ module Homebrew end 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?') - puts full_cask_names unless full_cask_names.blank? + puts full_cask_names if full_cask_names.present? end elsif args.cask? list_casks(args: args) diff --git a/Library/Homebrew/cmd/search.rb b/Library/Homebrew/cmd/search.rb index 480023574c..d2bed58275 100644 --- a/Library/Homebrew/cmd/search.rb +++ b/Library/Homebrew/cmd/search.rb @@ -119,7 +119,7 @@ module Homebrew 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? puts puts "If you meant #{query.inspect} specifically:" diff --git a/Library/Homebrew/cmd/tap-info.rb b/Library/Homebrew/cmd/tap-info.rb index 81284e8c0d..4d6cd7436d 100644 --- a/Library/Homebrew/cmd/tap-info.rb +++ b/Library/Homebrew/cmd/tap-info.rb @@ -80,7 +80,7 @@ module Homebrew end info += ", private" if tap.private? info += "\n#{tap.path} (#{tap.path.abv})" - info += "\nFrom: #{tap.remote.blank? ? "N/A" : tap.remote}" + info += "\nFrom: #{tap.remote.presence || "N/A"}" else info += "Not installed" end diff --git a/Library/Homebrew/cxxstdlib.rb b/Library/Homebrew/cxxstdlib.rb index e6ef4838d6..ead686989c 100644 --- a/Library/Homebrew/cxxstdlib.rb +++ b/Library/Homebrew/cxxstdlib.rb @@ -20,7 +20,7 @@ class CxxStdlib end 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 CxxStdlib.new(type, compiler, apple_compiler) diff --git a/Library/Homebrew/dependencies_helpers.rb b/Library/Homebrew/dependencies_helpers.rb index 98507958db..dfb2dd0017 100644 --- a/Library/Homebrew/dependencies_helpers.rb +++ b/Library/Homebrew/dependencies_helpers.rb @@ -47,7 +47,7 @@ module DependenciesHelpers if dep.recommended? klass.prune if ignores.include?("recommended?") || dependent.build.without?(dep) 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? keep = false keep ||= dep.test? && includes.include?("test?") && dependent == root_dependent diff --git a/Library/Homebrew/extend/ENV/shared.rb b/Library/Homebrew/extend/ENV/shared.rb index eac0a305d4..0557a96608 100644 --- a/Library/Homebrew/extend/ENV/shared.rb +++ b/Library/Homebrew/extend/ENV/shared.rb @@ -82,7 +82,7 @@ module SharedEnvExtension value = value.to_s Array(keys).each do |key| old_value = self[key] - self[key] = if old_value.nil? || old_value.empty? + self[key] = if old_value.blank? value else old_value + separator + value @@ -95,7 +95,7 @@ module SharedEnvExtension value = value.to_s Array(keys).each do |key| old_value = self[key] - self[key] = if old_value.nil? || old_value.empty? + self[key] = if old_value.blank? value else value + separator + old_value diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index f2e00e41c6..29b282ed11 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -301,7 +301,7 @@ class Pathname sig { params(expected: T.nilable(Checksum)).void } 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) raise ChecksumMismatchError.new(self, expected, actual) unless expected == actual diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index f384768a13..c3227514ec 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -260,13 +260,13 @@ class Formula end 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 - 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 - return unless val.nil? || val.empty? || val =~ /\s/ + return unless val.blank? || val =~ /\s/ raise FormulaValidationError.new(full_name, :version, val) end diff --git a/Library/Homebrew/formula_auditor.rb b/Library/Homebrew/formula_auditor.rb index 1835029ae4..c5d5c97408 100644 --- a/Library/Homebrew/formula_auditor.rb +++ b/Library/Homebrew/formula_auditor.rb @@ -367,7 +367,7 @@ module Homebrew def audit_homepage homepage = formula.homepage - return if homepage.nil? || homepage.empty? + return if homepage.blank? return unless @online diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 2f9667d99c..908287cf5e 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -364,7 +364,7 @@ class FormulaInstaller 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}" end @@ -537,9 +537,7 @@ class FormulaInstaller req_deps = [] formulae = [formula] formula_deps_map = Dependency.expand(formula) - .each_with_object({}) do |dep, hash| - hash[dep.name] = dep - end + .index_by(&:name) while f = formulae.pop runtime_requirements = runtime_requirements(f) @@ -594,9 +592,9 @@ class FormulaInstaller end 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 - elsif !Keg.relocation_formulae.include?(formula.name) + elsif Keg.relocation_formulae.exclude?(formula.name) Keg.relocation_formulae else [] diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 86a014e155..28e3864742 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -248,7 +248,7 @@ module Formulary attr_reader :tap 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) super name, path end diff --git a/Library/Homebrew/keg_relocate.rb b/Library/Homebrew/keg_relocate.rb index 6fd598cfa1..0ab2e24079 100644 --- a/Library/Homebrew/keg_relocate.rb +++ b/Library/Homebrew/keg_relocate.rb @@ -171,7 +171,7 @@ class Keg libtool_files = [] 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 end diff --git a/Library/Homebrew/linkage_checker.rb b/Library/Homebrew/linkage_checker.rb index 9025bf0374..e356b501e1 100644 --- a/Library/Homebrew/linkage_checker.rb +++ b/Library/Homebrew/linkage_checker.rb @@ -270,9 +270,9 @@ class LinkageChecker def sort_by_formula_full_name!(arr) arr.sort! do |a, b| - if a.include?("/") && !b.include?("/") + if a.include?("/") && b.exclude?("/") 1 - elsif !a.include?("/") && b.include?("/") + elsif a.exclude?("/") && b.include?("/") -1 else a <=> b diff --git a/Library/Homebrew/livecheck/livecheck.rb b/Library/Homebrew/livecheck/livecheck.rb index 1c4d6d3699..9531265260 100644 --- a/Library/Homebrew/livecheck/livecheck.rb +++ b/Library/Homebrew/livecheck/livecheck.rb @@ -407,7 +407,7 @@ module Homebrew next 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" next end diff --git a/Library/Homebrew/livecheck/strategy/gnu.rb b/Library/Homebrew/livecheck/strategy/gnu.rb index 083330b564..1d181d3992 100644 --- a/Library/Homebrew/livecheck/strategy/gnu.rb +++ b/Library/Homebrew/livecheck/strategy/gnu.rb @@ -50,7 +50,7 @@ module Homebrew # @param url [String] the URL to match against # @return [Boolean] def self.match?(url) - URL_MATCH_REGEX.match?(url) && !url.include?("savannah.") + URL_MATCH_REGEX.match?(url) && url.exclude?("savannah.") end # Generates a URL and regex (if one isn't provided) and passes them diff --git a/Library/Homebrew/os/mac.rb b/Library/Homebrew/os/mac.rb index 26f373068d..1d291b235f 100644 --- a/Library/Homebrew/os/mac.rb +++ b/Library/Homebrew/os/mac.rb @@ -185,7 +185,7 @@ module OS path = mdfind(*ids) .reject { |p| p.include?("/Backups.backupdb/") } .first - Pathname.new(path) unless path.nil? || path.empty? + Pathname.new(path) if path.present? end def mdfind(*ids) diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index a9fbd0038f..d7980f6518 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -514,9 +514,9 @@ module Kernel def tap_and_name_comparison proc do |a, b| - if a.include?("/") && !b.include?("/") + if a.include?("/") && b.exclude?("/") 1 - elsif !a.include?("/") && b.include?("/") + elsif a.exclude?("/") && b.include?("/") -1 else a <=> b diff --git a/Library/Homebrew/utils/curl.rb b/Library/Homebrew/utils/curl.rb index 7229bd2e2a..afcc85712c 100644 --- a/Library/Homebrew/utils/curl.rb +++ b/Library/Homebrew/utils/curl.rb @@ -71,7 +71,7 @@ module Utils env: { "SSL_CERT_FILE" => nil }.merge(env), **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. if result.status.exitstatus == 56 # Unexpected EOF out = curl_output("-V").stdout diff --git a/Library/Homebrew/utils/fork.rb b/Library/Homebrew/utils/fork.rb index 6b858996b6..e9eb1ea243 100644 --- a/Library/Homebrew/utils/fork.rb +++ b/Library/Homebrew/utils/fork.rb @@ -79,7 +79,7 @@ module Utils # without writing its Interrupt exception to the error pipe. raise Interrupt if $CHILD_STATUS.exitstatus == 130 - if data && !data.empty? + if data.present? error_hash = JSON.parse(T.must(data.lines.first)) e = ChildProcessError.new(error_hash) diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index dfd585a567..8aeb60a21a 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -451,13 +451,11 @@ module GitHub next if commit.present? && commit != r["commit"]["oid"] next unless valid_associations.include? r["authorAssociation"] - email = if r["author"]["email"].blank? - "#{r["author"]["databaseId"]}+#{r["author"]["login"]}@users.noreply.github.com" - else - r["author"]["email"] - end + email = r["author"]["email"].presence || + "#{r["author"]["databaseId"]}+#{r["author"]["login"]}@users.noreply.github.com" - name = r["author"]["name"].presence || r["author"]["login"] + name = r["author"]["name"].presence || + r["author"]["login"] { "email" => email, diff --git a/Library/Homebrew/utils/shared_audits.rb b/Library/Homebrew/utils/shared_audits.rb index 6587672c8e..bd176425ea 100644 --- a/Library/Homebrew/utils/shared_audits.rb +++ b/Library/Homebrew/utils/shared_audits.rb @@ -107,7 +107,7 @@ module SharedAudits 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)" end