Fix RuboCop checks.

This commit is contained in:
Mike McQuaid 2020-08-19 17:12:32 +01:00
parent 33e5e157c4
commit 3a91c37e66
No known key found for this signature in database
GPG Key ID: 48A898132FD8EE70
48 changed files with 124 additions and 107 deletions

View File

@ -212,6 +212,10 @@ Style/GuardClause:
Style/HashSyntax: Style/HashSyntax:
EnforcedStyle: ruby19 EnforcedStyle: ruby19
# so many of these in formulae and can't be autocorrected
Style/StringConcatenation:
Enabled: false
# ruby style guide favorite # ruby style guide favorite
Style/StringLiterals: Style/StringLiterals:
EnforcedStyle: double_quotes EnforcedStyle: double_quotes

View File

@ -63,7 +63,7 @@ Metrics/ModuleLength:
Max: 600 Max: 600
Metrics/PerceivedComplexity: Metrics/PerceivedComplexity:
Enabled: true Enabled: true
Max: 80 Max: 90
# we won't change backward compatible predicate names # we won't change backward compatible predicate names
Naming/PredicateName: Naming/PredicateName:
@ -139,3 +139,7 @@ Style/FrozenStringLiteralComment:
# so many of these in formulae but none in here # so many of these in formulae but none in here
Style/GuardClause: Style/GuardClause:
Enabled: true Enabled: true
# so many of these in formulae but none in here
Style/StringConcatenation:
Enabled: true

View File

@ -98,11 +98,11 @@ module Cask
@caskroom_path ||= Caskroom.path.join(token) @caskroom_path ||= Caskroom.path.join(token)
end end
def outdated?(greedy = false) def outdated?(greedy: false)
!outdated_versions(greedy).empty? !outdated_versions(greedy: greedy).empty?
end end
def outdated_versions(greedy = false) def outdated_versions(greedy: false)
# special case: tap version is not available # special case: tap version is not available
return [] if version.nil? return [] if version.nil?
@ -125,7 +125,7 @@ module Cask
def outdated_info(greedy, verbose, json) def outdated_info(greedy, verbose, json)
return token if !verbose && !json return token if !verbose && !json
installed_versions = outdated_versions(greedy).join(", ") installed_versions = outdated_versions(greedy: greedy).join(", ")
if json if json
{ {

View File

@ -44,7 +44,7 @@ module Cask
attr_reader :token, :path attr_reader :token, :path
def initialize(path) def initialize(path) # rubocop:disable Lint/MissingSuper
path = Pathname(path).expand_path path = Pathname(path).expand_path
@token = path.basename(".rb").to_s @token = path.basename(".rb").to_s
@ -79,7 +79,7 @@ module Cask
class FromURILoader < FromPathLoader class FromURILoader < FromPathLoader
def self.can_load?(ref) def self.can_load?(ref)
uri_regex = ::URI::DEFAULT_PARSER.make_regexp uri_regex = ::URI::DEFAULT_PARSER.make_regexp
return false unless ref.to_s.match?(Regexp.new('\A' + uri_regex.source + '\Z', uri_regex.options)) return false unless ref.to_s.match?(Regexp.new("\\A#{uri_regex.source}\\Z", uri_regex.options))
uri = URI(ref) uri = URI(ref)
return false unless uri return false unless uri

View File

@ -58,20 +58,22 @@ module Cask
}.freeze }.freeze
def self.description def self.description
max_command_len = Cmd.commands.map(&:length).max max_command_length = Cmd.commands.map(&:length).max
<<~EOS + command_lines = Cmd.command_classes
.select(&:visible?)
.map do |klass|
" - #{"`#{klass.command_name}`".ljust(max_command_length + 2)} #{klass.short_description}\n"
end
<<~EOS
Homebrew Cask provides a friendly CLI workflow for the administration of macOS applications distributed as binaries. Homebrew Cask provides a friendly CLI workflow for the administration of macOS applications distributed as binaries.
Commands: Commands:
#{command_lines.join}
See also: `man brew`
EOS EOS
Cmd.command_classes
.select(&:visible?)
.map do |klass|
" - #{"`#{klass.command_name}`".ljust(max_command_len + 2)} #{klass.short_description}\n"
end
.join +
"\nSee also: `man brew`"
end end
def self.parser(&block) def self.parser(&block)

View File

@ -17,7 +17,7 @@ module Cask
def run def run
success = true success = true
checks = Homebrew::Diagnostic::Checks.new true checks = Homebrew::Diagnostic::Checks.new(verbose: true)
checks.cask_checks.each do |check| checks.cask_checks.each do |check|
out = checks.send(check) out = checks.send(check)

View File

@ -34,16 +34,16 @@ module Cask
end end
def self.get_info(cask) def self.get_info(cask)
output = title_info(cask) + "\n" output = +"#{title_info(cask)}\n"
output << Formatter.url(cask.homepage) + "\n" if cask.homepage output << "#{Formatter.url(cask.homepage)}\n" if cask.homepage
output << installation_info(cask) output << installation_info(cask)
repo = repo_info(cask) repo = repo_info(cask)
output << repo + "\n" if repo output << "#{repo}\n" if repo
output << name_info(cask) output << name_info(cask)
output << desc_info(cask) output << desc_info(cask)
language = language_info(cask) language = language_info(cask)
output << language if language output << language if language
output << artifact_info(cask) + "\n" output << "#{artifact_info(cask)}\n"
caveats = Installer.caveats(cask) caveats = Installer.caveats(cask)
output << caveats if caveats output << caveats if caveats
output output

View File

@ -19,7 +19,7 @@ module Cask
def run def run
outdated_casks = casks(alternative: -> { Caskroom.casks }).select do |cask| outdated_casks = casks(alternative: -> { Caskroom.casks }).select do |cask|
odebug "Checking update info of Cask #{cask}" odebug "Checking update info of Cask #{cask}"
cask.outdated?(args.greedy?) cask.outdated?(greedy: args.greedy?)
end end
verbose = ($stdout.tty? || args.verbose?) && !args.quiet? verbose = ($stdout.tty? || args.verbose?) && !args.quiet?

View File

@ -54,13 +54,13 @@ module Cask
outdated_casks = if casks.empty? outdated_casks = if casks.empty?
Caskroom.casks.select do |cask| Caskroom.casks.select do |cask|
cask.outdated?(greedy) cask.outdated?(greedy: greedy)
end end
else else
casks.select do |cask| casks.select do |cask|
raise CaskNotInstalledError, cask unless cask.installed? || force raise CaskNotInstalledError, cask unless cask.installed? || force
cask.outdated?(true) cask.outdated?(greedy: true)
end end
end end

View File

@ -292,7 +292,7 @@ module Cask
end end
def respond_to_missing?(*) def respond_to_missing?(*)
true super || true
end end
def appdir def appdir

View File

@ -30,7 +30,7 @@ module Cask
end end
def respond_to_missing?(*) def respond_to_missing?(*)
true super || true
end end
end end
end end

View File

@ -5,6 +5,8 @@ module Cask
class MultipleCaskErrors < CaskError class MultipleCaskErrors < CaskError
def initialize(errors) def initialize(errors)
super
@errors = errors @errors = errors
end end
@ -20,6 +22,8 @@ module Cask
attr_reader :token, :reason attr_reader :token, :reason
def initialize(token, reason = nil) def initialize(token, reason = nil)
super()
@token = token @token = token
@reason = reason.to_s @reason = reason.to_s
end end
@ -168,6 +172,8 @@ module Cask
attr_reader :path, :reason attr_reader :path, :reason
def initialize(path, reason) def initialize(path, reason)
super
@path = path @path = path
@reason = reason @reason = reason
end end

View File

@ -85,7 +85,7 @@ module Cask
poo << "during #{section}" if section poo << "during #{section}" if section
poo << "on Cask #{token}." poo << "on Cask #{token}."
opoo(poo.join(" ") + "\n" + error_message_with_suggestions) opoo("#{poo.join(" ")}\n#{error_message_with_suggestions}")
end end
end end
end end

View File

@ -17,7 +17,7 @@ class Caveats
build = f.build build = f.build
f.build = Tab.for_formula(f) f.build = Tab.for_formula(f)
s = f.caveats.to_s s = f.caveats.to_s
caveats << s.chomp + "\n" unless s.empty? caveats << "#{s.chomp}\n" unless s.empty?
ensure ensure
f.build = build f.build = build
end end

View File

@ -28,7 +28,7 @@ class Cleaner
[@f.bin, @f.sbin, @f.lib].each { |d| clean_dir(d) if d.exist? } [@f.bin, @f.sbin, @f.lib].each { |d| clean_dir(d) if d.exist? }
# Get rid of any info 'dir' files, so they don't conflict at the link stage # Get rid of any info 'dir' files, so they don't conflict at the link stage
info_dir_file = @f.info + "dir" info_dir_file = @f.info/"dir"
observe_file_removal info_dir_file if info_dir_file.file? && !@f.skip_clean?(info_dir_file) observe_file_removal info_dir_file if info_dir_file.file? && !@f.skip_clean?(info_dir_file)
prune prune

View File

@ -48,7 +48,7 @@ module Homebrew
mtime < days.days.ago && ctime < days.days.ago mtime < days.days.ago && ctime < days.days.ago
end end
def stale?(scrub = false) def stale?(scrub: false)
return false unless resolved_path.file? return false unless resolved_path.file?
if dirname.basename.to_s == "Cask" if dirname.basename.to_s == "Cask"
@ -308,7 +308,7 @@ module Homebrew
next next
end end
next cleanup_path(path) { path.unlink } if path.stale?(scrub?) next cleanup_path(path) { path.unlink } if path.stale?(scrub: scrub?)
end end
cleanup_unreferenced_downloads cleanup_unreferenced_downloads

View File

@ -142,9 +142,9 @@ module Homebrew
if @table[switch] == true || @table[flag] == true if @table[switch] == true || @table[flag] == true
@cli_args << option @cli_args << option
elsif @table[flag].instance_of? String elsif @table[flag].instance_of? String
@cli_args << option + "=" + @table[flag] @cli_args << "#{option}=#{@table[flag]}"
elsif @table[flag].instance_of? Array elsif @table[flag].instance_of? Array
@cli_args << option + "=" + @table[flag].join(",") @cli_args << "#{option}=#{@table[flag].join(",")}"
end end
end end
@cli_args.freeze @cli_args.freeze

View File

@ -11,7 +11,7 @@ module Homebrew
@force_bottle = force_bottle @force_bottle = force_bottle
@flags = flags @flags = flags
__setobj__(@args) super(@args)
end end
def to_formulae def to_formulae

View File

@ -83,26 +83,26 @@ module Homebrew
raise FormulaUnspecifiedError raise FormulaUnspecifiedError
end end
puts_deps_tree dependents, recursive, args: args puts_deps_tree dependents, recursive: recursive, args: args
return return
elsif args.all? elsif args.all?
puts_deps sorted_dependents(Formula.to_a + Cask::Cask.to_a), recursive, args: args puts_deps sorted_dependents(Formula.to_a + Cask::Cask.to_a), recursive: recursive, args: args
return return
elsif !args.no_named? && args.for_each? elsif !args.no_named? && args.for_each?
puts_deps sorted_dependents(args.formulae_and_casks), recursive, args: args puts_deps sorted_dependents(args.formulae_and_casks), recursive: recursive, args: args
return return
end end
if args.no_named? if args.no_named?
raise FormulaUnspecifiedError unless args.installed? raise FormulaUnspecifiedError unless args.installed?
puts_deps sorted_dependents(Formula.installed + Cask::Caskroom.casks), recursive, args: args puts_deps sorted_dependents(Formula.installed + Cask::Caskroom.casks), recursive: recursive, args: args
return return
end end
dependents = dependents(args.formulae_and_casks) dependents = dependents(args.formulae_and_casks)
all_deps = deps_for_dependents(dependents, recursive, args: args, &(args.union? ? :| : :&)) all_deps = deps_for_dependents(dependents, recursive: recursive, args: args, &(args.union? ? :| : :&))
condense_requirements(all_deps, args: args) condense_requirements(all_deps, args: args)
all_deps.map! { |d| dep_display_name(d, args: args) } all_deps.map! { |d| dep_display_name(d, args: args) }
all_deps.uniq! all_deps.uniq!
@ -144,7 +144,7 @@ module Homebrew
str str
end end
def deps_for_dependent(d, recursive = false, args:) def deps_for_dependent(d, recursive: false, args:)
includes, ignores = args_includes_ignores(args) includes, ignores = args_includes_ignores(args)
deps = d.runtime_dependencies if @use_runtime_dependencies deps = d.runtime_dependencies if @use_runtime_dependencies
@ -160,13 +160,13 @@ module Homebrew
deps + reqs.to_a deps + reqs.to_a
end end
def deps_for_dependents(dependents, recursive = false, args:, &block) def deps_for_dependents(dependents, recursive: false, args:, &block)
dependents.map { |d| deps_for_dependent(d, recursive, args: args) }.reduce(&block) dependents.map { |d| deps_for_dependent(d, recursive: recursive, args: args) }.reduce(&block)
end end
def puts_deps(dependents, recursive = false, args:) def puts_deps(dependents, recursive: false, args:)
dependents.each do |dependent| dependents.each do |dependent|
deps = deps_for_dependent(dependent, recursive, args: args) deps = deps_for_dependent(dependent, recursive: recursive, args: args)
condense_requirements(deps, args: args) condense_requirements(deps, args: args)
deps.sort_by!(&:name) deps.sort_by!(&:name)
deps.map! { |d| dep_display_name(d, args: args) } deps.map! { |d| dep_display_name(d, args: args) }
@ -174,7 +174,7 @@ module Homebrew
end end
end end
def puts_deps_tree(dependents, recursive = false, args:) def puts_deps_tree(dependents, recursive: false, args:)
dependents.each do |d| dependents.each do |d|
puts d.full_name puts d.full_name
@dep_stack = [] @dep_stack = []

View File

@ -31,7 +31,7 @@ module Homebrew
inject_dump_stats!(Diagnostic::Checks, /^check_*/) if args.audit_debug? inject_dump_stats!(Diagnostic::Checks, /^check_*/) if args.audit_debug?
checks = Diagnostic::Checks.new args.verbose? checks = Diagnostic::Checks.new(verbose: args.verbose?)
if args.list_checks? if args.list_checks?
puts checks.all.sort puts checks.all.sort

View File

@ -179,7 +179,7 @@ module Commands
cmds = internal_commands + internal_developer_commands + internal_commands_aliases cmds = internal_commands + internal_developer_commands + internal_commands_aliases
file = HOMEBREW_REPOSITORY/"completions/internal_commands_list.txt" file = HOMEBREW_REPOSITORY/"completions/internal_commands_list.txt"
file.atomic_write(cmds.sort.join("\n") + "\n") file.atomic_write("#{cmds.sort.join("\n")}\n")
end end
def rebuild_commands_completion_list def rebuild_commands_completion_list
@ -187,6 +187,6 @@ module Commands
HOMEBREW_CACHE.mkpath HOMEBREW_CACHE.mkpath
file = HOMEBREW_CACHE/"all_commands_list.txt" file = HOMEBREW_CACHE/"all_commands_list.txt"
file.atomic_write(commands(aliases: true).sort.join("\n") + "\n") file.atomic_write("#{commands(aliases: true).sort.join("\n")}\n")
end end
end end

View File

@ -544,7 +544,7 @@ module Homebrew
)\n+ # multiple empty lines )\n+ # multiple empty lines
)+ )+
/mx /mx
string = s.sub!(pattern, '\0' + output + "\n") string = s.sub!(pattern, "\\0#{output}\n")
odie "Bottle block addition failed!" unless string odie "Bottle block addition failed!" unless string
end end
end end

View File

@ -378,7 +378,8 @@ module Homebrew
EOS EOS
user_message = args.message user_message = args.message
if user_message if user_message
pr_message += "\n" + <<~EOS pr_message += <<~EOS
--- ---
#{user_message} #{user_message}

View File

@ -65,7 +65,7 @@ module Homebrew
revision: "#{formula_spec.specs[:revision]}" revision: "#{formula_spec.specs[:revision]}"
EOS EOS
end end
replacement = old + " revision 1\n" replacement = "#{old} revision 1\n"
else else
old = "revision #{current_revision}" old = "revision #{current_revision}"

View File

@ -205,7 +205,7 @@ module Homebrew
def initialize(url, args, description = nil) def initialize(url, args, description = nil)
@base_url = url @base_url = url
# GitHub provides commits/pull-requests raw patches using this URL. # GitHub provides commits/pull-requests raw patches using this URL.
@patch_url = url + ".patch" @patch_url = "#{url}.patch"
@patchpath = HOMEBREW_CACHE + File.basename(patch_url) @patchpath = HOMEBREW_CACHE + File.basename(patch_url)
@description = description @description = description
@args = args @args = args

View File

@ -30,7 +30,7 @@ module Homebrew
# Diagnostic checks. # Diagnostic checks.
class Checks class Checks
def initialize(verbose = true) def initialize(verbose: true)
@verbose = verbose @verbose = verbose
end end

View File

@ -345,7 +345,7 @@ class CurlDownloadStrategy < AbstractFileDownloadStrategy
return @resolved_info_cache[url] if @resolved_info_cache.include?(url) return @resolved_info_cache[url] if @resolved_info_cache.include?(url)
if (domain = Homebrew::EnvConfig.artifact_domain) if (domain = Homebrew::EnvConfig.artifact_domain)
url = url.sub(%r{^((ht|f)tps?://)?}, domain.chomp("/") + "/") url = url.sub(%r{^((ht|f)tps?://)?}, "#{domain.chomp("/")}/")
end end
out, _, status= curl_output("--location", "--silent", "--head", "--request", "GET", url.to_s) out, _, status= curl_output("--location", "--silent", "--head", "--request", "GET", url.to_s)
@ -503,7 +503,7 @@ end
# This strategy extracts local binary packages. # This strategy extracts local binary packages.
class LocalBottleDownloadStrategy < AbstractFileDownloadStrategy class LocalBottleDownloadStrategy < AbstractFileDownloadStrategy
def initialize(path) def initialize(path) # rubocop:disable Lint/MissingSuper
@cached_location = path @cached_location = path
end end
end end
@ -552,7 +552,7 @@ class SubversionDownloadStrategy < VCSDownloadStrategy
end end
end end
def fetch_repo(target, url, revision = nil, ignore_externals = false) def fetch_repo(target, url, revision = nil, ignore_externals: false)
# Use "svn update" when the repository already exists locally. # Use "svn update" when the repository already exists locally.
# This saves on bandwidth and will have a similar effect to verifying the # This saves on bandwidth and will have a similar effect to verifying the
# cache as it will make any changes to get the right revision. # cache as it will make any changes to get the right revision.
@ -593,10 +593,10 @@ class SubversionDownloadStrategy < VCSDownloadStrategy
when :revisions when :revisions
# nil is OK for main_revision, as fetch_repo will then get latest # nil is OK for main_revision, as fetch_repo will then get latest
main_revision = @ref[:trunk] main_revision = @ref[:trunk]
fetch_repo cached_location, @url, main_revision, true fetch_repo cached_location, @url, main_revision, ignore_externals: true
externals do |external_name, external_url| externals do |external_name, external_url|
fetch_repo cached_location/external_name, external_url, @ref[external_name], true fetch_repo cached_location/external_name, external_url, @ref[external_name], ignore_externals: true
end end
else else
fetch_repo cached_location, @url fetch_repo cached_location, @url

View File

@ -7,6 +7,8 @@ class UsageError < RuntimeError
attr_reader :reason attr_reader :reason
def initialize(reason = nil) def initialize(reason = nil)
super
@reason = reason @reason = reason
end end
@ -63,6 +65,8 @@ class FormulaUnavailableError < RuntimeError
attr_accessor :dependent attr_accessor :dependent
def initialize(name) def initialize(name)
super
@name = name @name = name
end end

View File

@ -84,7 +84,7 @@ module Hardware
end end
%w[aes altivec avx avx2 lm ssse3 sse4_2].each do |flag| %w[aes altivec avx avx2 lm ssse3 sse4_2].each do |flag|
define_method(flag + "?") { flags.include? flag } define_method("#{flag}?") { flags.include? flag }
end end
def sse3? def sse3?

View File

@ -22,8 +22,8 @@ class OsxfuseRequirement < Requirement
def message def message
msg = "libfuse is required to install this formula.\n" msg = "libfuse is required to install this formula.\n"
if libfuse_formula_exists? if libfuse_formula_exists?
msg + <<~EOS <<~EOS
Run `brew install libfuse` to install it. #{msg}Run `brew install libfuse` to install it.
EOS EOS
else else
msg + super msg + super

View File

@ -44,6 +44,6 @@ class Caveats
s << "" << "WARNING: brew services will fail when run under tmux." s << "" << "WARNING: brew services will fail when run under tmux."
end end
end end
s.join("\n") + "\n" unless s.empty? "#{s.join("\n")}\n" unless s.empty?
end end
end end

View File

@ -22,7 +22,7 @@ class StringInreplaceExtension
end end
# Warn if nothing was replaced # Warn if nothing was replaced
def gsub!(before, after, audit_result = true) def gsub!(before, after, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
result = inreplace_string.gsub!(before, after) result = inreplace_string.gsub!(before, after)
errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil? errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil?
result result

View File

@ -944,12 +944,12 @@ class Formula
# The generated launchd {.plist} service name. # The generated launchd {.plist} service name.
def plist_name def plist_name
"homebrew.mxcl." + name "homebrew.mxcl.#{name}"
end end
# The generated launchd {.plist} file path. # The generated launchd {.plist} file path.
def plist_path def plist_path
prefix + (plist_name + ".plist") prefix/"#{plist_name}.plist"
end end
# @private # @private
@ -1137,7 +1137,7 @@ class Formula
to_check = path.relative_path_from(HOMEBREW_PREFIX).to_s to_check = path.relative_path_from(HOMEBREW_PREFIX).to_s
self.class.link_overwrite_paths.any? do |p| self.class.link_overwrite_paths.any? do |p|
p == to_check || p == to_check ||
to_check.start_with?(p.chomp("/") + "/") || to_check.start_with?("#{p.chomp("/")}/") ||
to_check =~ /^#{Regexp.escape(p).gsub('\*', ".*?")}$/ to_check =~ /^#{Regexp.escape(p).gsub('\*', ".*?")}$/
end end
end end
@ -2070,21 +2070,17 @@ class Formula
# recursively delete the temporary directory. Passing `opts[:retain]` # recursively delete the temporary directory. Passing `opts[:retain]`
# or calling `do |staging| ... staging.retain!` in the block will skip # or calling `do |staging| ... staging.retain!` in the block will skip
# the deletion and retain the temporary directory's contents. # the deletion and retain the temporary directory's contents.
def mktemp(prefix = name, opts = {}) def mktemp(prefix = name, opts = {}, &block)
Mktemp.new(prefix, opts).run do |staging| Mktemp.new(prefix, opts).run(&block)
yield staging
end
end end
# A version of `FileUtils.mkdir` that also changes to that folder in # A version of `FileUtils.mkdir` that also changes to that folder in
# a block. # a block.
def mkdir(name) def mkdir(name, &block)
result = FileUtils.mkdir_p(name) result = FileUtils.mkdir_p(name)
return result unless block_given? return result unless block_given?
FileUtils.chdir name do FileUtils.chdir(name, &block)
yield
end
end end
# Run `xcodebuild` without Homebrew's compiler environment variables set. # Run `xcodebuild` without Homebrew's compiler environment variables set.
@ -2184,6 +2180,8 @@ class Formula
include BuildEnvironment::DSL include BuildEnvironment::DSL
def method_added(method) def method_added(method)
super
case method case method
when :brew when :brew
raise "You cannot override Formula#brew in class #{name}" raise "You cannot override Formula#brew in class #{name}"

View File

@ -362,10 +362,10 @@ class Keg
ObserverPathnameExtension.n ObserverPathnameExtension.n
end end
def lock def lock(&block)
FormulaLock.new(name).with_lock do FormulaLock.new(name).with_lock do
if oldname_opt_record if oldname_opt_record
FormulaLock.new(oldname_opt_record.basename.to_s).with_lock { yield } FormulaLock.new(oldname_opt_record.basename.to_s).with_lock(&block)
else else
yield yield
end end

View File

@ -126,10 +126,8 @@ class Requirement
name name
end end
def mktemp def mktemp(&block)
Mktemp.new(name).run do |staging| Mktemp.new(name).run(&block)
yield staging
end
end end
private private

View File

@ -193,10 +193,8 @@ class Resource
protected protected
def mktemp(prefix) def mktemp(prefix, &block)
Mktemp.new(prefix).run do |staging| Mktemp.new(prefix).run(&block)
yield staging
end
end end
private private

View File

@ -467,7 +467,7 @@ module RuboCop
fileutils_methods = Regexp.new( fileutils_methods = Regexp.new(
FileUtils.singleton_methods(false) FileUtils.singleton_methods(false)
.map { |m| "(?-mix:^" + Regexp.escape(m) + "$)" } .map { |m| "(?-mix:^#{Regexp.escape(m)}$)" }
.join("|"), .join("|"),
) )
find_every_method_call_by_name(body_node, :system).each do |method| find_every_method_call_by_name(body_node, :system).each do |method|

View File

@ -71,7 +71,9 @@ class SystemCommand
@options = options @options = options
@env = env @env = env
@env.keys.grep_v(/^[\w&&\D]\w*$/) do |name| @env.each_key do |name|
next if /^[\w&&\D]\w*$/.match?(name)
raise ArgumentError, "Invalid variable name: '#{name}'" raise ArgumentError, "Invalid variable name: '#{name}'"
end end
end end

View File

@ -134,7 +134,7 @@ describe Cask::Cask, :cask do
expectations.each do |installed_version, expected_output| expectations.each do |installed_version, expected_output|
context "when versions #{installed_version} are installed and the " \ context "when versions #{installed_version} are installed and the " \
"tap version is #{tap_version}, #{"not" unless greedy} greedy" do "tap version is #{tap_version}, #{"not" unless greedy} greedy" do
subject { cask.outdated_versions greedy } subject { cask.outdated_versions(greedy: greedy) }
it { it {
allow(cask).to receive(:versions).and_return(installed_version) allow(cask).to receive(:versions).and_return(installed_version)

View File

@ -111,7 +111,7 @@ describe Cask::Cmd::Outdated, :cask do
expect { expect {
described_class.run("--json") described_class.run("--json")
}.to output(result + "\n").to_stdout }.to output("#{result}\n").to_stdout
end end
end end
@ -132,7 +132,7 @@ describe Cask::Cmd::Outdated, :cask do
expect { expect {
described_class.run("--json", "--quiet") described_class.run("--json", "--quiet")
}.to output(result + "\n").to_stdout }.to output("#{result}\n").to_stdout
end end
end end
@ -163,7 +163,7 @@ describe Cask::Cmd::Outdated, :cask do
expect { expect {
described_class.run("--json", "--greedy") described_class.run("--json", "--greedy")
}.to output(result + "\n").to_stdout }.to output("#{result}\n").to_stdout
end end
it 'does not include the Casks with "auto_updates true" with no version change in JSON format' do it 'does not include the Casks with "auto_updates true" with no version change in JSON format' do
@ -190,7 +190,7 @@ describe Cask::Cmd::Outdated, :cask do
expect { expect {
described_class.run("--json", "--greedy") described_class.run("--json", "--greedy")
}.to output(result + "\n").to_stdout }.to output("#{result}\n").to_stdout
end end
end end
end end

View File

@ -233,7 +233,7 @@ describe Cask::Installer, :cask do
it "uninstalls all versions if force is set" do it "uninstalls all versions if force is set" do
caffeine = Cask::CaskLoader.load(cask_path("local-caffeine")) caffeine = Cask::CaskLoader.load(cask_path("local-caffeine"))
mutated_version = caffeine.version + ".1" mutated_version = "#{caffeine.version}.1"
described_class.new(caffeine).install described_class.new(caffeine).install

View File

@ -287,7 +287,7 @@ describe Homebrew::CLI::Parser do
context "kegs" do context "kegs" do
before do before do
keg = HOMEBREW_CELLAR + "mxcl/10.0" keg = HOMEBREW_CELLAR/"mxcl/10.0"
keg.mkpath keg.mkpath
end end

View File

@ -22,7 +22,7 @@ describe "brew outdated", :integration_test do
].to_json ].to_json
expect { brew "outdated", "--json=v1" } expect { brew "outdated", "--json=v1" }
.to output(expected_json + "\n").to_stdout .to output("#{expected_json}\n").to_stdout
.and be_a_success .and be_a_success
end end
end end

View File

@ -266,16 +266,12 @@ module Kernel
raise $CHILD_STATUS.inspect raise $CHILD_STATUS.inspect
end end
def with_homebrew_path def with_homebrew_path(&block)
with_env(PATH: PATH.new(ENV["HOMEBREW_PATH"])) do with_env(PATH: PATH.new(ENV["HOMEBREW_PATH"]), &block)
yield
end
end end
def with_custom_locale(locale) def with_custom_locale(locale, &block)
with_env(LC_ALL: locale) do with_env(LC_ALL: locale, &block)
yield
end
end end
# Kernel.system but with exceptions # Kernel.system but with exceptions

View File

@ -47,8 +47,8 @@ module Formatter
indent = width - desc indent = width - desc
s.gsub(/(?<=\S) *\n(?=\S)/, " ") s.gsub(/(?<=\S) *\n(?=\S)/, " ")
.gsub(/([`>)\]]:) /, "\\1\n ") .gsub(/([`>)\]]:) /, "\\1\n ")
.gsub(/^( +-.+ +(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n" + " " * indent) .gsub(/^( +-.+ +(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n#{" " * indent}")
.gsub(/^( {#{indent}}(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n" + " " * indent) .gsub(/^( {#{indent}}(?=\S.{#{desc}}))(.{1,#{desc}})( +|$)\n?/, "\\1\\2\n#{" " * indent}")
.gsub(/(.{1,#{width}})( +|$)\n?/, "\\1\n") .gsub(/(.{1,#{width}})( +|$)\n?/, "\\1\n")
end end

View File

@ -21,7 +21,7 @@ module Utils
# #
# `inreplace` supports regular expressions: # `inreplace` supports regular expressions:
# <pre>inreplace "somefile.cfg", /look[for]what?/, "replace by #{bin}/tool"</pre> # <pre>inreplace "somefile.cfg", /look[for]what?/, "replace by #{bin}/tool"</pre>
def inreplace(paths, before = nil, after = nil, audit_result = true) def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter
errors = {} errors = {}
errors["`paths` (first) parameter"] = ["`paths` was empty"] if paths.blank? errors["`paths` (first) parameter"] = ["`paths` was empty"] if paths.blank?

View File

@ -92,7 +92,7 @@ module Utils
str = str.dup str = str.dup
# anything that isn't a known safe character is padded # anything that isn't a known safe character is padded
str.gsub!(UNSAFE_SHELL_CHAR, "\\\\" + "\\1") str.gsub!(UNSAFE_SHELL_CHAR, "\\\\" + "\\1") # rubocop:disable Style/StringConcatenation
# newlines have to be specially quoted in csh # newlines have to be specially quoted in csh
str.gsub!(/\n/, "'\\\n'") str.gsub!(/\n/, "'\\\n'")
str str
@ -105,7 +105,7 @@ module Utils
str = str.dup str = str.dup
# anything that isn't a known safe character is padded # anything that isn't a known safe character is padded
str.gsub!(UNSAFE_SHELL_CHAR, "\\\\" + "\\1") str.gsub!(UNSAFE_SHELL_CHAR, "\\\\" + "\\1") # rubocop:disable Style/StringConcatenation
str.gsub!(/\n/, "'\n'") str.gsub!(/\n/, "'\n'")
str str
end end

View File

@ -102,6 +102,8 @@ class Version
PATTERN = /[a-z]+/i.freeze PATTERN = /[a-z]+/i.freeze
def initialize(value) def initialize(value)
super
@value = value.to_s @value = value.to_s
end end
@ -121,6 +123,8 @@ class Version
PATTERN = /[0-9]+/i.freeze PATTERN = /[0-9]+/i.freeze
def initialize(value) def initialize(value)
super
@value = value.to_i @value = value.to_i
end end