diff --git a/Library/Homebrew/PATH.rb b/Library/Homebrew/PATH.rb index ac9f408a93..8fb2269987 100644 --- a/Library/Homebrew/PATH.rb +++ b/Library/Homebrew/PATH.rb @@ -47,15 +47,13 @@ class PATH alias to_s to_str def ==(other) - if other.respond_to?(:to_ary) - return true if to_ary == other.to_ary + if other.respond_to?(:to_ary) && to_ary == other.to_ary + true + elsif other.respond_to?(:to_str) && to_str == other.to_str + true + else + false end - - if other.respond_to?(:to_str) - return true if to_str == other.to_str - end - - false end def empty? diff --git a/Library/Homebrew/cask.rb b/Library/Homebrew/cask.rb index 0e2132e78e..e39f0328b1 100644 --- a/Library/Homebrew/cask.rb +++ b/Library/Homebrew/cask.rb @@ -13,7 +13,6 @@ require "cask/exceptions" require "cask/denylist" require "cask/download" require "cask/dsl" -require "cask/exceptions" require "cask/installer" require "cask/macos" require "cask/metadata" diff --git a/Library/Homebrew/cask/artifact/stage_only.rb b/Library/Homebrew/cask/artifact/stage_only.rb index 78efa24d5d..a013388e25 100644 --- a/Library/Homebrew/cask/artifact/stage_only.rb +++ b/Library/Homebrew/cask/artifact/stage_only.rb @@ -14,10 +14,6 @@ module Cask new(cask) end - def initialize(cask) - super(cask) - end - def to_a [true] end diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index e1702e43c7..f9628b1d4c 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -380,10 +380,10 @@ module Cask add_warning "cask token contains .app" if token.end_with? ".app" - if /-(?alpha|beta|rc|release-candidate)$/ =~ cask.token - if cask.tap.official? && cask.tap != "homebrew/cask-versions" - add_warning "cask token contains version designation '#{designation}'" - end + if /-(?alpha|beta|rc|release-candidate)$/ =~ cask.token && + cask.tap.official? && + cask.tap != "homebrew/cask-versions" + add_warning "cask token contains version designation '#{designation}'" end add_warning "cask token mentions launcher" if token.end_with? "launcher" diff --git a/Library/Homebrew/cask/cmd/uninstall.rb b/Library/Homebrew/cask/cmd/uninstall.rb index c02d68cf63..89a85cd20a 100644 --- a/Library/Homebrew/cask/cmd/uninstall.rb +++ b/Library/Homebrew/cask/cmd/uninstall.rb @@ -44,9 +44,9 @@ module Cask odebug "Uninstalling Cask #{cask}" if cask.installed? - if installed_caskfile = cask.installed_caskfile + if (installed_caskfile = cask.installed_caskfile) && installed_caskfile.exist? # Use the same cask file that was used for installation, if possible. - cask = CaskLoader.load(installed_caskfile) if installed_caskfile.exist? + cask = CaskLoader.load(installed_caskfile) end else raise CaskNotInstalledError, cask unless force diff --git a/Library/Homebrew/cask/cmd/zap.rb b/Library/Homebrew/cask/cmd/zap.rb index 9b208899ab..c2e981301b 100644 --- a/Library/Homebrew/cask/cmd/zap.rb +++ b/Library/Homebrew/cask/cmd/zap.rb @@ -32,9 +32,9 @@ module Cask odebug "Zapping Cask #{cask}" if cask.installed? - if installed_caskfile = cask.installed_caskfile + if (installed_caskfile = cask.installed_caskfile) && installed_caskfile.exist? # Use the same cask file that was used for installation, if possible. - cask = CaskLoader.load(installed_caskfile) if installed_caskfile.exist? + cask = CaskLoader.load(installed_caskfile) end else raise CaskNotInstalledError, cask unless args.force? diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index cc8f451d98..2f8b2c8cfd 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -285,10 +285,8 @@ module Cask end end - def respond_to_missing?(*) - super - end - + # No need to define it as its the default/superclass implementation. + # rubocop:disable Style/MissingRespondToMissing def method_missing(method, *) if method Utils.method_missing_message(method, token) @@ -297,6 +295,7 @@ module Cask super end end + # rubocop:enable Style/MissingRespondToMissing def appdir cask.config.appdir diff --git a/Library/Homebrew/cask/dsl/base.rb b/Library/Homebrew/cask/dsl/base.rb index 4ea58e01e9..f8d40aadd6 100644 --- a/Library/Homebrew/cask/dsl/base.rb +++ b/Library/Homebrew/cask/dsl/base.rb @@ -21,10 +21,8 @@ module Cask @command.run!(executable, **options) end - def respond_to_missing?(*) - super - end - + # No need to define it as its the default/superclass implementation. + # rubocop:disable Style/MissingRespondToMissing def method_missing(method, *) if method underscored_class = self.class.name.gsub(/([[:lower:]])([[:upper:]][[:lower:]])/, '\1_\2').downcase @@ -35,6 +33,7 @@ module Cask super end end + # rubocop:enable Style/MissingRespondToMissing end end end diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index e28e4fa093..009c66d68c 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -214,9 +214,7 @@ module Cask odebug "Installing artifact of class #{artifact.class}" - if artifact.is_a?(Artifact::Binary) - next unless binaries? - end + next if artifact.is_a?(Artifact::Binary) && !binaries? artifact.install_phase(command: @command, verbose: verbose?, force: force?) already_installed_artifacts.unshift(artifact) @@ -226,13 +224,11 @@ module Cask rescue => e begin already_installed_artifacts.each do |artifact| - next unless artifact.respond_to?(:uninstall_phase) + if artifact.respond_to?(:uninstall_phase) + odebug "Reverting installation of artifact of class #{artifact.class}" + artifact.uninstall_phase(command: @command, verbose: verbose?, force: force?) + end - odebug "Reverting installation of artifact of class #{artifact.class}" - artifact.uninstall_phase(command: @command, verbose: verbose?, force: force?) - end - - already_installed_artifacts.each do |artifact| next unless artifact.respond_to?(:post_uninstall_phase) odebug "Reverting installation of artifact of class #{artifact.class}" @@ -455,13 +451,13 @@ module Cask odebug "#{artifacts.length} artifact/s defined", artifacts artifacts.each do |artifact| - next unless artifact.respond_to?(:uninstall_phase) + if artifact.respond_to?(:uninstall_phase) + odebug "Uninstalling artifact of class #{artifact.class}" + artifact.uninstall_phase( + command: @command, verbose: verbose?, skip: clear, force: force?, upgrade: upgrade?, + ) + end - odebug "Uninstalling artifact of class #{artifact.class}" - artifact.uninstall_phase(command: @command, verbose: verbose?, skip: clear, force: force?, upgrade: upgrade?) - end - - artifacts.each do |artifact| next unless artifact.respond_to?(:post_uninstall_phase) odebug "Post-uninstalling artifact of class #{artifact.class}" diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 5a03ec590c..107998cde5 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -416,9 +416,7 @@ module Homebrew path.extend(ObserverPathnameExtension) if path.symlink? unless path.resolved_path_exists? - if path.to_s.match?(Keg::INFOFILE_RX) - path.uninstall_info unless dry_run? - end + path.uninstall_info if path.to_s.match?(Keg::INFOFILE_RX) && !dry_run? if dry_run? puts "Would remove (broken link): #{path}" diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index 14c87cc102..f9757b7af0 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -63,8 +63,8 @@ module Homebrew def info args = info_args.parse - if args.days.present? - raise UsageError, "--days must be one of #{VALID_DAYS.join(", ")}" unless VALID_DAYS.include?(args.days) + if args.days.present? && !VALID_DAYS.include?(args.days) + raise UsageError, "--days must be one of #{VALID_DAYS.join(", ")}" end if args.category.present? @@ -79,10 +79,7 @@ module Homebrew if args.json raise UsageError, "invalid JSON version: #{args.json}" unless ["v1", true].include? args.json - - if !(args.all? || args.installed?) && args.no_named? - raise FormulaUnspecifiedError if args.no_named? - end + raise FormulaUnspecifiedError if !(args.all? || args.installed?) && args.no_named? print_json(args: args) elsif args.github? diff --git a/Library/Homebrew/compat/cli/parser.rb b/Library/Homebrew/compat/cli/parser.rb index ec330bb23c..ee9e3964ad 100644 --- a/Library/Homebrew/compat/cli/parser.rb +++ b/Library/Homebrew/compat/cli/parser.rb @@ -5,10 +5,8 @@ module Homebrew class Parser module Compat module DeprecatedArgs - def respond_to_missing?(*) - super - end - + # No need to define it as its the default/superclass implementation. + # rubocop:disable Style/MissingRespondToMissing def method_missing(method, *) if ![:debug?, :quiet?, :verbose?, :value].include?(method) && !@printed_args_warning odeprecated "Homebrew.args", "`args = _args.parse` and pass `args` along the call chain" @@ -17,6 +15,7 @@ module Homebrew super end + # rubocop:enable Style/MissingRespondToMissing end def parse(*) diff --git a/Library/Homebrew/description_cache_store.rb b/Library/Homebrew/description_cache_store.rb index 93138181ab..ac8820fb38 100644 --- a/Library/Homebrew/description_cache_store.rb +++ b/Library/Homebrew/description_cache_store.rb @@ -81,11 +81,6 @@ class DescriptionCacheStore < CacheStore private - # Not implemented; access is through `Searchable`. - def fetch - super - end - # `select` from the underlying database. def select(&block) database.select(&block) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 590037223d..c03574b4a7 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -1030,8 +1030,8 @@ module Homebrew def audit_download_strategy url_strategy = DownloadStrategyDetector.detect(url) - if using == :git || url_strategy == GitDownloadStrategy - problem "Git should specify :revision when a :tag is specified." if specs[:tag] && !specs[:revision] + if (using == :git || url_strategy == GitDownloadStrategy) && specs[:tag] && !specs[:revision] + problem "Git should specify :revision when a :tag is specified." end return unless using diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 21ad88677a..66c8b28a3f 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -187,12 +187,10 @@ module Homebrew absolute_symlinks_start_with_string << pn if link.to_s.start_with?(string) end - if args.verbose? - unless absolute_symlinks_start_with_string.empty? - opoo "Absolute symlink starting with #{string}:" - absolute_symlinks_start_with_string.each do |pn| - puts " #{pn} -> #{pn.resolved_path}" - end + if args.verbose? && absolute_symlinks_start_with_string.present? + opoo "Absolute symlink starting with #{string}:" + absolute_symlinks_start_with_string.each do |pn| + puts " #{pn} -> #{pn.resolved_path}" end end diff --git a/Library/Homebrew/dev-cmd/pr-pull.rb b/Library/Homebrew/dev-cmd/pr-pull.rb index da5725d4d4..be6586ae77 100644 --- a/Library/Homebrew/dev-cmd/pr-pull.rb +++ b/Library/Homebrew/dev-cmd/pr-pull.rb @@ -215,8 +215,8 @@ module Homebrew bintray_key = ENV["HOMEBREW_BINTRAY_KEY"] bintray_org = args.bintray_org || "homebrew" - if bintray_user.blank? || bintray_key.blank? - odie "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" if !args.dry_run? && !args.no_upload? + if (bintray_user.blank? || bintray_key.blank?) && !args.dry_run? && !args.no_upload? + odie "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" end workflow = args.workflow || "tests.yml" diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 7f53003ef8..6661f22bc9 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -656,11 +656,6 @@ module Homebrew end next if status.blank? - # these will result in uncommitted gems. - if path == HOMEBREW_REPOSITORY - next if ENV["HOMEBREW_SORBET"] - end - message ||= "" message += "\n" unless message.empty? message += <<~EOS diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 7a16ac59b7..c0e374bff3 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -19,6 +19,8 @@ require "active_support/core_ext/object/try" require "active_support/core_ext/array/access" require "active_support/core_ext/string/inflections" require "active_support/core_ext/array/conversions" +require "active_support/core_ext/hash/deep_merge" +require "active_support/core_ext/file/atomic" I18n.backend.available_locales # Initialize locales so they can be overwritten. I18n.backend.store_translations :en, support: { array: { last_word_connector: " and " } } @@ -66,7 +68,6 @@ HOMEBREW_DEFAULT_PREFIX = "/usr/local" LINUXBREW_DEFAULT_PREFIX = "/home/linuxbrew/.linuxbrew" require "fileutils" -require "os" require "os/global" module Homebrew @@ -123,9 +124,6 @@ end.compact.freeze require "set" require "extend/string" -require "active_support/core_ext/object/blank" -require "active_support/core_ext/hash/deep_merge" -require "active_support/core_ext/file/atomic" require "system_command" require "exceptions" diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index 00668f1250..d2b3afc72d 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -297,8 +297,8 @@ class Keg next if aliases.include?(a) alias_opt_symlink = opt/a - if alias_opt_symlink.symlink? && alias_opt_symlink.exist? - alias_opt_symlink.delete if rack == alias_opt_symlink.realpath.parent + if alias_opt_symlink.symlink? && alias_opt_symlink.exist? && rack == alias_opt_symlink.realpath.parent + alias_opt_symlink.delete end alias_linkedkegs_symlink = linkedkegs/a diff --git a/Library/Homebrew/rubocops/options.rb b/Library/Homebrew/rubocops/options.rb index d5766145c6..907a98c18b 100644 --- a/Library/Homebrew/rubocops/options.rb +++ b/Library/Homebrew/rubocops/options.rb @@ -18,11 +18,9 @@ module RuboCop option_call_nodes.each do |option_call| option = parameters(option_call).first problem DEPRECATION_MSG if regex_match_group(option, /32-bit/) - end - option_call_nodes.each do |option_call| offending_node(option_call) - option = string_content(parameters(option_call).first) + option = string_content(option) problem UNI_DEPRECATION_MSG if option == "universal" if option !~ /with(out)?-/ && diff --git a/Library/Homebrew/rubocops/patches.rb b/Library/Homebrew/rubocops/patches.rb index 25afeb601c..03c9aa8d14 100644 --- a/Library/Homebrew/rubocops/patches.rb +++ b/Library/Homebrew/rubocops/patches.rb @@ -48,13 +48,11 @@ module RuboCop end gh_patch_param_pattern = %r{https?://github\.com/.+/.+/(?:commit|pull)/[a-fA-F0-9]*.(?:patch|diff)} - if regex_match_group(patch, gh_patch_param_pattern) - unless patch_url.match?(/\?full_index=\w+$/) - problem <<~EOS - GitHub patches should use the full_index parameter: - #{patch_url}?full_index=1 - EOS - end + if regex_match_group(patch, gh_patch_param_pattern) && !patch_url.match?(/\?full_index=\w+$/) + problem <<~EOS + GitHub patches should use the full_index parameter: + #{patch_url}?full_index=1 + EOS end gh_patch_patterns = Regexp.union([%r{/raw\.github\.com/}, @@ -62,13 +60,11 @@ module RuboCop %r{gist\.github\.com/raw}, %r{gist\.github\.com/.+/raw}, %r{gist\.githubusercontent\.com/.+/raw}]) - if regex_match_group(patch, gh_patch_patterns) - unless patch_url.match?(%r{/[a-fA-F0-9]{6,40}/}) - problem <<~EOS.chomp - GitHub/Gist patches should specify a revision: - #{patch_url} - EOS - end + if regex_match_group(patch, gh_patch_patterns) && !patch_url.match?(%r{/[a-fA-F0-9]{6,40}/}) + problem <<~EOS.chomp + GitHub/Gist patches should specify a revision: + #{patch_url} + EOS end gh_patch_diff_pattern = diff --git a/Library/Homebrew/rubocops/shared/desc_helper.rb b/Library/Homebrew/rubocops/shared/desc_helper.rb index e780ad4503..e393b7835b 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -64,8 +64,10 @@ module RuboCop name_regex = name.delete("-").split("").join('[\s\-]?') problem "Description shouldn't start with the #{type} name." if regex_match_group(desc, /^#{name_regex}\b/i) - if type == :cask && match = regex_match_group(desc, /\b(macOS|Mac( ?OS( ?X)?)?|OS ?X)\b/i) - problem "Description shouldn't contain the platform." if match[1] != "MAC" + if type == :cask && + (match = regex_match_group(desc, /\b(macOS|Mac( ?OS( ?X)?)?|OS ?X)\b/i)) && + match[1] != "MAC" + problem "Description shouldn't contain the platform." end # Check if a full stop is used at the end of a desc (apart from in the case of "etc."). diff --git a/Library/Homebrew/system_config.rb b/Library/Homebrew/system_config.rb index 8df4e5cfec..7e67f599b9 100644 --- a/Library/Homebrew/system_config.rb +++ b/Library/Homebrew/system_config.rb @@ -145,10 +145,7 @@ module SystemConfig value = Homebrew::EnvConfig.send(method_name) next unless value - - if (default = hash[:default].presence) - next if value.to_s == default.to_s - end + next if (default = hash[:default].presence) && value.to_s == default.to_s if ENV.sensitive?(env) f.puts "#{env}: set" diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 565783751a..32b68ce230 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -272,8 +272,8 @@ class Tap begin safe_system "git", *args - unless Readall.valid_tap?(self, aliases: true) - raise "Cannot tap #{name}: invalid syntax in tap!" unless Homebrew::EnvConfig.developer? + if !Readall.valid_tap?(self, aliases: true) && !Homebrew::EnvConfig.developer? + raise "Cannot tap #{name}: invalid syntax in tap!" end rescue Interrupt, RuntimeError ignore_interrupts do diff --git a/Library/Homebrew/test/software_spec_spec.rb b/Library/Homebrew/test/software_spec_spec.rb index fd294b48f0..34278b48e4 100644 --- a/Library/Homebrew/test/software_spec_spec.rb +++ b/Library/Homebrew/test/software_spec_spec.rb @@ -192,9 +192,6 @@ describe BottleSpecification do checksums.each_pair do |cat, digest| subject.sha256(digest => cat) - end - - checksums.each_pair do |cat, digest| checksum, = subject.checksum_for(cat) expect(Checksum.new(:sha256, digest)).to eq(checksum) end diff --git a/Library/Homebrew/utils/analytics.rb b/Library/Homebrew/utils/analytics.rb index 60951fb6c0..c6c1c9b8f3 100644 --- a/Library/Homebrew/utils/analytics.rb +++ b/Library/Homebrew/utils/analytics.rb @@ -138,9 +138,8 @@ module Utils else item["formula"] end - if filter.present? - next if key != filter && !key.start_with?("#{filter} ") - end + next if filter.present? && key != filter && !key.start_with?("#{filter} ") + results[key] = item["count"].tr(",", "").to_i end @@ -163,12 +162,8 @@ module Utils value.each do |days, results| days = days.to_i if full_analytics - if args.days.present? - next if args.days&.to_i != days - end - if args.category.present? - next if args.category != category - end + next if args.days.present? && args.days&.to_i != days + next if args.category.present? && args.category != category table_output(category, days, results) else