Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RuboCop autofixes for Ruby 3.1 #16337

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def self.fetch_json_api_file(endpoint, target: HOMEBREW_CACHE_API/endpoint,
end

mtime = insecure_download ? Time.new(1970, 1, 1) : Time.now
FileUtils.touch(target, mtime: mtime) unless skip_download
FileUtils.touch(target, mtime:) unless skip_download
JSON.parse(target.read)
rescue JSON::ParserError
target.unlink
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/api/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def all_renames
def write_names(regenerate: false)
download_and_cache_data! unless cache.key?("casks")

Homebrew::API.write_names_file(all_casks.keys, "cask", regenerate: regenerate)
Homebrew::API.write_names_file(all_casks.keys, "cask", regenerate:)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/api/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def all_renames
def write_names_and_aliases(regenerate: false)
download_and_cache_data! unless cache.key?("formulae")

return unless Homebrew::API.write_names_file(all_formulae.keys, "formula", regenerate: regenerate)
return unless Homebrew::API.write_names_file(all_formulae.keys, "formula", regenerate:)

(HOMEBREW_CACHE_API/"formula_aliases.txt").open("w") do |file|
all_aliases.each do |alias_name, real_name|
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/brew.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
# - no arguments are passed
if empty_argv || help_flag
require "help"
Homebrew::Help.help cmd, remaining_args: args.remaining, empty_argv: empty_argv
Homebrew::Help.help cmd, remaining_args: args.remaining, empty_argv:
# `Homebrew::Help.help` never returns, except for unknown commands.
end

Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ def install
ENV.deps = formula_deps
ENV.run_time_deps = run_time_deps
ENV.setup_build_environment(
formula: formula,
formula:,
cc: args.cc,
build_bottle: args.build_bottle?,
bottle_arch: args.bottle_arch,
Expand All @@ -94,7 +94,7 @@ def install
deps.each(&:modify_build_environment)
else
ENV.setup_build_environment(
formula: formula,
formula:,
cc: args.cc,
build_bottle: args.build_bottle?,
bottle_arch: args.bottle_arch,
Expand Down Expand Up @@ -227,7 +227,7 @@ def fixopt(formula)

formula = args.named.to_formulae.first
options = Options.create(args.flags_only)
build = Build.new(formula, options, args: args)
build = Build.new(formula, options, args:)
build.install
rescue Exception => e # rubocop:disable Lint/RescueException
error_hash = JSON.parse e.to_json
Expand Down
16 changes: 8 additions & 8 deletions Library/Homebrew/cask/artifact/abstract_uninstall.rb
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ def uninstall_launchctl(*services, command: nil, **_)
plist_status = command.run(
"/bin/launchctl",
args: ["list", service],
sudo: sudo,
sudo:,
sudo_as_root: sudo,
print_stderr: false,
).stdout
if plist_status.start_with?("{")
command.run!(
"/bin/launchctl",
args: ["remove", service],
sudo: sudo,
sudo:,
sudo_as_root: sudo,
)
sleep 1
Expand All @@ -129,21 +129,21 @@ def uninstall_launchctl(*services, command: nil, **_)
paths.each { |elt| elt.prepend(Dir.home).freeze } unless sudo
paths = paths.map { |elt| Pathname(elt) }.select(&:exist?)
paths.each do |path|
command.run!("/bin/rm", args: ["-f", "--", path], sudo: sudo, sudo_as_root: sudo)
command.run!("/bin/rm", args: ["-f", "--", path], sudo:, sudo_as_root: sudo)
end
# undocumented and untested: pass a path to uninstall :launchctl
next unless Pathname(service).exist?

command.run!(
"/bin/launchctl",
args: ["unload", "-w", "--", service],
sudo: sudo,
sudo:,
sudo_as_root: sudo,
)
command.run!(
"/bin/rm",
args: ["-f", "--", service],
sudo: sudo,
sudo:,
sudo_as_root: sudo,
)
sleep 1
Expand Down Expand Up @@ -502,13 +502,13 @@ def recursive_rmdir(*directories, command: nil, **_)

# Directory counts as empty if it only contains a `.DS_Store`.
if children.include?(ds_store = resolved_path/".DS_Store")
Utils.gain_permissions_remove(ds_store, command: command)
Utils.gain_permissions_remove(ds_store, command:)
children.delete(ds_store)
end

next false unless recursive_rmdir(*children, command: command)
next false unless recursive_rmdir(*children, command:)

Utils.gain_permissions_rmdir(resolved_path, command: command)
Utils.gain_permissions_rmdir(resolved_path, command:)

true
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/artifact/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ def resolve_target(target)

sig { params(cask: Cask, source: T.any(String, Pathname), target: T.any(String, Pathname)).void }
def initialize(cask, source, target:)
super(cask, source, target: target)
super(cask, source, target:)
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/artifact/binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module Artifact
# @api private
class Binary < Symlinked
def link(command: nil, **options)
super(command: command, **options)
super(command:, **options)
return if source.executable?

if source.writable?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/artifact/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def summarize
end

def to_h
{ path: path }.tap do |h|
{ path: }.tap do |h|
h[:args] = args unless is_a?(ManualInstaller)
end
end
Expand Down
24 changes: 12 additions & 12 deletions Library/Homebrew/cask/artifact/moved.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def move(adopt: false, force: false, verbose: false, predecessor: nil, reinstall
if target.parent.writable? && !force
target.rmdir
else
Utils.gain_permissions_remove(target, command: command)
Utils.gain_permissions_remove(target, command:)
end
end
else
Expand All @@ -55,7 +55,7 @@ def move(adopt: false, force: false, verbose: false, predecessor: nil, reinstall
same = command.run(
"/usr/bin/diff",
args: ["--recursive", "--brief", source, target],
verbose: verbose,
verbose:,
print_stdout: verbose,
).success?

Expand All @@ -76,22 +76,22 @@ def move(adopt: false, force: false, verbose: false, predecessor: nil, reinstall
raise CaskError, "#{message}." unless force

opoo "#{message}; overwriting."
delete(target, force: force, command: command, **options)
delete(target, force:, command:, **options)
end
end

ohai "Moving #{self.class.english_name} '#{source.basename}' to '#{target}'"

Utils.gain_permissions_mkpath(target.dirname, command: command) unless target.dirname.exist?
Utils.gain_permissions_mkpath(target.dirname, command:) unless target.dirname.exist?

if target.directory? && Quarantine.app_management_permissions_granted?(app: target, command: command)
if target.directory? && Quarantine.app_management_permissions_granted?(app: target, command:)
if target.writable?
source.children.each { |child| FileUtils.move(child, target/child.basename) }
else
command.run!("/bin/cp", args: ["-pR", *source.children, target],
sudo: true)
end
Quarantine.copy_xattrs(source, target, command: command)
Quarantine.copy_xattrs(source, target, command:)
source.rmtree
elsif target.dirname.writable?
FileUtils.move(source, target)
Expand All @@ -109,7 +109,7 @@ def move(adopt: false, force: false, verbose: false, predecessor: nil, reinstall
def post_move(command)
FileUtils.ln_sf target, source

add_altname_metadata(target, source.basename, command: command)
add_altname_metadata(target, source.basename, command:)
end

def matching_artifact?(cask)
Expand All @@ -129,7 +129,7 @@ def move_back(skip: false, force: false, command: nil, **options)
raise CaskError, "#{message}." unless force

opoo "#{message}; overwriting."
delete(source, force: force, command: command, **options)
delete(source, force:, command:, **options)
end

unless target.exist?
Expand All @@ -144,7 +144,7 @@ def move_back(skip: false, force: false, command: nil, **options)
# We need to preserve extended attributes between copies.
command.run!("/bin/cp", args: ["-pR", target, source], sudo: !source.parent.writable?)

delete(target, force: force, command: command, **options)
delete(target, force:, command:, **options)
end

def delete(target, force: false, successor: nil, command: nil, **_)
Expand All @@ -154,21 +154,21 @@ def delete(target, force: false, successor: nil, command: nil, **_)
return unless Utils.path_occupied?(target)

if target.directory? && matching_artifact?(successor) && Quarantine.app_management_permissions_granted?(
app: target, command: command,
app: target, command:,
)
# If an app folder is deleted, macOS considers the app uninstalled and removes some data.
# Remove only the contents to handle this case.
target.children.each do |child|
if target.writable? && !force
child.rmtree
else
Utils.gain_permissions_remove(child, command: command)
Utils.gain_permissions_remove(child, command:)
end
end
elsif target.parent.writable? && !force
target.rmtree
else
Utils.gain_permissions_remove(target, command: command)
Utils.gain_permissions_remove(target, command:)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cask/artifact/pkg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def run_installer(command: nil, verbose: false, **_options)
"/usr/sbin/installer",
sudo: true,
sudo_as_root: true,
args: args,
args:,
print_stdout: true,
env: env,
env:,
)
end
end
Expand Down
10 changes: 5 additions & 5 deletions Library/Homebrew/cask/artifact/symlinked.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,30 @@ def link(force: false, command: nil, **_options)
if force && target.symlink? &&
(target.realpath == source.realpath || target.realpath.to_s.start_with?("#{cask.caskroom_path}/"))
opoo "#{message}; overwriting."
Utils.gain_permissions_remove(target, command: command)
Utils.gain_permissions_remove(target, command:)
else
raise CaskError, "#{message}."
end
end

ohai "Linking #{self.class.english_name} '#{source.basename}' to '#{target}'"
create_filesystem_link(command: command)
create_filesystem_link(command:)
end

def unlink(command: nil, **)
return unless target.symlink?

ohai "Unlinking #{self.class.english_name} '#{target}'"
Utils.gain_permissions_remove(target, command: command)
Utils.gain_permissions_remove(target, command:)
end

def create_filesystem_link(command: nil)
Utils.gain_permissions_mkpath(target.dirname, command: command)
Utils.gain_permissions_mkpath(target.dirname, command:)

command.run! "/bin/ln", args: ["-h", "-f", "-s", "--", source, target],
sudo: !target.dirname.writable?

add_altname_metadata(source, target.basename, command: command)
add_altname_metadata(source, target.basename, command:)
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def initialize(
download = online || signing if download.nil?

@cask = cask
@download = Download.new(cask, quarantine: quarantine) if download
@download = Download.new(cask, quarantine:) if download
@online = online
@strict = strict
@signing = signing
Expand Down Expand Up @@ -93,7 +93,7 @@ def add_error(message, location: nil, strict_only: false)
# Only raise non-critical audits if the user specified `--strict`.
return if strict_only && !@strict

errors << ({ message: message, location: location, corrected: false })
errors << ({ message:, location:, corrected: false })
end

def result
Expand Down Expand Up @@ -661,7 +661,7 @@ def audit_github_prerelease_version

tag = SharedAudits.github_tag_from_url(cask.url)
tag ||= cask.version
error = SharedAudits.github_release(user, repo, tag, cask: cask)
error = SharedAudits.github_release(user, repo, tag, cask:)
add_error error, location: cask.url.location if error
end

Expand All @@ -676,7 +676,7 @@ def audit_gitlab_prerelease_version

tag = SharedAudits.gitlab_tag_from_url(cask.url)
tag ||= cask.version
error = SharedAudits.gitlab_release(user, repo, tag, cask: cask)
error = SharedAudits.gitlab_release(user, repo, tag, cask:)
add_error error, location: cask.url.location if error
end

Expand Down Expand Up @@ -814,7 +814,7 @@ def validate_url_for_https_availability(url_to_check, url_type, cask_token, tap,
add_error problem, location: location unless exception
elsif exception
add_error "#{url_to_check} is in the secure connection audit skiplist but does not need to be skipped",
location: location
location:
end
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cask/auditor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def output_summary?(audit = nil)

def audit_languages(languages)
original_config = cask.config
localized_config = original_config.merge(Config.new(explicit: { languages: languages }))
localized_config = original_config.merge(Config.new(explicit: { languages: }))
cask.config = localized_config

audit_cask_instance(cask)
Expand Down
14 changes: 7 additions & 7 deletions Library/Homebrew/cask/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def refresh
def timestamped_versions(caskroom_path: self.caskroom_path)
relative_paths = Pathname.glob(metadata_timestamped_path(
version: "*", timestamp: "*",
caskroom_path: caskroom_path
caskroom_path:
))
.map { |p| p.relative_path_from(p.parent.parent) }
# Sorbet is unaware that Pathname is sortable: https://github.com/sorbet/sorbet/issues/6844
Expand Down Expand Up @@ -211,8 +211,8 @@ def caskroom_path
end

def outdated?(greedy: false, greedy_latest: false, greedy_auto_updates: false)
!outdated_version(greedy: greedy, greedy_latest: greedy_latest,
greedy_auto_updates: greedy_auto_updates).nil?
!outdated_version(greedy:, greedy_latest:,
greedy_auto_updates:).nil?
end

def outdated_version(greedy: false, greedy_latest: false, greedy_auto_updates: false)
Expand All @@ -236,8 +236,8 @@ def outdated_version(greedy: false, greedy_latest: false, greedy_auto_updates: f
def outdated_info(greedy, verbose, json, greedy_latest, greedy_auto_updates)
return token if !verbose && !json

installed_version = outdated_version(greedy: greedy, greedy_latest: greedy_latest,
greedy_auto_updates: greedy_auto_updates).to_s
installed_version = outdated_version(greedy:, greedy_latest:,
greedy_auto_updates:).to_s

if json
{
Expand Down Expand Up @@ -351,10 +351,10 @@ def to_hash_with_variations
if @dsl.on_system_blocks_exist?
begin
MacOSVersion::SYMBOLS.keys.product(OnSystem::ARCH_OPTIONS).each do |os, arch|
bottle_tag = ::Utils::Bottles::Tag.new(system: os, arch: arch)
bottle_tag = ::Utils::Bottles::Tag.new(system: os, arch:)
next unless bottle_tag.valid_combination?

Homebrew::SimulateSystem.with os: os, arch: arch do
Homebrew::SimulateSystem.with(os:, arch:) do
refresh

to_h.each do |key, value|
Expand Down
Loading
Loading