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: default hash syntax. #16848

Merged
merged 2 commits into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 0 additions & 3 deletions Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,6 @@ Style/HashAsLastArrayItem:
- "/**/Formula/**/*.rb"
- "**/Formula/**/*.rb"

Style/HashSyntax:
EnforcedShorthandSyntax: either

Style/InverseMethods:
InverseMethods:
:blank?: :present?
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,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, freeze: true)
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 @@ -83,7 +83,7 @@ def self.all_renames
def self.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 @@ -119,7 +119,7 @@ def self.tap_git_head
def self.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
10 changes: 5 additions & 5 deletions 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 Expand Up @@ -133,14 +133,14 @@
Homebrew::Help.help cmd, remaining_args: args.remaining, usage_error: e.message
rescue SystemExit => e
onoe "Kernel.exit" if args.debug? && !e.success?
$stderr.puts Utils::Backtrace.clean(e) if args.debug?
$stderr.puts Utils::Backtrace.clean(e) if args&.debug? || ARGV.include?("--debug")
raise
rescue Interrupt
$stderr.puts # seemingly a newline is typical
exit 130
rescue BuildError => e
Utils::Analytics.report_build_error(e)
e.dump(verbose: args.verbose?)
e.dump(verbose: args&.verbose?)

if e.formula.head? || e.formula.deprecated? || e.formula.disabled?
reason = if e.formula.head?
Expand All @@ -167,7 +167,7 @@
raise if e.message.empty?

onoe e
$stderr.puts Utils::Backtrace.clean(e) if args.debug?
$stderr.puts Utils::Backtrace.clean(e) if args&.debug? || ARGV.include?("--debug")

exit 1
rescue MethodDeprecatedError => e
Expand All @@ -176,7 +176,7 @@
$stderr.puts "If reporting this issue please do so at (not Homebrew/brew or Homebrew/homebrew-core):"
$stderr.puts " #{Formatter.url(e.issues_url)}"
end
$stderr.puts Utils::Backtrace.clean(e) if args.debug?
$stderr.puts Utils::Backtrace.clean(e) if args&.debug? || ARGV.include?("--debug")
exit 1
rescue Exception => e # rubocop:disable Lint/RescueException
onoe e
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 @@ -93,7 +93,7 @@ def install
end
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 @@ -225,7 +225,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 @@ -113,15 +113,15 @@
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 @@ -133,21 +133,21 @@
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)

Check warning on line 136 in Library/Homebrew/cask/artifact/abstract_uninstall.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/artifact/abstract_uninstall.rb#L136

Added line #L136 was not covered by tests
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 @@ -511,13 +511,13 @@

# 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
5 changes: 0 additions & 5 deletions Library/Homebrew/cask/artifact/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,6 @@ def self.from_args(cask, *args)
def resolve_target(target)
super(target, base_dir: nil)
end

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)
end
MikeMcQuaid marked this conversation as resolved.
Show resolved Hide resolved
end
end
end
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 @@ -94,7 +94,7 @@
end

def to_h
{ path: path }.tap do |h|
{ path: }.tap do |h|

Check warning on line 97 in Library/Homebrew/cask/artifact/installer.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/artifact/installer.rb#L97

Added line #L97 was not covered by tests
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 @@
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 @@
same = command.run(
"/usr/bin/diff",
args: ["--recursive", "--brief", source, target],
verbose: verbose,
verbose:,
print_stdout: verbose,
).success?

Expand All @@ -76,22 +76,22 @@
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 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 @@
raise CaskError, "#{message}." unless force

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

Check warning on line 132 in Library/Homebrew/cask/artifact/moved.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/artifact/moved.rb#L132

Added line #L132 was not covered by tests
end

unless target.exist?
Expand All @@ -144,7 +144,7 @@
# 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 @@
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 @@ -66,9 +66,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 @@
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:)

Check warning on line 60 in Library/Homebrew/cask/artifact/symlinked.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/artifact/symlinked.rb#L60

Added line #L60 was not covered by tests
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:)

Check warning on line 74 in Library/Homebrew/cask/artifact/symlinked.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/artifact/symlinked.rb#L74

Added line #L74 was not covered by tests
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
12 changes: 6 additions & 6 deletions Library/Homebrew/cask/audit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
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 @@ -95,7 +95,7 @@
# 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 @@ -663,7 +663,7 @@

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:)

Check warning on line 666 in Library/Homebrew/cask/audit.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/audit.rb#L666

Added line #L666 was not covered by tests
add_error error, location: cask.url.location if error
end

Expand All @@ -678,7 +678,7 @@

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:)

Check warning on line 681 in Library/Homebrew/cask/audit.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/cask/audit.rb#L681

Added line #L681 was not covered by tests
add_error error, location: cask.url.location if error
end

Expand Down Expand Up @@ -783,7 +783,7 @@

validate_url_for_https_availability(
homepage, SharedAudits::URL_TYPE_HOMEPAGE,
user_agents: user_agents,
user_agents:,
check_content: true,
strict: strict?
)
Expand Down Expand Up @@ -843,7 +843,7 @@
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