From 0184e271d844c04ccf023b86f157464a86a2a190 Mon Sep 17 00:00:00 2001 From: Markus Reiter Date: Mon, 16 Nov 2020 22:18:56 +0100 Subject: [PATCH] Fix RuboCop offenses. --- Library/.rubocop.yml | 4 +++ Library/Homebrew/cask/cask.rb | 2 +- Library/Homebrew/cask/cmd.rb | 2 +- Library/Homebrew/cask/cmd/abstract_command.rb | 2 +- Library/Homebrew/cask/cmd/install.rb | 2 +- Library/Homebrew/cask/dsl.rb | 4 +-- Library/Homebrew/cli/parser.rb | 2 +- Library/Homebrew/compilers.rb | 2 +- Library/Homebrew/dependency.rb | 4 +-- Library/Homebrew/extend/os/linux/formula.rb | 8 +++--- Library/Homebrew/extend/os/mac/formula.rb | 8 +++--- Library/Homebrew/formula.rb | 26 +++++++++---------- Library/Homebrew/language/python.rb | 4 +-- Library/Homebrew/linkage_checker.rb | 2 +- Library/Homebrew/requirement.rb | 10 +++---- Library/Homebrew/resource.rb | 2 +- Library/Homebrew/software_spec.rb | 2 +- Library/Homebrew/tap.rb | 2 +- Library/Homebrew/test/cmd/--cache_spec.rb | 6 ++--- Library/Homebrew/test/cmd/--cellar_spec.rb | 2 +- Library/Homebrew/test/cmd/--prefix_spec.rb | 2 +- Library/Homebrew/test/cmd/--version_spec.rb | 2 +- Library/Homebrew/test/cmd/cleanup_spec.rb | 2 +- Library/Homebrew/test/cmd/config_spec.rb | 2 +- Library/Homebrew/test/cmd/install_spec.rb | 8 +++--- Library/Homebrew/test/dev-cmd/command_spec.rb | 2 +- .../Homebrew/test/diagnostic_checks_spec.rb | 2 +- 27 files changed, 60 insertions(+), 56 deletions(-) diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index f4c1604ff7..2792594c60 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -163,6 +163,10 @@ Performance/CaseWhenSplat: Performance/Caller: Enabled: false +# Makes code less readable for minor performance increases. +Performance/MethodObjectAsBlock: + Enabled: false + # Don't allow cops to be disabled in casks and formulae. Style/DisableCopsWithinSourceCodeDirective: Enabled: true diff --git a/Library/Homebrew/cask/cask.rb b/Library/Homebrew/cask/cask.rb index 92f28cb702..da73e98755 100644 --- a/Library/Homebrew/cask/cask.rb +++ b/Library/Homebrew/cask/cask.rb @@ -22,7 +22,7 @@ module Cask attr_reader :token, :sourcefile_path, :config, :default_config def self.each(&block) - return to_enum unless block_given? + return to_enum unless block Tap.flat_map(&:cask_files).each do |f| block.call CaskLoader::FromTapPathLoader.new(f).load(config: nil) diff --git a/Library/Homebrew/cask/cmd.rb b/Library/Homebrew/cask/cmd.rb index cee4589519..16c5d30a6f 100644 --- a/Library/Homebrew/cask/cmd.rb +++ b/Library/Homebrew/cask/cmd.rb @@ -84,7 +84,7 @@ module Cask def self.parser(&block) Homebrew::CLI::Parser.new do - if block_given? + if block instance_eval(&block) else usage_banner <<~EOS diff --git a/Library/Homebrew/cask/cmd/abstract_command.rb b/Library/Homebrew/cask/cmd/abstract_command.rb index fe57b597c8..afa69cc2fa 100644 --- a/Library/Homebrew/cask/cmd/abstract_command.rb +++ b/Library/Homebrew/cask/cmd/abstract_command.rb @@ -68,7 +68,7 @@ module Cask Cmd.parser do usage_banner banner - instance_eval(&block) if block_given? + instance_eval(&block) if block OPTIONS.each do |option| send(*option) diff --git a/Library/Homebrew/cask/cmd/install.rb b/Library/Homebrew/cask/cmd/install.rb index 6dceac2767..c2dc60105f 100644 --- a/Library/Homebrew/cask/cmd/install.rb +++ b/Library/Homebrew/cask/cmd/install.rb @@ -34,7 +34,7 @@ module Cask send(*option) end - instance_eval(&block) if block_given? + instance_eval(&block) if block end end diff --git a/Library/Homebrew/cask/dsl.rb b/Library/Homebrew/cask/dsl.rb index f0abafa93a..149fedb7de 100644 --- a/Library/Homebrew/cask/dsl.rb +++ b/Library/Homebrew/cask/dsl.rb @@ -125,7 +125,7 @@ module Cask def language(*args, default: false, &block) if args.empty? language_eval - elsif block_given? + elsif block @language_blocks ||= {} @language_blocks[args] = block @@ -248,7 +248,7 @@ module Cask def caveats(*strings, &block) @caveats ||= DSL::Caveats.new(cask) - if block_given? + if block @caveats.eval_caveats(&block) elsif strings.any? strings.each do |string| diff --git a/Library/Homebrew/cli/parser.rb b/Library/Homebrew/cli/parser.rb index 6ff29d5a37..d9ebb5e01d 100644 --- a/Library/Homebrew/cli/parser.rb +++ b/Library/Homebrew/cli/parser.rb @@ -136,7 +136,7 @@ module Homebrew switch short, long, description: desc, env: option_to_name(long), method: :on_tail end - instance_eval(&block) if block_given? + instance_eval(&block) if block end def switch(*names, description: nil, env: nil, required_for: nil, depends_on: nil, method: :on) diff --git a/Library/Homebrew/compilers.rb b/Library/Homebrew/compilers.rb index c8a9dfe584..8881c84133 100644 --- a/Library/Homebrew/compilers.rb +++ b/Library/Homebrew/compilers.rb @@ -56,7 +56,7 @@ class CompilerFailure def initialize(name, version, &block) @name = name @version = Version.parse(version.to_s) - instance_eval(&block) if block_given? + instance_eval(&block) if block end def fails_with?(compiler) diff --git a/Library/Homebrew/dependency.rb b/Library/Homebrew/dependency.rb index aa22361478..21a7d7e78c 100644 --- a/Library/Homebrew/dependency.rb +++ b/Library/Homebrew/dependency.rb @@ -120,9 +120,9 @@ class Dependency @expand_stack.pop end - def action(dependent, dep, &_block) + def action(dependent, dep, &block) catch(:action) do - if block_given? + if block yield dependent, dep elsif dep.optional? || dep.recommended? prune unless dependent.build.with?(dep) diff --git a/Library/Homebrew/extend/os/linux/formula.rb b/Library/Homebrew/extend/os/linux/formula.rb index fdcecb20d2..29ff3dd802 100644 --- a/Library/Homebrew/extend/os/linux/formula.rb +++ b/Library/Homebrew/extend/os/linux/formula.rb @@ -4,8 +4,8 @@ class Formula undef on_linux - def on_linux(&_block) - raise "No block content defined for on_linux block" unless block_given? + def on_linux(&block) + raise "No block content defined for on_linux block" unless block yield end @@ -19,8 +19,8 @@ class Formula class << self undef on_linux - def on_linux(&_block) - raise "No block content defined for on_linux block" unless block_given? + def on_linux(&block) + raise "No block content defined for on_linux block" unless block yield end diff --git a/Library/Homebrew/extend/os/mac/formula.rb b/Library/Homebrew/extend/os/mac/formula.rb index 3834f8c040..ed9f64a4b4 100644 --- a/Library/Homebrew/extend/os/mac/formula.rb +++ b/Library/Homebrew/extend/os/mac/formula.rb @@ -4,8 +4,8 @@ class Formula undef on_macos - def on_macos(&_block) - raise "No block content defined for on_macos block" unless block_given? + def on_macos(&block) + raise "No block content defined for on_macos block" unless block yield end @@ -13,8 +13,8 @@ class Formula class << self undef on_macos - def on_macos(&_block) - raise "No block content defined for on_macos block" unless block_given? + def on_macos(&block) + raise "No block content defined for on_macos block" unless block yield end diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 26b0846459..eaed557009 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -282,7 +282,7 @@ class Formula # and is specified to this instance. def installed_alias_path path = build.source["path"] if build.is_a?(Tab) - return unless path&.match?(%r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}) + return unless path&.match?(%r{#{HOMEBREW_TAP_DIR_REGEX}/Aliases}o) return unless File.symlink?(path) path @@ -1384,16 +1384,16 @@ class Formula #
on_macos do
   # # Do something Mac-specific
   # end
- def on_macos(&_block) - raise "No block content defined for on_macos block" unless block_given? + def on_macos(&block) + raise "No block content defined for on_macos block" unless block end # Block only executed on Linux. No-op on macOS. #
on_linux do
   # # Do something Linux-specific
   # end
- def on_linux(&_block) - raise "No block content defined for on_linux block" unless block_given? + def on_linux(&block) + raise "No block content defined for on_linux block" unless block end # Standard parameters for cargo builds. @@ -2118,7 +2118,7 @@ class Formula # a block. def mkdir(name, &block) result = FileUtils.mkdir_p(name) - return result unless block_given? + return result unless block FileUtils.chdir(name, &block) end @@ -2458,7 +2458,7 @@ class Formula # end def stable(&block) @stable ||= SoftwareSpec.new(flags: build_flags) - return @stable unless block_given? + return @stable unless block @stable.instance_eval(&block) end @@ -2482,7 +2482,7 @@ class Formula #
head "https://hg.is.awesome.but.git.has.won.example.com/", using: :hg
def head(val = nil, specs = {}, &block) @head ||= HeadSoftwareSpec.new(flags: build_flags) - if block_given? + if block @head.instance_eval(&block) elsif val @head.url(val, specs) @@ -2553,16 +2553,16 @@ class Formula #
on_macos do
     #   depends_on "mac_only_dep"
     # end
- def on_macos(&_block) - raise "No block content defined for on_macos block" unless block_given? + def on_macos(&block) + raise "No block content defined for on_macos block" unless block end # Block only executed on Linux. No-op on macOS. #
on_linux do
     #   depends_on "linux_only_dep"
     # end
- def on_linux(&_block) - raise "No block content defined for on_linux block" unless block_given? + def on_linux(&block) + raise "No block content defined for on_linux block" unless block end # @!attribute [w] option @@ -2757,7 +2757,7 @@ class Formula # end def livecheck(&block) @livecheck ||= Livecheck.new(self) - return @livecheck unless block_given? + return @livecheck unless block @livecheckable = true @livecheck.instance_eval(&block) diff --git a/Library/Homebrew/language/python.rb b/Library/Homebrew/language/python.rb index 5b44de4412..165ee1da28 100644 --- a/Library/Homebrew/language/python.rb +++ b/Library/Homebrew/language/python.rb @@ -270,7 +270,7 @@ module Language next unless f.symlink? next unless (rp = f.realpath.to_s).start_with? HOMEBREW_CELLAR - version = rp.match %r{^#{HOMEBREW_CELLAR}/python@(.*?)/} + version = rp.match %r{^#{HOMEBREW_CELLAR}/python@(.*?)/}o version = "@#{version.captures.first}" unless version.nil? new_target = rp.sub %r{#{HOMEBREW_CELLAR}/python#{version}/[^/]+}, Formula["python#{version}"].opt_prefix @@ -281,7 +281,7 @@ module Language Pathname.glob(@venv_root/"lib/python*/orig-prefix.txt").each do |prefix_file| prefix_path = prefix_file.read - version = prefix_path.match %r{^#{HOMEBREW_CELLAR}/python@(.*?)/} + version = prefix_path.match %r{^#{HOMEBREW_CELLAR}/python@(.*?)/}o version = "@#{version.captures.first}" unless version.nil? prefix_path.sub! %r{^#{HOMEBREW_CELLAR}/python#{version}/[^/]+}, Formula["python#{version}"].opt_prefix diff --git a/Library/Homebrew/linkage_checker.rb b/Library/Homebrew/linkage_checker.rb index d1a898cfd6..ef189d011d 100644 --- a/Library/Homebrew/linkage_checker.rb +++ b/Library/Homebrew/linkage_checker.rb @@ -129,7 +129,7 @@ class LinkageChecker private def dylib_to_dep(dylib) - dylib =~ %r{#{Regexp.escape(HOMEBREW_PREFIX)}/(opt|Cellar)/([\w+-.@]+)/} + dylib =~ %r{#{Regexp.escape(HOMEBREW_PREFIX)}/(opt|Cellar)/([\w+-.@]+)/}o Regexp.last_match(2) end diff --git a/Library/Homebrew/requirement.rb b/Library/Homebrew/requirement.rb index 93863c3086..5078ac7bd7 100644 --- a/Library/Homebrew/requirement.rb +++ b/Library/Homebrew/requirement.rb @@ -82,7 +82,7 @@ class Requirement return unless @satisfied_result.is_a?(Pathname) parent = @satisfied_result.resolved_path.parent - if parent.to_s =~ %r{^#{Regexp.escape(HOMEBREW_CELLAR)}/([\w+-.@]+)/[^/]+/(s?bin)/?$} + if parent.to_s =~ %r{^#{Regexp.escape(HOMEBREW_CELLAR)}/([\w+-.@]+)/[^/]+/(s?bin)/?$}o parent = HOMEBREW_PREFIX/"opt/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}" end parent @@ -168,14 +168,14 @@ class Requirement attr_rw :fatal, :cask, :download def satisfy(options = nil, &block) - return @satisfied if options.nil? && !block_given? + return @satisfied if options.nil? && !block options = {} if options.nil? @satisfied = Satisfier.new(options, &block) end def env(*settings, &block) - if block_given? + if block @env_proc = block else super @@ -236,9 +236,9 @@ class Requirement reqs end - def prune?(dependent, req, &_block) + def prune?(dependent, req, &block) catch(:prune) do - if block_given? + if block yield dependent, req elsif req.optional? || req.recommended? prune unless dependent.build.with?(req) diff --git a/Library/Homebrew/resource.rb b/Library/Homebrew/resource.rb index 7e16b3582e..68c237471a 100644 --- a/Library/Homebrew/resource.rb +++ b/Library/Homebrew/resource.rb @@ -32,7 +32,7 @@ class Resource @checksum = nil @using = nil @patches = [] - instance_eval(&block) if block_given? + instance_eval(&block) if block end def owner=(owner) diff --git a/Library/Homebrew/software_spec.rb b/Library/Homebrew/software_spec.rb index 14067d5a6e..f5f817ba05 100644 --- a/Library/Homebrew/software_spec.rb +++ b/Library/Homebrew/software_spec.rb @@ -107,7 +107,7 @@ class SoftwareSpec end def resource(name, klass = Resource, &block) - if block_given? + if block raise DuplicateResourceError, name if resource_defined?(name) res = klass.new(name, &block) diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index 2eae5745e2..d4a33d8ab7 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -586,7 +586,7 @@ class Tap def self.each(&block) return unless TAP_DIRECTORY.directory? - return to_enum unless block_given? + return to_enum unless block TAP_DIRECTORY.subdirs.each do |user| user.subdirs.each do |repo| diff --git a/Library/Homebrew/test/cmd/--cache_spec.rb b/Library/Homebrew/test/cmd/--cache_spec.rb index 6f8acbb945..c7e9e5dc82 100644 --- a/Library/Homebrew/test/cmd/--cache_spec.rb +++ b/Library/Homebrew/test/cmd/--cache_spec.rb @@ -10,14 +10,14 @@ end describe "brew --cache", :integration_test do it "prints all cache files for a given Formula" do expect { brew "--cache", testball } - .to output(%r{#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--testball-}).to_stdout + .to output(%r{#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--testball-}o).to_stdout .and not_to_output.to_stderr .and be_a_success end it "prints the cache files for a given Cask" do expect { brew "--cache", cask_path("local-caffeine") } - .to output(%r{#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip}).to_stdout + .to output(%r{#{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip}o).to_stdout .and not_to_output.to_stderr .and be_a_success end @@ -28,7 +28,7 @@ describe "brew --cache", :integration_test do %r{ #{HOMEBREW_CACHE}/downloads/[\da-f]{64}--testball-.*\n #{HOMEBREW_CACHE}/downloads/[\da-f]{64}--caffeine\.zip - }x, + }xo, ).to_stdout .and not_to_output.to_stderr .and be_a_success diff --git a/Library/Homebrew/test/cmd/--cellar_spec.rb b/Library/Homebrew/test/cmd/--cellar_spec.rb index 1bda2bd9f9..c558c684a8 100644 --- a/Library/Homebrew/test/cmd/--cellar_spec.rb +++ b/Library/Homebrew/test/cmd/--cellar_spec.rb @@ -10,7 +10,7 @@ end describe "brew --cellar", :integration_test do it "returns the Cellar subdirectory for a given Formula" do expect { brew "--cellar", testball } - .to output(%r{#{HOMEBREW_CELLAR}/testball}).to_stdout + .to output(%r{#{HOMEBREW_CELLAR}/testball}o).to_stdout .and not_to_output.to_stderr .and be_a_success end diff --git a/Library/Homebrew/test/cmd/--prefix_spec.rb b/Library/Homebrew/test/cmd/--prefix_spec.rb index 527581f5f5..95ac7bb042 100644 --- a/Library/Homebrew/test/cmd/--prefix_spec.rb +++ b/Library/Homebrew/test/cmd/--prefix_spec.rb @@ -10,7 +10,7 @@ end describe "brew --prefix", :integration_test do it "prints a given Formula's prefix" do expect { brew "--prefix", testball } - .to output(%r{#{HOMEBREW_CELLAR}/testball}).to_stdout + .to output(%r{#{HOMEBREW_CELLAR}/testball}o).to_stdout .and not_to_output.to_stderr .and be_a_success end diff --git a/Library/Homebrew/test/cmd/--version_spec.rb b/Library/Homebrew/test/cmd/--version_spec.rb index 7d9d71cd8b..11e91912e8 100644 --- a/Library/Homebrew/test/cmd/--version_spec.rb +++ b/Library/Homebrew/test/cmd/--version_spec.rb @@ -10,7 +10,7 @@ end describe "brew --version", :integration_test do it "prints the Homebrew version" do expect { brew "--version" } - .to output(/^Homebrew #{Regexp.escape(HOMEBREW_VERSION)}\n/).to_stdout + .to output(/^Homebrew #{Regexp.escape(HOMEBREW_VERSION)}\n/o).to_stdout .and not_to_output.to_stderr .and be_a_success end diff --git a/Library/Homebrew/test/cmd/cleanup_spec.rb b/Library/Homebrew/test/cmd/cleanup_spec.rb index 437f8a6277..d1906e5562 100644 --- a/Library/Homebrew/test/cmd/cleanup_spec.rb +++ b/Library/Homebrew/test/cmd/cleanup_spec.rb @@ -22,7 +22,7 @@ describe "brew cleanup", :integration_test do (HOMEBREW_CACHE/"test").write "test" expect { brew "cleanup", "--prune=all" } - .to output(%r{#{Regexp.escape(HOMEBREW_CACHE)}/test}).to_stdout + .to output(%r{#{Regexp.escape(HOMEBREW_CACHE)}/test}o).to_stdout .and not_to_output.to_stderr .and be_a_success end diff --git a/Library/Homebrew/test/cmd/config_spec.rb b/Library/Homebrew/test/cmd/config_spec.rb index df5bed7910..843c2a52a5 100644 --- a/Library/Homebrew/test/cmd/config_spec.rb +++ b/Library/Homebrew/test/cmd/config_spec.rb @@ -10,7 +10,7 @@ end describe "brew config", :integration_test do it "prints information about the current Homebrew configuration" do expect { brew "config" } - .to output(/HOMEBREW_VERSION: #{Regexp.escape HOMEBREW_VERSION}/).to_stdout + .to output(/HOMEBREW_VERSION: #{Regexp.escape HOMEBREW_VERSION}/o).to_stdout .and not_to_output.to_stderr .and be_a_success end diff --git a/Library/Homebrew/test/cmd/install_spec.rb b/Library/Homebrew/test/cmd/install_spec.rb index ef100add41..c17cc00ee7 100644 --- a/Library/Homebrew/test/cmd/install_spec.rb +++ b/Library/Homebrew/test/cmd/install_spec.rb @@ -12,7 +12,7 @@ describe "brew install", :integration_test do setup_test_formula "testball1" expect { brew "install", "testball1" } - .to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}).to_stdout + .to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}o).to_stdout .and not_to_output.to_stderr .and be_a_success expect(HOMEBREW_CELLAR/"testball1/0.1/foo/test").not_to be_a_file @@ -22,7 +22,7 @@ describe "brew install", :integration_test do setup_test_formula "testball1" expect { brew "install", "testball1", "--with-foo" } - .to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}).to_stdout + .to output(%r{#{HOMEBREW_CELLAR}/testball1/0\.1}o).to_stdout .and not_to_output.to_stderr .and be_a_success expect(HOMEBREW_CELLAR/"testball1/0.1/foo/test").to be_a_file @@ -36,7 +36,7 @@ describe "brew install", :integration_test do RUBY expect { brew "install", "testball1" } - .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}).to_stdout + .to output(%r{#{HOMEBREW_CELLAR}/testball1/1\.0}o).to_stdout .and not_to_output.to_stderr .and be_a_success expect(HOMEBREW_CELLAR/"testball1/1.0/foo/test").not_to be_a_file @@ -69,7 +69,7 @@ describe "brew install", :integration_test do # and there will be the git requirement, but we cannot instantiate git # formula since we only have testball1 formula. expect { brew "install", "testball1", "--HEAD", "--ignore-dependencies" } - .to output(%r{#{HOMEBREW_CELLAR}/testball1/HEAD-d5eb689}).to_stdout + .to output(%r{#{HOMEBREW_CELLAR}/testball1/HEAD-d5eb689}o).to_stdout .and output(/Cloning into/).to_stderr .and be_a_success expect(HOMEBREW_CELLAR/"testball1/HEAD-d5eb689/foo/test").not_to be_a_file diff --git a/Library/Homebrew/test/dev-cmd/command_spec.rb b/Library/Homebrew/test/dev-cmd/command_spec.rb index 5e6ecdfbe9..87c9dd61f3 100644 --- a/Library/Homebrew/test/dev-cmd/command_spec.rb +++ b/Library/Homebrew/test/dev-cmd/command_spec.rb @@ -10,7 +10,7 @@ end describe "brew command", :integration_test do it "returns the file for a given command" do expect { brew "command", "info" } - .to output(%r{#{Regexp.escape(HOMEBREW_LIBRARY_PATH)}/cmd/info.rb}).to_stdout + .to output(%r{#{Regexp.escape(HOMEBREW_LIBRARY_PATH)}/cmd/info.rb}o).to_stdout .and be_a_success end end diff --git a/Library/Homebrew/test/diagnostic_checks_spec.rb b/Library/Homebrew/test/diagnostic_checks_spec.rb index bd2c17beca..72a23e16d9 100644 --- a/Library/Homebrew/test/diagnostic_checks_spec.rb +++ b/Library/Homebrew/test/diagnostic_checks_spec.rb @@ -66,7 +66,7 @@ describe Homebrew::Diagnostic::Checks do specify "#check_user_path_2" do ENV["PATH"] = ENV["PATH"].gsub \ - %r{(?:^|#{File::PATH_SEPARATOR})#{HOMEBREW_PREFIX}/bin}, "" + %r{(?:^|#{File::PATH_SEPARATOR})#{HOMEBREW_PREFIX}/bin}o, "" expect(subject.check_user_path_1).to be nil expect(subject.check_user_path_2)