From d64429a736db2d9fbe4c85f9c8c4480d58fdf656 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Tue, 19 Feb 2019 13:11:32 +0000 Subject: [PATCH] rubocop: enable Style/IfUnlessModifier. --- Library/.rubocop_shared.yml | 3 +- Library/Homebrew/.rubocop.yml | 4 ++ Library/Homebrew/brew.rb | 12 +--- .../cask/artifact/abstract_uninstall.rb | 4 +- Library/Homebrew/cask/artifact/artifact.rb | 4 +- Library/Homebrew/cask/artifact/installer.rb | 4 +- Library/Homebrew/cask/artifact/pkg.rb | 4 +- Library/Homebrew/cask/artifact/stage_only.rb | 4 +- Library/Homebrew/cask/audit.rb | 8 +-- Library/Homebrew/cask/cask_loader.rb | 16 ++--- Library/Homebrew/cask/dsl.rb | 4 +- Library/Homebrew/cask/installer.rb | 12 +--- Library/Homebrew/cask/metadata.rb | 12 +--- Library/Homebrew/caveats.rb | 16 ++--- Library/Homebrew/cleaner.rb | 8 +-- Library/Homebrew/cleanup.rb | 8 +-- Library/Homebrew/cli_parser.rb | 4 +- Library/Homebrew/cmd/deps.rb | 4 +- Library/Homebrew/cmd/gist-logs.rb | 4 +- Library/Homebrew/cmd/info.rb | 4 +- Library/Homebrew/cmd/install.rb | 12 +--- Library/Homebrew/cmd/list.rb | 4 +- Library/Homebrew/cmd/update-report.rb | 12 +--- Library/Homebrew/compilers.rb | 4 +- Library/Homebrew/config.rb | 8 +-- Library/Homebrew/cxxstdlib.rb | 8 +-- Library/Homebrew/dependencies.rb | 12 +--- Library/Homebrew/dependency_collector.rb | 4 +- Library/Homebrew/dev-cmd/audit.rb | 60 +++++-------------- Library/Homebrew/dev-cmd/bottle.rb | 28 +++------ Library/Homebrew/dev-cmd/bump-formula-pr.rb | 20 ++----- Library/Homebrew/dev-cmd/extract.rb | 20 ++----- Library/Homebrew/dev-cmd/man.rb | 4 +- Library/Homebrew/dev-cmd/mirror.rb | 4 +- Library/Homebrew/dev-cmd/pull.rb | 40 ++++--------- Library/Homebrew/diagnostic.rb | 4 +- Library/Homebrew/download_strategy.rb | 4 +- Library/Homebrew/extend/ENV/super.rb | 4 +- .../Homebrew/extend/os/mac/system_config.rb | 12 +--- Library/Homebrew/extend/pathname.rb | 4 +- Library/Homebrew/extend/string.rb | 12 +--- Library/Homebrew/formula.rb | 24 ++------ Library/Homebrew/formula_installer.rb | 20 ++----- Library/Homebrew/formulary.rb | 40 ++++--------- Library/Homebrew/global.rb | 4 +- Library/Homebrew/keg.rb | 12 +--- Library/Homebrew/language/node.rb | 4 +- Library/Homebrew/load_path.rb | 4 +- Library/Homebrew/locale.rb | 8 +-- Library/Homebrew/migrator.rb | 8 +-- Library/Homebrew/os/mac/xquartz.rb | 4 +- .../requirements/codesign_requirement.rb | 8 +-- Library/Homebrew/resource.rb | 4 +- Library/Homebrew/rubocops/checksum.rb | 8 +-- Library/Homebrew/rubocops/extend/formula.rb | 4 +- Library/Homebrew/rubocops/formula_desc.rb | 8 +-- Library/Homebrew/rubocops/lines.rb | 8 +-- Library/Homebrew/rubocops/urls.rb | 4 +- Library/Homebrew/software_spec.rb | 4 +- Library/Homebrew/style.rb | 8 +-- Library/Homebrew/system_config.rb | 12 +--- Library/Homebrew/tab.rb | 8 +-- Library/Homebrew/tap.rb | 12 +--- Library/Homebrew/test/spec_helper.rb | 8 +-- Library/Homebrew/test/support/lib/config.rb | 4 +- Library/Homebrew/unpack_strategy/tar.rb | 4 +- Library/Homebrew/utils.rb | 8 +-- Library/Homebrew/utils/github.rb | 8 +-- Library/Homebrew/utils/tty.rb | 4 +- Library/Homebrew/version.rb | 8 +-- 70 files changed, 173 insertions(+), 506 deletions(-) diff --git a/Library/.rubocop_shared.yml b/Library/.rubocop_shared.yml index 5c2922e020..32d122760f 100644 --- a/Library/.rubocop_shared.yml +++ b/Library/.rubocop_shared.yml @@ -49,8 +49,7 @@ Style/CollectionMethods: Style/FormatStringToken: EnforcedStyle: template -# This often leads to lines longer than the maximum line length. -# https://github.com/rubocop-hq/rubocop/issues/6149 +# This shouldn't be enabled until LineLength is lower. Style/IfUnlessModifier: Enabled: false diff --git a/Library/Homebrew/.rubocop.yml b/Library/Homebrew/.rubocop.yml index 317c6ffd63..625c9a8fcb 100644 --- a/Library/Homebrew/.rubocop.yml +++ b/Library/Homebrew/.rubocop.yml @@ -125,6 +125,10 @@ Style/GuardClause: Style/HashSyntax: EnforcedStyle: ruby19_no_mixed_keys +# LineLength is low enough here to re-enable it. +Style/IfUnlessModifier: + Enabled: true + # so many of these in formulae but none in here Style/TrailingBodyOnMethodDefinition: Enabled: true diff --git a/Library/Homebrew/brew.rb b/Library/Homebrew/brew.rb index ad8734b629..f7ca49a6ef 100644 --- a/Library/Homebrew/brew.rb +++ b/Library/Homebrew/brew.rb @@ -1,6 +1,4 @@ -unless ENV["HOMEBREW_BREW_FILE"] - raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" -end +raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" unless ENV["HOMEBREW_BREW_FILE"] std_trap = trap("INT") { exit! 130 } # no backtrace thanks @@ -92,9 +90,7 @@ begin # `Homebrew.help` never returns, except for external/unknown commands. end - if ENV["HOMEBREW_BUILD_FROM_SOURCE"] - odisabled("HOMEBREW_BUILD_FROM_SOURCE", "--build-from-source") - end + odisabled("HOMEBREW_BUILD_FROM_SOURCE", "--build-from-source") if ENV["HOMEBREW_BUILD_FROM_SOURCE"] if internal_cmd Homebrew.send cmd.to_s.tr("-", "_").downcase @@ -113,9 +109,7 @@ begin brew_uid = HOMEBREW_BREW_FILE.stat.uid tap_commands = [] - if Process.uid.zero? && !brew_uid.zero? - tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] - end + tap_commands += %W[/usr/bin/sudo -u ##{brew_uid}] if Process.uid.zero? && !brew_uid.zero? # Unset HOMEBREW_HELP to avoid confusing the tap ENV.delete("HOMEBREW_HELP") if help_flag tap_commands += %W[#{HOMEBREW_BREW_FILE} tap #{possible_tap}] diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index 531e20c653..7bef09818a 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -179,9 +179,7 @@ module Cask # :signal should come after :quit so it can be used as a backup when :quit fails def uninstall_signal(*signals, command: nil, **_) signals.each do |pair| - unless pair.size == 2 - raise CaskInvalidError.new(cask, "Each #{stanza} :signal must consist of 2 elements.") - end + raise CaskInvalidError.new(cask, "Each #{stanza} :signal must consist of 2 elements.") unless pair.size == 2 signal, bundle_id = pair ohai "Signalling '#{signal}' to application ID '#{bundle_id}'" diff --git a/Library/Homebrew/cask/artifact/artifact.rb b/Library/Homebrew/cask/artifact/artifact.rb index 28907292d5..39c7511305 100644 --- a/Library/Homebrew/cask/artifact/artifact.rb +++ b/Library/Homebrew/cask/artifact/artifact.rb @@ -13,9 +13,7 @@ module Cask def self.from_args(cask, *args) source_string, target_hash = args - if source_string.nil? - raise CaskInvalidError.new(cask.token, "no source given for #{english_name}") - end + raise CaskInvalidError.new(cask.token, "no source given for #{english_name}") if source_string.nil? unless target_hash.is_a?(Hash) raise CaskInvalidError.new(cask.token, "target required for #{english_name} '#{source_string}'") diff --git a/Library/Homebrew/cask/artifact/installer.rb b/Library/Homebrew/cask/artifact/installer.rb index 05811ec122..9f417617ec 100644 --- a/Library/Homebrew/cask/artifact/installer.rb +++ b/Library/Homebrew/cask/artifact/installer.rb @@ -32,9 +32,7 @@ module Cask cask.staged_path.join(path) end - if absolute_path.exist? && !absolute_path.executable? - FileUtils.chmod "+x", absolute_path - end + FileUtils.chmod "+x", absolute_path if absolute_path.exist? && !absolute_path.executable? executable = if absolute_path.exist? absolute_path diff --git a/Library/Homebrew/cask/artifact/pkg.rb b/Library/Homebrew/cask/artifact/pkg.rb index add64dbebf..505bbbb95a 100644 --- a/Library/Homebrew/cask/artifact/pkg.rb +++ b/Library/Homebrew/cask/artifact/pkg.rb @@ -46,9 +46,7 @@ module Cask "-target", "/" ] args << "-verboseR" if verbose - if stanza_options.fetch(:allow_untrusted, false) - args << "-allowUntrusted" - end + args << "-allowUntrusted" if stanza_options.fetch(:allow_untrusted, false) with_choices_file do |choices_path| args << "-applyChoiceChangesXML" << choices_path if choices_path env = { diff --git a/Library/Homebrew/cask/artifact/stage_only.rb b/Library/Homebrew/cask/artifact/stage_only.rb index 3d45dc057f..add6ba3dab 100644 --- a/Library/Homebrew/cask/artifact/stage_only.rb +++ b/Library/Homebrew/cask/artifact/stage_only.rb @@ -4,9 +4,7 @@ module Cask module Artifact class StageOnly < AbstractArtifact def self.from_args(cask, *args) - if args != [true] - raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true") - end + raise CaskInvalidError.new(cask.token, "'stage_only' takes only a single argument: true") if args != [true] new(cask) end diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 1c6f5d8540..77186462dc 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -106,18 +106,14 @@ module Cask k.directives.key?(:uninstall_preflight) end - if count > 1 - add_warning "only a single uninstall_preflight stanza is allowed" - end + add_warning "only a single uninstall_preflight stanza is allowed" if count > 1 count = cask.artifacts.count do |k| k.is_a?(Artifact::PostflightBlock) && k.directives.key?(:uninstall_postflight) end - if count > 1 - add_warning "only a single uninstall_postflight stanza is allowed" - end + add_warning "only a single uninstall_postflight stanza is allowed" if count > 1 return unless cask.artifacts.count { |k| k.is_a?(Artifact::Zap) } > 1 diff --git a/Library/Homebrew/cask/cask_loader.rb b/Library/Homebrew/cask/cask_loader.rb index 70ccf15d25..1416442b84 100644 --- a/Library/Homebrew/cask/cask_loader.rb +++ b/Library/Homebrew/cask/cask_loader.rb @@ -58,9 +58,7 @@ module Cask begin instance_eval(content, path).tap do |cask| - unless cask.is_a?(Cask) - raise CaskUnreadableError.new(token, "'#{path}' does not contain a cask.") - end + raise CaskUnreadableError.new(token, "'#{path}' does not contain a cask.") unless cask.is_a?(Cask) end rescue NameError, ArgumentError, ScriptError => e raise CaskUnreadableError.new(token, e.message) @@ -70,9 +68,7 @@ module Cask private def cask(header_token, **options, &block) - if token != header_token - raise CaskTokenMismatchError.new(token, header_token) - end + raise CaskTokenMismatchError.new(token, header_token) if token != header_token super(header_token, **options, sourcefile_path: path, &block) end @@ -192,9 +188,7 @@ module Cask return loader_class.new(ref) if loader_class.can_load?(ref) end - if FromTapPathLoader.can_load?(default_path(ref)) - return FromTapPathLoader.new(default_path(ref)) - end + return FromTapPathLoader.new(default_path(ref)) if FromTapPathLoader.can_load?(default_path(ref)) case (possible_tap_casks = tap_paths(ref)).count when 1 @@ -209,9 +203,7 @@ module Cask end possible_installed_cask = Cask.new(ref) - if possible_installed_cask.installed? - return FromPathLoader.new(possible_installed_cask.installed_caskfile) - end + return FromPathLoader.new(possible_installed_cask.installed_caskfile) if possible_installed_cask.installed? NullLoader.new(ref) end diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index 5a9b540a6b..57ff905511 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -131,9 +131,7 @@ module Cask return @language = nil if @language_blocks.nil? || @language_blocks.empty? - if @language_blocks.default.nil? - raise CaskInvalidError.new(cask, "No default language specified.") - end + raise CaskInvalidError.new(cask, "No default language specified.") if @language_blocks.default.nil? locales = MacOS.languages .map do |language| diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index 88b8e83193..67a14da2a2 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -82,9 +82,7 @@ module Cask old_config = @cask.config - if @cask.installed? && !force? && !reinstall? && !upgrade? - raise CaskAlreadyInstalledError, @cask - end + raise CaskAlreadyInstalledError, @cask if @cask.installed? && !force? && !reinstall? && !upgrade? check_conflicts @@ -100,9 +98,7 @@ module Cask install_artifacts - unless @cask.tap&.private? - ::Utils::Analytics.report_event("cask_install", @cask.token) - end + ::Utils::Analytics.report_event("cask_install", @cask.token) unless @cask.tap&.private? puts summary end @@ -113,9 +109,7 @@ module Cask @cask.conflicts_with[:cask].each do |conflicting_cask| begin conflicting_cask = CaskLoader.load(conflicting_cask) - if conflicting_cask.installed? - raise CaskConflictError.new(@cask, conflicting_cask) - end + raise CaskConflictError.new(@cask, conflicting_cask) if conflicting_cask.installed? rescue CaskUnavailableError next # Ignore conflicting Casks that do not exist. end diff --git a/Library/Homebrew/cask/metadata.rb b/Library/Homebrew/cask/metadata.rb index 8335232dee..276554b354 100644 --- a/Library/Homebrew/cask/metadata.rb +++ b/Library/Homebrew/cask/metadata.rb @@ -9,17 +9,13 @@ module Cask def metadata_versioned_path(version: self.version) cask_version = (version || :unknown).to_s - if cask_version.empty? - raise CaskError, "Cannot create metadata path with empty version." - end + raise CaskError, "Cannot create metadata path with empty version." if cask_version.empty? metadata_master_container_path.join(cask_version) end def metadata_timestamped_path(version: self.version, timestamp: :latest, create: false) - if create && timestamp == :latest - raise CaskError, "Cannot create metadata path when timestamp is :latest." - end + raise CaskError, "Cannot create metadata path when timestamp is :latest." if create && timestamp == :latest path = if timestamp == :latest Pathname.glob(metadata_versioned_path(version: version).join("*")).max @@ -37,9 +33,7 @@ module Cask end def metadata_subdir(leaf, version: self.version, timestamp: :latest, create: false) - if create && timestamp == :latest - raise CaskError, "Cannot create metadata subdir when timestamp is :latest." - end + raise CaskError, "Cannot create metadata subdir when timestamp is :latest." if create && timestamp == :latest unless leaf.respond_to?(:empty?) && !leaf.empty? raise CaskError, "Cannot create metadata subdir for empty leaf." diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 0c4f56bd1b..7a85c71897 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -47,12 +47,8 @@ class Caveats If you need to have #{f.name} first in your PATH run: EOS - if f.bin.directory? - s << " #{Utils::Shell.prepend_path_in_profile(f.opt_bin.to_s)}\n" - end - if f.sbin.directory? - s << " #{Utils::Shell.prepend_path_in_profile(f.opt_sbin.to_s)}\n" - end + s << " #{Utils::Shell.prepend_path_in_profile(f.opt_bin.to_s)}\n" if f.bin.directory? + s << " #{Utils::Shell.prepend_path_in_profile(f.opt_sbin.to_s)}\n" if f.sbin.directory? end if f.lib.directory? || f.include.directory? @@ -61,13 +57,9 @@ class Caveats For compilers to find #{f.name} you may need to set: EOS - if f.lib.directory? - s << " #{Utils::Shell.export_value("LDFLAGS", "-L#{f.opt_lib}")}\n" - end + s << " #{Utils::Shell.export_value("LDFLAGS", "-L#{f.opt_lib}")}\n" if f.lib.directory? - if f.include.directory? - s << " #{Utils::Shell.export_value("CPPFLAGS", "-I#{f.opt_include}")}\n" - end + s << " #{Utils::Shell.export_value("CPPFLAGS", "-I#{f.opt_include}")}\n" if f.include.directory? if which("pkg-config", ENV["HOMEBREW_PATH"]) && ((f.lib/"pkgconfig").directory? || (f.share/"pkgconfig").directory?) diff --git a/Library/Homebrew/cleaner.rb b/Library/Homebrew/cleaner.rb index 6fc4ef0774..d6c7e7f33c 100644 --- a/Library/Homebrew/cleaner.rb +++ b/Library/Homebrew/cleaner.rb @@ -25,9 +25,7 @@ class Cleaner # Get rid of any info 'dir' files, so they don't conflict at the link stage info_dir_file = @f.info + "dir" - if info_dir_file.file? && !@f.skip_clean?(info_dir_file) - observe_file_removal info_dir_file - end + observe_file_removal info_dir_file if info_dir_file.file? && !@f.skip_clean?(info_dir_file) prune end @@ -111,9 +109,7 @@ class Cleaner end if ARGV.debug? old_perms = path.stat.mode & 0777 - if perms != old_perms - puts "Fixing #{path} permissions from #{old_perms.to_s(8)} to #{perms.to_s(8)}" - end + puts "Fixing #{path} permissions from #{old_perms.to_s(8)} to #{perms.to_s(8)}" if perms != old_perms end path.chmod perms end diff --git a/Library/Homebrew/cleanup.rb b/Library/Homebrew/cleanup.rb index 4b102b39d5..4a0691989e 100644 --- a/Library/Homebrew/cleanup.rb +++ b/Library/Homebrew/cleanup.rb @@ -120,9 +120,7 @@ module CleanupRefinement return false end - unless basename.to_s.match?(/\A#{Regexp.escape(name)}\-\-#{Regexp.escape(cask.version)}\b/) - return true - end + 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) @@ -334,9 +332,7 @@ module Homebrew def cleanup_lockfiles(*lockfiles) return if dry_run? - if lockfiles.empty? && HOMEBREW_LOCKS.directory? - lockfiles = HOMEBREW_LOCKS.children.select(&:file?) - end + lockfiles = HOMEBREW_LOCKS.children.select(&:file?) if lockfiles.empty? && HOMEBREW_LOCKS.directory? lockfiles.each do |file| next unless file.readable? diff --git a/Library/Homebrew/cli_parser.rb b/Library/Homebrew/cli_parser.rb index d8440aed6e..963111528e 100644 --- a/Library/Homebrew/cli_parser.rb +++ b/Library/Homebrew/cli_parser.rb @@ -220,9 +220,7 @@ module Homebrew if :mandatory.equal?(constraint_type) && primary_passed && !secondary_passed raise OptionConstraintError.new(primary, secondary) end - if secondary_passed && !primary_passed - raise OptionConstraintError.new(primary, secondary, missing: true) - end + raise OptionConstraintError.new(primary, secondary, missing: true) if secondary_passed && !primary_passed end end diff --git a/Library/Homebrew/cmd/deps.rb b/Library/Homebrew/cmd/deps.rb index 239e300d47..3effcedb02 100644 --- a/Library/Homebrew/cmd/deps.rb +++ b/Library/Homebrew/cmd/deps.rb @@ -200,9 +200,7 @@ module Homebrew "│ " end - if dep.is_a? Dependency - recursive_deps_tree(Formulary.factory(dep.name), prefix + prefix_addition, true) - end + recursive_deps_tree(Formulary.factory(dep.name), prefix + prefix_addition, true) if dep.is_a? Dependency end @dep_stack.pop diff --git a/Library/Homebrew/cmd/gist-logs.rb b/Library/Homebrew/cmd/gist-logs.rb index 66cb1dffe6..dbe0ad1810 100644 --- a/Library/Homebrew/cmd/gist-logs.rb +++ b/Library/Homebrew/cmd/gist-logs.rb @@ -73,9 +73,7 @@ module Homebrew end url = create_gist(files, descr) - if args.new_issue? - url = create_issue(f.tap, "#{f.name} failed to build on #{MacOS.full_version}", url) - end + url = create_issue(f.tap, "#{f.name} failed to build on #{MacOS.full_version}", url) if args.new_issue? puts url if url end diff --git a/Library/Homebrew/cmd/info.rb b/Library/Homebrew/cmd/info.rb index c13b62f8db..6e834a94c8 100644 --- a/Library/Homebrew/cmd/info.rb +++ b/Library/Homebrew/cmd/info.rb @@ -310,9 +310,7 @@ module Homebrew def output_analytics(filter: nil) days = args.days || "30" valid_days = %w[30 90 365] - unless valid_days.include?(days) - raise ArgumentError("Days must be one of #{valid_days.join(", ")}!") - end + raise ArgumentError("Days must be one of #{valid_days.join(", ")}!") unless valid_days.include?(days) category = args.category || "install" valid_categories = %w[install install-on-request build-error os-version] diff --git a/Library/Homebrew/cmd/install.rb b/Library/Homebrew/cmd/install.rb index 0369d1d8ef..ada9aef850 100644 --- a/Library/Homebrew/cmd/install.rb +++ b/Library/Homebrew/cmd/install.rb @@ -94,9 +94,7 @@ module Homebrew unless args.force? ARGV.named.each do |name| next if File.exist?(name) - if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_CASK_REGEX - next - end + next if name !~ HOMEBREW_TAP_FORMULA_REGEX && name !~ HOMEBREW_CASK_TAP_CASK_REGEX tap = Tap.fetch(Regexp.last_match(1), Regexp.last_match(2)) tap.install unless tap.installed? @@ -143,14 +141,10 @@ module Homebrew end # --HEAD, fail with no head defined - if args.head? && f.head.nil? - raise "No head is defined for #{f.full_name}" - end + raise "No head is defined for #{f.full_name}" if args.head? && f.head.nil? # --devel, fail with no devel defined - if args.devel? && f.devel.nil? - raise "No devel block is defined for #{f.full_name}" - end + raise "No devel block is defined for #{f.full_name}" if args.devel? && f.devel.nil? installed_head_version = f.latest_head_version if installed_head_version && diff --git a/Library/Homebrew/cmd/list.rb b/Library/Homebrew/cmd/list.rb index 15ceae6a86..03ad69e7a3 100644 --- a/Library/Homebrew/cmd/list.rb +++ b/Library/Homebrew/cmd/list.rb @@ -133,9 +133,7 @@ module Homebrew pinned_versions = {} names.sort.each do |d| keg_pin = (HOMEBREW_PINNED_KEGS/d.basename.to_s) - if keg_pin.exist? || keg_pin.symlink? - pinned_versions[d] = keg_pin.readlink.basename.to_s - end + pinned_versions[d] = keg_pin.readlink.basename.to_s if keg_pin.exist? || keg_pin.symlink? end pinned_versions.each do |d, version| puts d.basename.to_s.concat(args.versions? ? " #{version}" : "") diff --git a/Library/Homebrew/cmd/update-report.rb b/Library/Homebrew/cmd/update-report.rb index fc27295bd6..0de8847cd9 100644 --- a/Library/Homebrew/cmd/update-report.rb +++ b/Library/Homebrew/cmd/update-report.rb @@ -75,9 +75,7 @@ module Homebrew puts " #{Formatter.url("https://github.com/Homebrew/brew#donations")}\n" # Consider the message possibly missed if not a TTY. - if $stdout.tty? - safe_system "git", "config", "--local", "--replace-all", "homebrew.donationmessage", "true" - end + safe_system "git", "config", "--local", "--replace-all", "homebrew.donationmessage", "true" if $stdout.tty? end end @@ -88,9 +86,7 @@ module Homebrew initial_revision = ENV["HOMEBREW_UPDATE_BEFORE"].to_s current_revision = ENV["HOMEBREW_UPDATE_AFTER"].to_s - if initial_revision.empty? || current_revision.empty? - odie "update-report should not be called directly!" - end + odie "update-report should not be called directly!" if initial_revision.empty? || current_revision.empty? if initial_revision != current_revision update_preinstall_header @@ -121,9 +117,7 @@ module Homebrew end if !updated - if !ARGV.include?("--preinstall") && !ENV["HOMEBREW_UPDATE_FAILED"] - puts "Already up-to-date." - end + puts "Already up-to-date." if !ARGV.include?("--preinstall") && !ENV["HOMEBREW_UPDATE_FAILED"] else if hub.empty? puts "No changes to formulae." diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb index 5f79d32dce..a6afa499f3 100644 --- a/Library/Homebrew/compilers.rb +++ b/Library/Homebrew/compilers.rb @@ -18,9 +18,7 @@ class CompilerFailure def version(val = nil) if val @version = Version.parse(val.to_s) - if name.to_s == "clang" && val.to_i < 600 - odisabled "'fails_with :clang' with 'build' < 600" - end + odisabled "'fails_with :clang' with 'build' < 600" if name.to_s == "clang" && val.to_i < 600 end @version end diff --git a/Library/Homebrew/config.rb b/Library/Homebrew/config.rb index 36b44eb803..098177aff6 100644 --- a/Library/Homebrew/config.rb +++ b/Library/Homebrew/config.rb @@ -1,6 +1,4 @@ -unless ENV["HOMEBREW_BREW_FILE"] - raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" -end +raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" unless ENV["HOMEBREW_BREW_FILE"] # Path to `bin/brew` main executable in `HOMEBREW_PREFIX` HOMEBREW_BREW_FILE = Pathname.new(ENV["HOMEBREW_BREW_FILE"]) @@ -8,9 +6,7 @@ HOMEBREW_BREW_FILE = Pathname.new(ENV["HOMEBREW_BREW_FILE"]) class MissingEnvironmentVariables < RuntimeError; end def get_env_or_raise(env) - unless ENV[env] - raise MissingEnvironmentVariables, "#{env} was not exported!" - end + raise MissingEnvironmentVariables, "#{env} was not exported!" unless ENV[env] ENV[env] end diff --git a/Library/Homebrew/cxxstdlib.rb b/Library/Homebrew/cxxstdlib.rb index b89c8b8a2c..82f4c76058 100644 --- a/Library/Homebrew/cxxstdlib.rb +++ b/Library/Homebrew/cxxstdlib.rb @@ -13,9 +13,7 @@ class CxxStdlib end def self.create(type, compiler) - if type && ![:libstdcxx, :libcxx].include?(type) - raise ArgumentError, "Invalid C++ stdlib type: #{type}" - end + raise ArgumentError, "Invalid C++ stdlib type: #{type}" if type && ![:libstdcxx, :libcxx].include?(type) klass = (compiler.to_s =~ GNU_GCC_REGEXP) ? GnuStdlib : AppleStdlib klass.new(type, compiler) @@ -60,9 +58,7 @@ class CxxStdlib next if dep.build? dep_stdlib = Tab.for_formula(dep.to_formula).cxxstdlib - unless compatible_with? dep_stdlib - raise CompatibilityError.new(formula, dep, dep_stdlib) - end + raise CompatibilityError.new(formula, dep, dep_stdlib) unless compatible_with? dep_stdlib end end diff --git a/Library/Homebrew/dependencies.rb b/Library/Homebrew/dependencies.rb index 0ca5d9ea88..386890c80a 100644 --- a/Library/Homebrew/dependencies.rb +++ b/Library/Homebrew/dependencies.rb @@ -95,21 +95,15 @@ module Homebrew formula.send("recursive_#{type}") do |dependent, dep| if dep.recommended? - if ignores.include?("recommended?") || dependent.build.without?(dep) - klass.prune - end + klass.prune if ignores.include?("recommended?") || dependent.build.without?(dep) elsif dep.test? if includes.include?("test?") - if type == :dependencies - Dependency.keep_but_prune_recursive_deps - end + Dependency.keep_but_prune_recursive_deps if type == :dependencies else klass.prune end elsif dep.optional? - if !includes.include?("optional?") && !dependent.build.with?(dep) - klass.prune - end + klass.prune if !includes.include?("optional?") && !dependent.build.with?(dep) elsif dep.build? klass.prune unless includes.include?("build?") end diff --git a/Library/Homebrew/dependency_collector.rb b/Library/Homebrew/dependency_collector.rb index fc74049f10..8ad82f9ce9 100644 --- a/Library/Homebrew/dependency_collector.rb +++ b/Library/Homebrew/dependency_collector.rb @@ -134,9 +134,7 @@ class DependencyCollector end def parse_class_spec(spec, tags) - unless spec < Requirement - raise TypeError, "#{spec.inspect} is not a Requirement subclass" - end + raise TypeError, "#{spec.inspect} is not a Requirement subclass" unless spec < Requirement spec.new(tags) end diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index b742fb80da..96d23902af 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -136,9 +136,7 @@ module Homebrew created_pr_comment = false if new_formula && !new_formula_problem_lines.empty? begin - if GitHub.create_issue_comment(new_formula_problem_lines.join("\n")) - created_pr_comment = true - end + created_pr_comment = true if GitHub.create_issue_comment(new_formula_problem_lines.join("\n")) rescue *GitHub.api_errors => e opoo "Unable to create issue comment: #{e.message}" end @@ -154,9 +152,7 @@ module Homebrew formula_plural = "#{formula_count} #{"formula".pluralize(formula_count)}" corrected_problem_plural = "#{corrected_problem_count} #{"problem".pluralize(corrected_problem_count)}" errors_summary = "#{problem_plural} in #{formula_plural} detected" - if corrected_problem_count.positive? - errors_summary += ", #{corrected_problem_plural} corrected" - end + errors_summary += ", #{corrected_problem_plural} corrected" if corrected_problem_count.positive? if problem_count.positive? || (new_formula_problem_count.positive? && !created_pr_comment) @@ -263,9 +259,7 @@ module Homebrew problem "'DATA' was found, but no '__END__'" if text.data? && !text.end? - if text.end? && !text.data? - problem "'__END__' was found, but 'DATA' is not used" - end + problem "'__END__' was found, but 'DATA' is not used" if text.end? && !text.data? if text =~ /inreplace [^\n]* do [^\n]*\n[^\n]*\.gsub![^\n]*\n\ *end/m problem "'inreplace ... do' was used for a single substitution (use the non-block form instead)." @@ -344,9 +338,7 @@ module Homebrew name = formula.name - if MissingFormula.blacklisted_reason(name) - problem "'#{name}' is blacklisted." - end + problem "'#{name}' is blacklisted." if MissingFormula.blacklisted_reason(name) if Formula.aliases.include? name problem "Formula name conflicts with existing aliases." @@ -418,13 +410,9 @@ module Homebrew problem "Dependency #{dep} does not define option #{opt.name.inspect}" end - if dep.name == "git" - problem "Don't use git as a dependency (it's always available)" - end + problem "Don't use git as a dependency (it's always available)" if dep.name == "git" - if dep.tags.include?(:run) - problem "Dependency '#{dep.name}' is marked as :run. Remove :run; it is a no-op." - end + problem "Dependency '#{dep.name}' is marked as :run. Remove :run; it is a no-op." if dep.tags.include?(:run) next unless @core_tap @@ -565,9 +553,7 @@ module Homebrew return unless formula.bottle_disabled? return if formula.bottle_unneeded? - unless formula.bottle_disable_reason.valid? - problem "Unrecognized bottle modifier" - end + problem "Unrecognized bottle modifier" unless formula.bottle_disable_reason.valid? return unless @core_tap problem "Formulae should not use `bottle :disabled`" @@ -635,9 +621,7 @@ module Homebrew next unless spec = formula.send(name.downcase) version = spec.version - if version.to_s !~ /\d/ - problem "#{name}: version (#{version}) is set to a string without a digit" - end + problem "#{name}: version (#{version}) is set to a string without a digit" if version.to_s !~ /\d/ if version.to_s.start_with?("HEAD") problem "#{name}: non-HEAD version name (#{version}) should not begin with HEAD" end @@ -733,9 +717,7 @@ module Homebrew version = Version.parse(stable.url) if version >= Version.create("1.0") _, minor_version, = version.to_s.split(".", 3).map(&:to_i) - if minor_version.odd? - problem "#{stable.version} is a development release" - end + problem "#{stable.version} is a development release" if minor_version.odd? end end end @@ -875,9 +857,7 @@ module Homebrew return unless @strict - if line.include?("env :userpaths") - problem "`env :userpaths` in formulae is deprecated" - end + problem "`env :userpaths` in formulae is deprecated" if line.include?("env :userpaths") if line =~ /system ((["'])[^"' ]*(?:\s[^"' ]*)+\2)/ bad_system = Regexp.last_match(1) @@ -954,9 +934,7 @@ module Homebrew def audit only_audits = @only except_audits = @except - if only_audits && except_audits - odie "--only and --except cannot be used simultaneously!" - end + odie "--only and --except cannot be used simultaneously!" if only_audits && except_audits methods.map(&:to_s).grep(/^audit_/).each do |audit_method_name| name = audit_method_name.gsub(/^audit_/, "") @@ -1027,9 +1005,7 @@ module Homebrew end end - if version.to_s.start_with?("v") - problem "version #{version} should not have a leading 'v'" - end + problem "version #{version} should not have a leading 'v'" if version.to_s.start_with?("v") return unless version.to_s =~ /_\d+$/ @@ -1044,9 +1020,7 @@ module Homebrew url_strategy = DownloadStrategyDetector.detect(url) if using == :git || url_strategy == GitDownloadStrategy - if specs[:tag] && !specs[:revision] - problem "Git should specify :revision when a :tag is specified." - end + problem "Git should specify :revision when a :tag is specified." if specs[:tag] && !specs[:revision] end return unless using @@ -1101,16 +1075,12 @@ module Homebrew problem http_content_problem end elsif strategy <= GitDownloadStrategy - unless Utils.git_remote_exists? url - problem "The URL #{url} is not a valid git URL" - end + problem "The URL #{url} is not a valid git URL" unless Utils.git_remote_exists? url elsif strategy <= SubversionDownloadStrategy next unless DevelopmentTools.subversion_handles_most_https_certificates? next unless Utils.svn_available? - unless Utils.svn_remote_exists? url - problem "The URL #{url} is not a valid svn URL" - end + problem "The URL #{url} is not a valid svn URL" unless Utils.svn_remote_exists? url end end end diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index 356241fe83..52bb5ec6d6 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -205,14 +205,10 @@ module Homebrew end def bottle_formula(f) - unless f.installed? - return ofail "Formula not installed or up-to-date: #{f.full_name}" - end + return ofail "Formula not installed or up-to-date: #{f.full_name}" unless f.installed? unless tap = f.tap - unless args.force_core_tap? - return ofail "Formula not from core or any installed taps: #{f.full_name}" - end + return ofail "Formula not from core or any installed taps: #{f.full_name}" unless args.force_core_tap? tap = CoreTap.instance end @@ -223,9 +219,7 @@ module Homebrew return end - unless Utils::Bottles.built_as? f - return ofail "Formula not installed with '--build-bottle': #{f.full_name}" - end + return ofail "Formula not installed with '--build-bottle': #{f.full_name}" unless Utils::Bottles.built_as? f return ofail "Formula has no stable version: #{f.full_name}" unless f.stable @@ -265,9 +259,7 @@ module Homebrew begin keg.delete_pyc_files! - unless args.skip_relocation? - changed_files = keg.replace_locations_with_placeholders - end + changed_files = keg.replace_locations_with_placeholders unless args.skip_relocation? Tab.clear_cache tab = Tab.for_keg(keg) @@ -300,9 +292,7 @@ module Homebrew mv "#{relocatable_tar_path}.gz", bottle_path end - if bottle_path.size > 1 * 1024 * 1024 - ohai "Detecting if #{filename} is relocatable..." - end + ohai "Detecting if #{filename} is relocatable..." if bottle_path.size > 1 * 1024 * 1024 if Homebrew.default_prefix?(prefix) prefix_check = File.join(prefix, "opt") @@ -344,9 +334,7 @@ module Homebrew ensure ignore_interrupts do original_tab&.write - unless args.skip_relocation? - keg.replace_placeholders_with_locations changed_files - end + keg.replace_placeholders_with_locations changed_files unless args.skip_relocation? end end end @@ -510,9 +498,7 @@ module Homebrew string = s.sub!(/ bottle do.+?end\n/m, output) odie "Bottle block update failed!" unless string else - if args.keep_old? - odie "--keep-old was passed but there was no existing bottle block!" - end + odie "--keep-old was passed but there was no existing bottle block!" if args.keep_old? puts output update_or_add = "add" if s.include? "stable do" diff --git a/Library/Homebrew/dev-cmd/bump-formula-pr.rb b/Library/Homebrew/dev-cmd/bump-formula-pr.rb index 820106b3fe..205a2cd0e8 100644 --- a/Library/Homebrew/dev-cmd/bump-formula-pr.rb +++ b/Library/Homebrew/dev-cmd/bump-formula-pr.rb @@ -380,30 +380,20 @@ module Homebrew contents = path.open("r") { |f| Formulary.ensure_utf8_encoding(f).read } contents.extend(StringInreplaceExtension) replacement_pairs.each do |old, new| - unless Homebrew.args.quiet? - ohai "replace #{old.inspect} with #{new.inspect}" - end - unless old - raise "No old value for new value #{new}! Did you pass the wrong arguments?" - end + ohai "replace #{old.inspect} with #{new.inspect}" unless Homebrew.args.quiet? + raise "No old value for new value #{new}! Did you pass the wrong arguments?" unless old contents.gsub!(old, new) end - unless contents.errors.empty? - raise Utils::InreplaceError, path => contents.errors - end + raise Utils::InreplaceError, path => contents.errors unless contents.errors.empty? path.atomic_write(contents) if args.write? contents else Utils::Inreplace.inreplace(path) do |s| replacement_pairs.each do |old, new| - unless Homebrew.args.quiet? - ohai "replace #{old.inspect} with #{new.inspect}" - end - unless old - raise "No old value for new value #{new}! Did you pass the wrong arguments?" - end + ohai "replace #{old.inspect} with #{new.inspect}" unless Homebrew.args.quiet? + raise "No old value for new value #{new}! Did you pass the wrong arguments?" unless old s.gsub!(old, new) end diff --git a/Library/Homebrew/dev-cmd/extract.rb b/Library/Homebrew/dev-cmd/extract.rb index 3360ab196c..0fecd1502d 100644 --- a/Library/Homebrew/dev-cmd/extract.rb +++ b/Library/Homebrew/dev-cmd/extract.rb @@ -5,38 +5,28 @@ require "tap" def with_monkey_patch BottleSpecification.class_eval do - if method_defined?(:method_missing) - alias_method :old_method_missing, :method_missing - end + alias_method :old_method_missing, :method_missing if method_defined?(:method_missing) define_method(:method_missing) { |*| } end Module.class_eval do - if method_defined?(:method_missing) - alias_method :old_method_missing, :method_missing - end + alias_method :old_method_missing, :method_missing if method_defined?(:method_missing) define_method(:method_missing) { |*| } end Resource.class_eval do - if method_defined?(:method_missing) - alias_method :old_method_missing, :method_missing - end + alias_method :old_method_missing, :method_missing if method_defined?(:method_missing) define_method(:method_missing) { |*| } end DependencyCollector.class_eval do - if method_defined?(:parse_symbol_spec) - alias_method :old_parse_symbol_spec, :parse_symbol_spec - end + alias_method :old_parse_symbol_spec, :parse_symbol_spec if method_defined?(:parse_symbol_spec) define_method(:parse_symbol_spec) { |*| } end if defined?(DependencyCollector::Compat) DependencyCollector::Compat.class_eval do - if method_defined?(:parse_string_spec) - alias_method :old_parse_string_spec, :parse_string_spec - end + alias_method :old_parse_string_spec, :parse_string_spec if method_defined?(:parse_string_spec) define_method(:parse_string_spec) { |*| } end end diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index c08461e7d2..15b84672d6 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -34,9 +34,7 @@ module Homebrew raise UsageError unless ARGV.named.empty? - if args.link? - odie "`brew man --link` is now done automatically by `brew update`." - end + odie "`brew man --link` is now done automatically by `brew update`." if args.link? regenerate_man_pages diff --git a/Library/Homebrew/dev-cmd/mirror.rb b/Library/Homebrew/dev-cmd/mirror.rb index e7deeb8b35..1b1365315d 100644 --- a/Library/Homebrew/dev-cmd/mirror.rb +++ b/Library/Homebrew/dev-cmd/mirror.rb @@ -23,9 +23,7 @@ module Homebrew bintray_user = ENV["HOMEBREW_BINTRAY_USER"] bintray_key = ENV["HOMEBREW_BINTRAY_KEY"] - if !bintray_user || !bintray_key - raise "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" - end + raise "Missing HOMEBREW_BINTRAY_USER or HOMEBREW_BINTRAY_KEY variables!" if !bintray_user || !bintray_key ARGV.formulae.each do |f| bintray_package = Utils::Bottles::Bintray.package f.name diff --git a/Library/Homebrew/dev-cmd/pull.rb b/Library/Homebrew/dev-cmd/pull.rb index fd1cc476dc..41c67a4026 100644 --- a/Library/Homebrew/dev-cmd/pull.rb +++ b/Library/Homebrew/dev-cmd/pull.rb @@ -66,17 +66,11 @@ module Homebrew pull_args.parse - if ARGV.named.empty? - odie "This command requires at least one argument containing a URL or pull request number" - end + odie "This command requires at least one argument containing a URL or pull request number" if ARGV.named.empty? # Passthrough Git environment variables for e.g. git am - if ENV["HOMEBREW_GIT_NAME"] - ENV["GIT_COMMITTER_NAME"] = ENV["HOMEBREW_GIT_NAME"] - end - if ENV["HOMEBREW_GIT_EMAIL"] - ENV["GIT_COMMITTER_EMAIL"] = ENV["HOMEBREW_GIT_EMAIL"] - end + ENV["GIT_COMMITTER_NAME"] = ENV["HOMEBREW_GIT_NAME"] if ENV["HOMEBREW_GIT_NAME"] + ENV["GIT_COMMITTER_EMAIL"] = ENV["HOMEBREW_GIT_EMAIL"] if ENV["HOMEBREW_GIT_EMAIL"] # Depending on user configuration, git may try to invoke gpg. if Utils.popen_read("git config --get --bool commit.gpgsign").chomp == "true" @@ -123,9 +117,7 @@ module Homebrew odie "Not a GitHub pull request or commit: #{arg}" end - if !testing_job && args.bottle? && issue.nil? - odie "No pull request detected!" - end + odie "No pull request detected!" if !testing_job && args.bottle? && issue.nil? if tap tap.install unless tap.installed? @@ -157,9 +149,7 @@ module Homebrew end odie "Can not bump if non-formula files are changed" unless patch_changes[:others].empty? end - if is_bumpable - old_versions = current_versions_from_info_external(patch_changes[:formulae].first) - end + old_versions = current_versions_from_info_external(patch_changes[:formulae].first) if is_bumpable patch_puller.apply_patch changed_formulae_names = [] @@ -288,9 +278,7 @@ module Homebrew end def publish_changed_formula_bottles(tap, changed_formulae_names) - if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] - raise "Need to load formulae to publish them!" - end + raise "Need to load formulae to publish them!" if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] published = [] bintray_creds = { user: ENV["HOMEBREW_BINTRAY_USER"], key: ENV["HOMEBREW_BINTRAY_KEY"] } @@ -458,9 +446,7 @@ module Homebrew repo = Utils::Bottles::Bintray.repository(f.tap) package = Utils::Bottles::Bintray.package(f.name) info = FormulaInfoFromJson.lookup(f.full_name) - if info.nil? - raise "Failed publishing bottle: failed reading formula info for #{f.full_name}" - end + raise "Failed publishing bottle: failed reading formula info for #{f.full_name}" if info.nil? unless info.bottle_info_any opoo "No bottle defined in formula #{package}" @@ -562,9 +548,7 @@ module Homebrew def verify_bintray_published(formulae_names) return if formulae_names.empty? - if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] - raise "Need to load formulae to verify their publication!" - end + raise "Need to load formulae to verify their publication!" if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] ohai "Verifying bottles published on Bintray" formulae = formulae_names.map { |n| Formula[n] } @@ -605,9 +589,7 @@ module Homebrew raise "Failed to find published #{f} bottle at #{url} (#{res.code} #{res.message})!" end - if retry_count >= max_retries - raise "Failed to find published #{f} bottle at #{url}!" - end + raise "Failed to find published #{f} bottle at #{url}!" if retry_count >= max_retries print(wrote_dots ? "." : "Waiting on Bintray.") wrote_dots = true @@ -630,9 +612,7 @@ module Homebrew curl_download url, to: filename break rescue - if retry_count >= max_curl_retries - raise "Failed to download #{f} bottle from #{url}!" - end + raise "Failed to download #{f} bottle from #{url}!" if retry_count >= max_curl_retries puts "curl download failed; retrying in #{curl_retry_delay_seconds} sec" sleep curl_retry_delay_seconds diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index edc2d4c33d..e6f509836f 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -278,9 +278,7 @@ module Homebrew next unless d.directory? d.find do |path| - if path.symlink? && !path.resolved_path_exists? - broken_symlinks << path - end + broken_symlinks << path if path.symlink? && !path.resolved_path_exists? end end return if broken_symlinks.empty? diff --git a/Library/Homebrew/download_strategy.rb b/Library/Homebrew/download_strategy.rb index 8481378f93..a6af403b3a 100644 --- a/Library/Homebrew/download_strategy.rb +++ b/Library/Homebrew/download_strategy.rb @@ -375,9 +375,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy if filename_with_encoding = content_disposition.parameters["filename*"] encoding, encoded_filename = filename_with_encoding.split("''", 2) - if encoding && encoded_filename - filename = URI.decode_www_form_component(encoded_filename).encode(encoding) - end + filename = URI.decode_www_form_component(encoded_filename).encode(encoding) if encoding && encoded_filename end filename || content_disposition.filename diff --git a/Library/Homebrew/extend/ENV/super.rb b/Library/Homebrew/extend/ENV/super.rb index 0b5cb41eaf..403144a3c4 100644 --- a/Library/Homebrew/extend/ENV/super.rb +++ b/Library/Homebrew/extend/ENV/super.rb @@ -110,9 +110,7 @@ module Superenv path.append("/usr/bin", "/bin", "/usr/sbin", "/sbin") begin - if homebrew_cc =~ GNU_GCC_REGEXP - path.append(gcc_version_formula($&).opt_bin) - end + path.append(gcc_version_formula($&).opt_bin) if homebrew_cc =~ GNU_GCC_REGEXP rescue FormulaUnavailableError # Don't fail and don't add these formulae to the path if they don't exist. nil diff --git a/Library/Homebrew/extend/os/mac/system_config.rb b/Library/Homebrew/extend/os/mac/system_config.rb index a773128f37..ec017bdc26 100644 --- a/Library/Homebrew/extend/os/mac/system_config.rb +++ b/Library/Homebrew/extend/os/mac/system_config.rb @@ -36,21 +36,15 @@ class SystemConfig end def clt - @clt ||= if MacOS::CLT.installed? - MacOS::CLT.version - end + @clt ||= MacOS::CLT.version if MacOS::CLT.installed? end def clt_headers - @clt_headers ||= if MacOS::CLT.headers_installed? - MacOS::CLT.headers_version - end + @clt_headers ||= MacOS::CLT.headers_version if MacOS::CLT.headers_installed? end def xquartz - @xquartz ||= if MacOS::XQuartz.installed? - "#{MacOS::XQuartz.version} => #{describe_path(MacOS::XQuartz.prefix)}" - end + @xquartz ||= "#{MacOS::XQuartz.version} => #{describe_path(MacOS::XQuartz.prefix)}" if MacOS::XQuartz.installed? end def dump_verbose_config(f = $stdout) diff --git a/Library/Homebrew/extend/pathname.rb b/Library/Homebrew/extend/pathname.rb index 78b3a460a7..8398726fe9 100644 --- a/Library/Homebrew/extend/pathname.rb +++ b/Library/Homebrew/extend/pathname.rb @@ -345,9 +345,7 @@ class Pathname # Writes an exec script that invokes a Java jar def write_jar_script(target_jar, script_name, java_opts = "", java_version: nil) mkpath - java_home = if java_version - "JAVA_HOME=\"#{Language::Java.java_home_shell(java_version)}\" " - end + java_home = ("JAVA_HOME=\"#{Language::Java.java_home_shell(java_version)}\" " if java_version) join(script_name).write <<~SH #!/bin/bash #{java_home}exec java #{java_opts} -jar #{target_jar} "$@" diff --git a/Library/Homebrew/extend/string.rb b/Library/Homebrew/extend/string.rb index 0b2fa3e379..71f08c453b 100644 --- a/Library/Homebrew/extend/string.rb +++ b/Library/Homebrew/extend/string.rb @@ -28,18 +28,14 @@ module StringInreplaceExtension def sub!(before, after) result = super - unless result - errors << "expected replacement of #{before.inspect} with #{after.inspect}" - end + errors << "expected replacement of #{before.inspect} with #{after.inspect}" unless result result end # Warn if nothing was replaced def gsub!(before, after, audit_result = true) result = super(before, after) - if audit_result && result.nil? - errors << "expected replacement of #{before.inspect} with #{after.inspect}" - end + errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil? result end @@ -55,9 +51,7 @@ module StringInreplaceExtension def remove_make_var!(flags) Array(flags).each do |flag| # Also remove trailing \n, if present. - unless gsub!(/^#{Regexp.escape(flag)}[ \t]*=.*$\n?/, "", false) - errors << "expected to remove #{flag.inspect}" - end + errors << "expected to remove #{flag.inspect}" unless gsub!(/^#{Regexp.escape(flag)}[ \t]*=.*$\n?/, "", false) end end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 5bc9aaae9f..ea2387e6ee 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -176,9 +176,7 @@ class Formula @name = name @path = path @alias_path = alias_path - @alias_name = if alias_path - File.basename(alias_path) - end + @alias_name = (File.basename(alias_path) if alias_path) @revision = self.class.revision || 0 @version_scheme = self.class.version_scheme || 0 @@ -248,14 +246,10 @@ class Formula end def validate_attributes! - if name.nil? || name.empty? || name =~ /\s/ - raise FormulaValidationError.new(full_name, :name, name) - end + raise FormulaValidationError.new(full_name, :name, name) if name.nil? || name.empty? || name =~ /\s/ url = active_spec.url - if url.nil? || url.empty? || url =~ /\s/ - raise FormulaValidationError.new(full_name, :url, url) - end + raise FormulaValidationError.new(full_name, :url, url) if url.nil? || url.empty? || url =~ /\s/ val = version.respond_to?(:to_str) ? version.to_str : version return unless val.nil? || val.empty? || val =~ /\s/ @@ -1338,9 +1332,7 @@ class Formula # Avoid false positives for clock_gettime support on 10.11. # CMake cache entries for other weak symbols may be added here as needed. - if MacOS.version == "10.11" && MacOS::Xcode.version >= "8.0" - args << "-DHAVE_CLOCK_GETTIME:INTERNAL=0" - end + args << "-DHAVE_CLOCK_GETTIME:INTERNAL=0" if MacOS.version == "10.11" && MacOS::Xcode.version >= "8.0" args end @@ -1842,9 +1834,7 @@ class Formula pretty_args.delete "--disable-debug" end pretty_args.each_index do |i| - if pretty_args[i].to_s.start_with? "import setuptools" - pretty_args[i] = "import setuptools..." - end + pretty_args[i] = "import setuptools..." if pretty_args[i].to_s.start_with? "import setuptools" end ohai "#{cmd} #{pretty_args * " "}".strip @@ -1957,9 +1947,7 @@ class Formula # If the cellar only has one version installed, don't complain # that we can't tell which one to keep. Don't complain at all if the # only installed version is a pinned formula. - unless quiet - opoo "Skipping #{full_name}: most recent version #{pkg_version} not installed" - end + opoo "Skipping #{full_name}: most recent version #{pkg_version} not installed" unless quiet end eligible_for_cleanup end diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 45f2f08499..bce23f8bff 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -244,9 +244,7 @@ class FormulaInstaller check_conflicts - if !pour_bottle? && !formula.bottle_unneeded? && !DevelopmentTools.installed? - raise BuildToolsError, [formula] - end + raise BuildToolsError, [formula] if !pour_bottle? && !formula.bottle_unneeded? && !DevelopmentTools.installed? unless ignore_deps? deps = compute_dependencies @@ -267,17 +265,13 @@ class FormulaInstaller end options = display_options(formula) - if show_header? - oh1 "Installing #{Formatter.identifier(formula.full_name)} #{options}".strip - end + oh1 "Installing #{Formatter.identifier(formula.full_name)} #{options}".strip if show_header? unless formula.tap&.private? action = "#{formula.full_name} #{options}".strip Utils::Analytics.report_event("install", action) - if installed_on_request - Utils::Analytics.report_event("install_on_request", action) - end + Utils::Analytics.report_event("install_on_request", action) if installed_on_request end self.class.attempted << formula @@ -624,9 +618,7 @@ class FormulaInstaller keg = Keg.new(formula.prefix) link(keg) - unless @poured_bottle && formula.bottle_specification.skip_relocation? - fix_dynamic_linkage(keg) - end + fix_dynamic_linkage(keg) unless @poured_bottle && formula.bottle_specification.skip_relocation? if build_bottle? ohai "Not running post_install as we're building a bottle" @@ -757,9 +749,7 @@ class FormulaInstaller formula.update_head_version - if !formula.prefix.directory? || Keg.new(formula.prefix).empty_installation? - raise "Empty installation" - end + raise "Empty installation" if !formula.prefix.directory? || Keg.new(formula.prefix).empty_installation? rescue Exception => e # rubocop:disable Lint/RescueException if e.is_a? BuildError e.formula = formula diff --git a/Library/Homebrew/formulary.rb b/Library/Homebrew/formulary.rb index 44f40685fa..8b40c7376f 100644 --- a/Library/Homebrew/formulary.rb +++ b/Library/Homebrew/formulary.rb @@ -16,9 +16,7 @@ module Formulary end def self.load_formula(name, path, contents, namespace) - if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] - raise "Formula loading disabled by HOMEBREW_DISABLE_LOAD_FORMULA!" - end + raise "Formula loading disabled by HOMEBREW_DISABLE_LOAD_FORMULA!" if ENV["HOMEBREW_DISABLE_LOAD_FORMULA"] mod = Module.new const_set(namespace, mod) @@ -244,9 +242,7 @@ module Formulary new_name = new_tap.core_tap? ? name : new_tapped_name end - if warn && old_name && new_name - opoo "Use #{new_name} instead of deprecated #{old_name}" - end + opoo "Use #{new_name} instead of deprecated #{old_name}" if warn && old_name && new_name end [name, path] @@ -397,22 +393,16 @@ module Formulary return TapLoader.new(ref, from: from) end - if File.extname(ref) == ".rb" && Pathname.new(ref).expand_path.exist? - return FromPathLoader.new(ref) - end + return FromPathLoader.new(ref) if File.extname(ref) == ".rb" && Pathname.new(ref).expand_path.exist? formula_with_that_name = core_path(ref) - if formula_with_that_name.file? - return FormulaLoader.new(ref, formula_with_that_name) - end + return FormulaLoader.new(ref, formula_with_that_name) if formula_with_that_name.file? possible_alias = CoreTap.instance.alias_dir/ref return AliasLoader.new(possible_alias) if possible_alias.file? possible_tap_formulae = tap_paths(ref) - if possible_tap_formulae.size > 1 - raise TapFormulaAmbiguityError.new(ref, possible_tap_formulae) - end + raise TapFormulaAmbiguityError.new(ref, possible_tap_formulae) if possible_tap_formulae.size > 1 if possible_tap_formulae.size == 1 path = possible_tap_formulae.first.resolved_path @@ -422,9 +412,7 @@ module Formulary if newref = CoreTap.instance.formula_renames[ref] formula_with_that_oldname = core_path(newref) - if formula_with_that_oldname.file? - return FormulaLoader.new(newref, formula_with_that_oldname) - end + return FormulaLoader.new(newref, formula_with_that_oldname) if formula_with_that_oldname.file? end possible_tap_newname_formulae = [] @@ -438,19 +426,13 @@ module Formulary raise TapFormulaWithOldnameAmbiguityError.new(ref, possible_tap_newname_formulae) end - unless possible_tap_newname_formulae.empty? - return TapLoader.new(possible_tap_newname_formulae.first, from: from) - end + return TapLoader.new(possible_tap_newname_formulae.first, from: from) unless possible_tap_newname_formulae.empty? possible_keg_formula = Pathname.new("#{HOMEBREW_PREFIX}/opt/#{ref}/.brew/#{ref}.rb") - if possible_keg_formula.file? - return FormulaLoader.new(ref, possible_keg_formula) - end + return FormulaLoader.new(ref, possible_keg_formula) if possible_keg_formula.file? possible_cached_formula = Pathname.new("#{HOMEBREW_CACHE_FORMULA}/#{ref}.rb") - if possible_cached_formula.file? - return FormulaLoader.new(ref, possible_cached_formula) - end + return FormulaLoader.new(ref, possible_cached_formula) if possible_cached_formula.file? NullLoader.new(ref) end @@ -473,9 +455,7 @@ module Formulary def self.find_with_priority(ref, spec = :stable) possible_pinned_tap_formulae = tap_paths(ref, Dir["#{HOMEBREW_LIBRARY}/PinnedTaps/*/*/"]).map(&:realpath) - if possible_pinned_tap_formulae.size > 1 - raise TapFormulaAmbiguityError.new(ref, possible_pinned_tap_formulae) - end + raise TapFormulaAmbiguityError.new(ref, possible_pinned_tap_formulae) if possible_pinned_tap_formulae.size > 1 if possible_pinned_tap_formulae.size == 1 selected_formula = factory(possible_pinned_tap_formulae.first, spec) diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index 7657f74c36..9232ce808c 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -148,6 +148,4 @@ require "official_taps" require "tap" require "tap_constants" -if !ARGV.include?("--no-compat") && !ENV["HOMEBREW_NO_COMPAT"] - require "compat" -end +require "compat" if !ARGV.include?("--no-compat") && !ENV["HOMEBREW_NO_COMPAT"] diff --git a/Library/Homebrew/keg.rb b/Library/Homebrew/keg.rb index aa62e8594f..4c12e22bfa 100644 --- a/Library/Homebrew/keg.rb +++ b/Library/Homebrew/keg.rb @@ -263,9 +263,7 @@ class Keg if tap bad_tap_opt = opt/tap.user - if !bad_tap_opt.symlink? && bad_tap_opt.directory? - FileUtils.rm_rf bad_tap_opt - end + FileUtils.rm_rf bad_tap_opt if !bad_tap_opt.symlink? && bad_tap_opt.directory? end aliases.each do |a| @@ -569,9 +567,7 @@ class Keg begin keg = Keg.for(src) rescue NotAKegError - if ARGV.verbose? - puts "Won't resolve conflicts for symlink #{dst} as it doesn't resolve into the Cellar" - end + puts "Won't resolve conflicts for symlink #{dst} as it doesn't resolve into the Cellar" if ARGV.verbose? return end @@ -636,9 +632,7 @@ class Keg # Don't link pyc or pyo files because Python overwrites these # cached object files and next time brew wants to link, the # file is in the way. - if %w[.pyc .pyo].include?(src.extname) && src.to_s.include?("/site-packages/") - Find.prune - end + Find.prune if %w[.pyc .pyo].include?(src.extname) && src.to_s.include?("/site-packages/") case yield src.relative_path_from(root) when :skip_file, nil diff --git a/Library/Homebrew/language/node.rb b/Library/Homebrew/language/node.rb index e7958e7d95..28d9ee4b83 100644 --- a/Library/Homebrew/language/node.rb +++ b/Library/Homebrew/language/node.rb @@ -11,9 +11,7 @@ module Language # directory, consequently breaking that assumption. We require a tarball # because npm install creates a "real" installation when fed a tarball. output = Utils.popen_read("npm pack --ignore-scripts") - if !$CHILD_STATUS.exitstatus.zero? || output.lines.empty? - raise "npm failed to pack #{Dir.pwd}" - end + raise "npm failed to pack #{Dir.pwd}" if !$CHILD_STATUS.exitstatus.zero? || output.lines.empty? output.lines.last.chomp end diff --git a/Library/Homebrew/load_path.rb b/Library/Homebrew/load_path.rb index 678263d322..c1629127ea 100644 --- a/Library/Homebrew/load_path.rb +++ b/Library/Homebrew/load_path.rb @@ -2,8 +2,6 @@ require "pathname" HOMEBREW_LIBRARY_PATH = Pathname(__dir__).realpath -unless $LOAD_PATH.include?(HOMEBREW_LIBRARY_PATH.to_s) - $LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.to_s) -end +$LOAD_PATH.push(HOMEBREW_LIBRARY_PATH.to_s) unless $LOAD_PATH.include?(HOMEBREW_LIBRARY_PATH.to_s) require "vendor/bundle-standalone/bundler/setup" diff --git a/Library/Homebrew/locale.rb b/Library/Homebrew/locale.rb index 79f863c047..4c05be5be8 100644 --- a/Library/Homebrew/locale.rb +++ b/Library/Homebrew/locale.rb @@ -11,9 +11,7 @@ class Locale def self.parse(string) string = string.to_s - if string !~ LOCALE_REGEX - raise ParserError, "'#{string}' cannot be parsed to a #{self}" - end + raise ParserError, "'#{string}' cannot be parsed to a #{self}" if string !~ LOCALE_REGEX scan = proc do |regex| string.scan(/(?:\-|^)(#{regex})(?:\-|$)/).flatten.first @@ -29,9 +27,7 @@ class Locale attr_reader :language, :region, :script def initialize(language, region, script) - if language.nil? && region.nil? && script.nil? - raise ArgumentError, "#{self.class} cannot be empty" - end + raise ArgumentError, "#{self.class} cannot be empty" if language.nil? && region.nil? && script.nil? { language: language, diff --git a/Library/Homebrew/migrator.rb b/Library/Homebrew/migrator.rb index b98d908d2b..b863e82371 100644 --- a/Library/Homebrew/migrator.rb +++ b/Library/Homebrew/migrator.rb @@ -118,9 +118,7 @@ class Migrator @old_tabs = old_cellar.subdirs.map { |d| Tab.for_keg(Keg.new(d)) } @old_tap = old_tabs.first.tap - if !force && !from_same_tap_user? - raise MigratorDifferentTapsError.new(formula, old_tap) - end + raise MigratorDifferentTapsError.new(formula, old_tap) if !force && !from_same_tap_user? @new_cellar = HOMEBREW_CELLAR/formula.name @new_cellar_existed = @new_cellar.exist? @@ -233,9 +231,7 @@ class Migrator end end - if conflicted - odie "Remove #{new_cellar} manually and run brew migrate #{oldname}." - end + odie "Remove #{new_cellar} manually and run brew migrate #{oldname}." if conflicted end oh1 "Moving #{Formatter.identifier(oldname)} versions to #{new_cellar}" diff --git a/Library/Homebrew/os/mac/xquartz.rb b/Library/Homebrew/os/mac/xquartz.rb index 393512b439..dc03fcb11f 100644 --- a/Library/Homebrew/os/mac/xquartz.rb +++ b/Library/Homebrew/os/mac/xquartz.rb @@ -87,9 +87,7 @@ module OS # remain public. New code should use `MacOS::X11.bin`, `MacOS::X11.lib` and # `MacOS::X11.include` instead, as that accounts for Xcode-only systems. def prefix - @prefix ||= if Pathname.new("/opt/X11/lib/libpng.dylib").exist? - Pathname.new("/opt/X11") - end + @prefix ||= Pathname.new("/opt/X11") if Pathname.new("/opt/X11/lib/libpng.dylib").exist? end def installed? diff --git a/Library/Homebrew/requirements/codesign_requirement.rb b/Library/Homebrew/requirements/codesign_requirement.rb index ed6c6988e8..aaf4f650fa 100644 --- a/Library/Homebrew/requirements/codesign_requirement.rb +++ b/Library/Homebrew/requirements/codesign_requirement.rb @@ -3,12 +3,8 @@ class CodesignRequirement < Requirement def initialize(tags) options = tags.shift - unless options.is_a?(Hash) - raise ArgumentError("CodesignRequirement requires an options Hash!") - end - unless options.key?(:identity) - raise ArgumentError("CodesignRequirement requires an identity key!") - end + raise ArgumentError("CodesignRequirement requires an options Hash!") unless options.is_a?(Hash) + raise ArgumentError("CodesignRequirement requires an identity key!") unless options.key?(:identity) @identity = options.fetch(:identity) @with = options.fetch(:with, "code signing") diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index 9cd6bd5d57..c71ee2bcf2 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -66,9 +66,7 @@ class Resource # directory. Subclasses that override stage should implement the tmp # dir using {Mktemp} so that works with all subtypes. def stage(target = nil, &block) - unless target || block - raise ArgumentError, "target directory or block is required" - end + raise ArgumentError, "target directory or block is required" unless target || block verify_download_integrity(fetch) prepare_patches diff --git a/Library/Homebrew/rubocops/checksum.rb b/Library/Homebrew/rubocops/checksum.rb index d00bd6740d..3d48cad941 100644 --- a/Library/Homebrew/rubocops/checksum.rb +++ b/Library/Homebrew/rubocops/checksum.rb @@ -7,13 +7,9 @@ module RuboCop def audit_formula(_node, _class_node, _parent_class_node, body_node) return if body_node.nil? - if method_called_ever?(body_node, :md5) - problem "MD5 checksums are deprecated, please use SHA256" - end + problem "MD5 checksums are deprecated, please use SHA256" if method_called_ever?(body_node, :md5) - if method_called_ever?(body_node, :sha1) - problem "SHA1 checksums are deprecated, please use SHA256" - end + problem "SHA1 checksums are deprecated, please use SHA256" if method_called_ever?(body_node, :sha1) sha256_calls = find_every_method_call_by_name(body_node, :sha256) sha256_calls.each do |sha256_call| diff --git a/Library/Homebrew/rubocops/extend/formula.rb b/Library/Homebrew/rubocops/extend/formula.rb index 59b71d0156..00d26ccf8f 100644 --- a/Library/Homebrew/rubocops/extend/formula.rb +++ b/Library/Homebrew/rubocops/extend/formula.rb @@ -367,9 +367,7 @@ module RuboCop def check_precedence(first_nodes, next_nodes) next_nodes.each do |each_next_node| first_nodes.each do |each_first_node| - if component_precedes?(each_first_node, each_next_node) - return [each_first_node, each_next_node] - end + return [each_first_node, each_next_node] if component_precedes?(each_first_node, each_next_node) end end nil diff --git a/Library/Homebrew/rubocops/formula_desc.rb b/Library/Homebrew/rubocops/formula_desc.rb index 94fde418fa..9ff6c75049 100644 --- a/Library/Homebrew/rubocops/formula_desc.rb +++ b/Library/Homebrew/rubocops/formula_desc.rb @@ -65,14 +65,10 @@ module RuboCop desc = parameters(desc_call).first # Check for leading whitespace. - if regex_match_group(desc, /^\s+/) - problem "Description shouldn't have a leading space" - end + problem "Description shouldn't have a leading space" if regex_match_group(desc, /^\s+/) # Check for trailing whitespace. - if regex_match_group(desc, /\s+$/) - problem "Description shouldn't have a trailing space" - end + problem "Description shouldn't have a trailing space" if regex_match_group(desc, /\s+$/) # Check if command-line is wrongly used in formula's desc if match = regex_match_group(desc, /(command ?line)/i) diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index 55cd1f5c59..718f5f8061 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -89,9 +89,7 @@ module RuboCop class OptionDeclarations < FormulaCop def audit_formula(_node, _class_node, _parent_class_node, body_node) - if find_method_def(body_node, :options) - problem "Use new-style option definitions" - end + problem "Use new-style option definitions" if find_method_def(body_node, :options) find_instance_method_call(body_node, :build, :without?) do |method| next unless unless_modifier?(method.parent) @@ -327,9 +325,7 @@ module RuboCop problem "Use Language::Node for npm install args" unless languageNodeModule?(method_node) end - if find_method_def(body_node, :test) - problem "Use new-style test definitions (test do)" - end + problem "Use new-style test definitions (test do)" if find_method_def(body_node, :test) find_method_with_args(body_node, :skip_clean, :all) do problem "`skip_clean :all` is deprecated; brew no longer strips symbols. " \ diff --git a/Library/Homebrew/rubocops/urls.rb b/Library/Homebrew/rubocops/urls.rb index c4ac19b220..83fb8798f0 100644 --- a/Library/Homebrew/rubocops/urls.rb +++ b/Library/Homebrew/rubocops/urls.rb @@ -97,9 +97,7 @@ module RuboCop problem "Don't use #{Regexp.last_match(1)}use_mirror in SourceForge urls (url is #{url})." end - if url.end_with?("/download") - problem "Don't use /download in SourceForge urls (url is #{url})." - end + problem "Don't use /download in SourceForge urls (url is #{url})." if url.end_with?("/download") if url =~ %r{^https?://sourceforge\.} problem "Use https://downloads.sourceforge.net to get geolocation (url is #{url})." diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 329d2b8fc6..d49b87d22c 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -55,9 +55,7 @@ class SoftwareSpec resources.each_value do |r| r.owner = self r.version ||= begin - if version.nil? - raise "#{full_name}: version missing for \"#{r.name}\" resource!" - end + raise "#{full_name}: version missing for \"#{r.name}\" resource!" if version.nil? if version.head? Version.create("HEAD") diff --git a/Library/Homebrew/style.rb b/Library/Homebrew/style.rb index c4886c6211..f2ce76b0ee 100644 --- a/Library/Homebrew/style.rb +++ b/Library/Homebrew/style.rb @@ -30,9 +30,7 @@ module Homebrew args << "--parallel" end - if ARGV.verbose? - args += ["--extra-details", "--display-cop-names"] - end + args += ["--extra-details", "--display-cop-names"] if ARGV.verbose? if options[:except_cops] options[:except_cops].map! { |cop| RuboCop::Cop::Cop.registry.qualified_cop_name(cop.to_s, "") } @@ -49,9 +47,7 @@ module Homebrew RuboCop::Cop::Cop.registry.departments.include?(cop.to_sym) end - if cops_to_include.empty? - odie "RuboCops #{options[:only_cops].join(",")} were not found" - end + odie "RuboCops #{options[:only_cops].join(",")} were not found" if cops_to_include.empty? args << "--only" << cops_to_include.join(",") end diff --git a/Library/Homebrew/system_config.rb b/Library/Homebrew/system_config.rb index dba2e8fb55..06641d0e14 100644 --- a/Library/Homebrew/system_config.rb +++ b/Library/Homebrew/system_config.rb @@ -157,15 +157,9 @@ class SystemConfig if defaults_hash[:HOMEBREW_REPOSITORY] != HOMEBREW_REPOSITORY.to_s f.puts "HOMEBREW_REPOSITORY: #{HOMEBREW_REPOSITORY}" end - if defaults_hash[:HOMEBREW_CELLAR] != HOMEBREW_CELLAR.to_s - f.puts "HOMEBREW_CELLAR: #{HOMEBREW_CELLAR}" - end - if defaults_hash[:HOMEBREW_CACHE] != HOMEBREW_CACHE.to_s - f.puts "HOMEBREW_CACHE: #{HOMEBREW_CACHE}" - end - if defaults_hash[:HOMEBREW_TEMP] != HOMEBREW_TEMP.to_s - f.puts "HOMEBREW_TEMP: #{HOMEBREW_TEMP}" - end + f.puts "HOMEBREW_CELLAR: #{HOMEBREW_CELLAR}" if defaults_hash[:HOMEBREW_CELLAR] != HOMEBREW_CELLAR.to_s + f.puts "HOMEBREW_CACHE: #{HOMEBREW_CACHE}" if defaults_hash[:HOMEBREW_CACHE] != HOMEBREW_CACHE.to_s + f.puts "HOMEBREW_TEMP: #{HOMEBREW_TEMP}" if defaults_hash[:HOMEBREW_TEMP] != HOMEBREW_TEMP.to_s if defaults_hash[:HOMEBREW_RUBY_WARNINGS] != ENV["HOMEBREW_RUBY_WARNINGS"].to_s f.puts "HOMEBREW_RUBY_WARNINGS: #{ENV["HOMEBREW_RUBY_WARNINGS"]}" end diff --git a/Library/Homebrew/tab.rb b/Library/Homebrew/tab.rb index 72bccb077d..7a58ed6e2c 100644 --- a/Library/Homebrew/tab.rb +++ b/Library/Homebrew/tab.rb @@ -133,13 +133,9 @@ class Tab < OpenStruct def self.for_formula(f) paths = [] - if f.opt_prefix.symlink? && f.opt_prefix.directory? - paths << f.opt_prefix.resolved_path - end + paths << f.opt_prefix.resolved_path if f.opt_prefix.symlink? && f.opt_prefix.directory? - if f.linked_keg.symlink? && f.linked_keg.directory? - paths << f.linked_keg.resolved_path - end + paths << f.linked_keg.resolved_path if f.linked_keg.symlink? && f.linked_keg.directory? if (dirs = f.installed_prefixes).length == 1 paths << dirs.first diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index de323aa858..3e039897cf 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -22,17 +22,13 @@ class Tap repo = args.second end - if [user, repo].any? { |part| part.nil? || part.include?("/") } - raise "Invalid tap name '#{args.join("/")}'" - end + raise "Invalid tap name '#{args.join("/")}'" if [user, repo].any? { |part| part.nil? || part.include?("/") } # We special case homebrew and linuxbrew so that users don't have to shift in a terminal. user = user.capitalize if ["homebrew", "linuxbrew"].include? user repo = repo.delete_prefix "homebrew-" - if ["Homebrew", "Linuxbrew"].include?(user) && ["core", "homebrew"].include?(repo) - return CoreTap.instance - end + return CoreTap.instance if ["Homebrew", "Linuxbrew"].include?(user) && ["core", "homebrew"].include?(repo) cache_key = "#{user}/#{repo}".downcase cache.fetch(cache_key) { |key| cache[key] = Tap.new(user, repo) } @@ -280,9 +276,7 @@ class Tap begin safe_system "git", *args unless Readall.valid_tap?(self, aliases: true) - unless ARGV.homebrew_developer? - raise "Cannot tap #{name}: invalid syntax in tap!" - end + raise "Cannot tap #{name}: invalid syntax in tap!" unless ARGV.homebrew_developer? end rescue Interrupt, RuntimeError ignore_interrupts do diff --git a/Library/Homebrew/test/spec_helper.rb b/Library/Homebrew/test/spec_helper.rb index 67e6f6cb87..a9df288115 100644 --- a/Library/Homebrew/test/spec_helper.rb +++ b/Library/Homebrew/test/spec_helper.rb @@ -5,9 +5,7 @@ if ENV["HOMEBREW_TESTS_COVERAGE"] if ENV["HOMEBREW_COVERALLS_REPO_TOKEN"] require "coveralls" - if !ENV["HOMEBREW_COLOR"] && (ENV["HOMEBREW_NO_COLOR"] || !$stdout.tty?) - Coveralls::Output.no_color - end + Coveralls::Output.no_color if !ENV["HOMEBREW_COLOR"] && (ENV["HOMEBREW_NO_COLOR"] || !$stdout.tty?) formatters << Coveralls::SimpleCov::Formatter @@ -128,9 +126,7 @@ RSpec.configure do |config| config.before(:each, :needs_svn) do homebrew_bin = File.dirname HOMEBREW_BREW_FILE - unless %W[/usr/bin/svn #{homebrew_bin}/svn].map { |x| File.executable?(x) }.any? - skip "subversion not installed." - end + skip "subversion not installed." unless %W[/usr/bin/svn #{homebrew_bin}/svn].map { |x| File.executable?(x) }.any? end config.before(:each, :needs_unzip) do diff --git a/Library/Homebrew/test/support/lib/config.rb b/Library/Homebrew/test/support/lib/config.rb index 6d6de3368e..28387c2694 100644 --- a/Library/Homebrew/test/support/lib/config.rb +++ b/Library/Homebrew/test/support/lib/config.rb @@ -1,6 +1,4 @@ -unless ENV["HOMEBREW_BREW_FILE"] - raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" -end +raise "HOMEBREW_BREW_FILE was not exported! Please call bin/brew directly!" unless ENV["HOMEBREW_BREW_FILE"] require "pathname" diff --git a/Library/Homebrew/unpack_strategy/tar.rb b/Library/Homebrew/unpack_strategy/tar.rb index 390acfba77..1b229a2902 100644 --- a/Library/Homebrew/unpack_strategy/tar.rb +++ b/Library/Homebrew/unpack_strategy/tar.rb @@ -17,9 +17,7 @@ module UnpackStrategy def self.can_extract?(path) return true if path.magic_number.match?(/\A.{257}ustar/n) - unless [Bzip2, Gzip, Lzip, Xz].any? { |s| s.can_extract?(path) } - return false - end + return false unless [Bzip2, Gzip, Lzip, Xz].any? { |s| s.can_extract?(path) } # Check if `tar` can list the contents, then it can also extract it. IO.popen(["tar", "tf", path], err: File::NULL) do |stdout| diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index d6ea652c8a..aef2f9d9aa 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -37,9 +37,7 @@ def odebug(title, *sput) end def oh1(title, options = {}) - if $stdout.tty? && !ARGV.verbose? && options.fetch(:truncate, :auto) == :auto - title = Tty.truncate(title) - end + title = Tty.truncate(title) if $stdout.tty? && !ARGV.verbose? && options.fetch(:truncate, :auto) == :auto puts Formatter.headline(title, color: :green) end @@ -491,9 +489,7 @@ end # shortfall or overrun may vary. def truncate_text_to_approximate_size(s, max_bytes, options = {}) front_weight = options.fetch(:front_weight, 0.5) - if front_weight < 0.0 || front_weight > 1.0 - raise "opts[:front_weight] must be between 0.0 and 1.0" - end + raise "opts[:front_weight] must be between 0.0 and 1.0" if front_weight < 0.0 || front_weight > 1.0 return s if s.bytesize <= max_bytes glue = "\n[...snip...]\n" diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index c733e5762a..e9db33db0d 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -185,9 +185,7 @@ module GitHub data_tmpfile.close args += ["--data", "@#{data_tmpfile.path}"] - if request_method - args += ["--request", request_method.to_s] - end + args += ["--request", request_method.to_s] if request_method end args += ["--dump-header", headers_tmpfile.path] @@ -206,9 +204,7 @@ module GitHub end begin - if !http_code.start_with?("2") || !status.success? - raise_api_error(output, errors, http_code, headers, scopes) - end + raise_api_error(output, errors, http_code, headers, scopes) if !http_code.start_with?("2") || !status.success? return if http_code == "204" # No Content diff --git a/Library/Homebrew/utils/tty.rb b/Library/Homebrew/utils/tty.rb index 6f3836280c..6d35584661 100644 --- a/Library/Homebrew/utils/tty.rb +++ b/Library/Homebrew/utils/tty.rb @@ -62,9 +62,7 @@ module Tty end def to_s - if !ENV["HOMEBREW_COLOR"] && (ENV["HOMEBREW_NO_COLOR"] || !$stdout.tty?) - return "" - end + return "" if !ENV["HOMEBREW_COLOR"] && (ENV["HOMEBREW_NO_COLOR"] || !$stdout.tty?) current_escape_sequence ensure diff --git a/Library/Homebrew/version.rb b/Library/Homebrew/version.rb index c3ed4fb544..c1eeaa1102 100644 --- a/Library/Homebrew/version.rb +++ b/Library/Homebrew/version.rb @@ -206,9 +206,7 @@ class Version end def self.create(val) - unless val.respond_to?(:to_str) - raise TypeError, "Version value must be a string; got a #{val.class} (#{val})" - end + raise TypeError, "Version value must be a string; got a #{val.class} (#{val})" unless val.respond_to?(:to_str) if val.to_str.start_with?("HEAD") HeadVersion.new(val) @@ -365,9 +363,7 @@ class Version private_class_method :_parse def initialize(val) - unless val.respond_to?(:to_str) - raise TypeError, "Version value must be a string; got a #{val.class} (#{val})" - end + raise TypeError, "Version value must be a string; got a #{val.class} (#{val})" unless val.respond_to?(:to_str) @version = val.to_str end