Skip to content

Commit

Permalink
Fix RuboCop offenses.
Browse files Browse the repository at this point in the history
  • Loading branch information
reitermarkus committed Nov 17, 2020
1 parent e41b3e8 commit 0184e27
Show file tree
Hide file tree
Showing 27 changed files with 60 additions and 56 deletions.
4 changes: 4 additions & 0 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ class 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)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/cmd.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def self.description

def self.parser(&block)
Homebrew::CLI::Parser.new do
if block_given?
if block
instance_eval(&block)
else
usage_banner <<~EOS
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/cmd/abstract_command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def self.parser(&block)
Cmd.parser do
usage_banner banner

instance_eval(&block) if block_given?
instance_eval(&block) if block

OPTIONS.each do |option|
send(*option)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/cmd/install.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def self.parser(&block)
send(*option)
end

instance_eval(&block) if block_given?
instance_eval(&block) if block
end
end

Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/dsl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def homepage(homepage = nil)
def language(*args, default: false, &block)
if args.empty?
language_eval
elsif block_given?
elsif block
@language_blocks ||= {}
@language_blocks[args] = block

Expand Down Expand Up @@ -248,7 +248,7 @@ def staged_path

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|
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cli/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def initialize(&block)
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)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/compilers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def self.create(spec, &block)
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)
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/dependency.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ def expand(dependent, deps = dependent.deps, &block)
@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)
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/extend/os/linux/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,8 +19,8 @@ def shared_library(name, version = nil)
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
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/extend/os/mac/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
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

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
Expand Down
26 changes: 13 additions & 13 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def validate_attributes!
# 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
Expand Down Expand Up @@ -1384,16 +1384,16 @@ def inspect
# <pre>on_macos do
# # Do something Mac-specific
# end</pre>
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.
# <pre>on_linux do
# # Do something Linux-specific
# end</pre>
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.
Expand Down Expand Up @@ -2118,7 +2118,7 @@ def mktemp(prefix = name, opts = {}, &block)
# 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
Expand Down Expand Up @@ -2458,7 +2458,7 @@ def build_flags
# end</pre>
def stable(&block)
@stable ||= SoftwareSpec.new(flags: build_flags)
return @stable unless block_given?
return @stable unless block

@stable.instance_eval(&block)
end
Expand All @@ -2482,7 +2482,7 @@ def devel
# <pre>head "https://hg.is.awesome.but.git.has.won.example.com/", using: :hg</pre>
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)
Expand Down Expand Up @@ -2553,16 +2553,16 @@ def uses_from_macos(dep, bounds = {})
# <pre>on_macos do
# depends_on "mac_only_dep"
# end</pre>
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.
# <pre>on_linux do
# depends_on "linux_only_dep"
# end</pre>
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
Expand Down Expand Up @@ -2757,7 +2757,7 @@ def test(&block)
# end</pre>
def livecheck(&block)
@livecheck ||= Livecheck.new(self)
return @livecheck unless block_given?
return @livecheck unless block

@livecheckable = true
@livecheck.instance_eval(&block)
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/language/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ def create
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
Expand All @@ -281,7 +281,7 @@ def create
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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/linkage_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def broken_dylibs_with_expectations
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

Expand Down
10 changes: 5 additions & 5 deletions Library/Homebrew/requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def satisfied_result_parent
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
Expand Down Expand Up @@ -168,14 +168,14 @@ class << self
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
Expand Down Expand Up @@ -236,9 +236,9 @@ def expand(dependent, &block)
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)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def initialize(name = nil, &block)
@checksum = nil
@using = nil
@patches = []
instance_eval(&block) if block_given?
instance_eval(&block) if block
end

def owner=(owner)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/software_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def resource_defined?(name)
end

def resource(name, klass = Resource, &block)
if block_given?
if block
raise DuplicateResourceError, name if resource_defined?(name)

res = klass.new(name, &block)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/tap.rb
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,7 @@ def ==(other)
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|
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/test/cmd/--cache_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
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
Expand All @@ -28,7 +28,7 @@
%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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/cmd/--cellar_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/cmd/--prefix_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/cmd/--version_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/cmd/cleanup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
(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
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/test/cmd/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
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
Expand Down

0 comments on commit 0184e27

Please sign in to comment.