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

build(deps-dev): bump rubocop-performance from 1.23.1 to 1.24.0 in /Library/Homebrew #19329

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
11 changes: 10 additions & 1 deletion Library/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,10 +219,19 @@ Performance/Caller:
Performance/CaseWhenSplat:
Enabled: true

# Makes code less readable for minor performance increases.
# It can also cause type errors (e.g. `map!`).
Performance/ChainArrayAllocation:
Enabled: false

# Makes code less readable for minor performance increases.
Performance/MethodObjectAsBlock:
Enabled: false

Performance/SelectMap:
Exclude:
- "Taps/**/*"

RSpec:
Include:
- "Homebrew/test/**/*"
Expand Down Expand Up @@ -272,7 +281,7 @@ Sorbet/RedundantExtendTSig:
Enabled: true

# We make limited and intentional use of refinements.
# It's posssible this may change in the future, though we probably still do not want to ban it in taps
# It's possible this may change in the future, though we probably still do not want to ban it in taps
# and Sorbet typecheck will tell us what is and isn't a problem anyway.
# Right now, our use of refinements isn't problematic (or at least not yet).
Sorbet/Refinement:
Expand Down
7 changes: 4 additions & 3 deletions Library/Homebrew/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,10 @@ GEM
parser (>= 3.3.1.0)
rubocop-md (1.2.4)
rubocop (>= 1.45)
rubocop-performance (1.23.1)
rubocop (>= 1.48.1, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-performance (1.24.0)
lint_roller (~> 1.1)
rubocop (>= 1.72.1, < 2.0)
rubocop-ast (>= 1.38.0, < 2.0)
rubocop-rspec (3.4.0)
rubocop (~> 1.61)
rubocop-sorbet (0.8.9)
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/aliases/alias.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def initialize(name, command = nil)
@symlink = T.let(nil, T.nilable(Pathname))

@command = if command&.start_with?("!", "%")
# `drop` is not defined on `String`
# rubocop:disable Performance/ArraySemiInfiniteRangeSlice
Copy link
Member

@Bo98 Bo98 Feb 23, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't supposed to be enabled. Upstream actually states:

This cop was created due to a mistake in microbenchmark and hence is disabled by default

https://docs.rubocop.org/rubocop-performance/cops_performance.html#performancearraysemiinfiniterangeslice

Given the large amount of fixes in this PR in a version bump that is supposed to only have one extra cop, it seems like something's very broken here and cop violations here should not be trusted until we get that fixed.

command[1..]
# rubocop:enable Performance/ArraySemiInfiniteRangeSlice
elsif command
"brew #{command}"
end
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/cask/cask_loader.rb
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,10 @@ def load(config:)
cask_options[:tap] = Tap.fetch(json_cask[:tap]) if json_cask[:tap].to_s.include?("/")

user_agent = json_cask.dig(:url_specs, :user_agent)
# `drop` is not defined on `String`
# rubocop:disable Performance/ArraySemiInfiniteRangeSlice
json_cask[:url_specs][:user_agent] = user_agent[1..].to_sym if user_agent && user_agent[0] == ":"
# rubocop:enable Performance/ArraySemiInfiniteRangeSlice
if (using = json_cask.dig(:url_specs, :using))
json_cask[:url_specs][:using] = using.to_sym
end
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/cask/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,7 @@ def default
def env
@env ||= self.class.canonicalize(
Homebrew::EnvConfig.cask_opts
.select { |arg| arg.include?("=") }
.map { |arg| T.cast(arg.split("=", 2), [String, String]) }
.filter_map { |arg| T.cast(arg.split("=", 2), [String, String]) if arg.include?("=") }
.map do |(flag, value)|
key = flag.sub(/^--/, "")
# converts --language flag to :languages config key
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/cask/dsl/container.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ def initialize(nested: nil, type: nil)
end

def pairs
# `drop` is not a method on `Symbol`
# rubocop:disable Performance/ArraySemiInfiniteRangeSlice
instance_variables.to_h { |ivar| [ivar[1..].to_sym, instance_variable_get(ivar)] }.compact
# rubocop:enable Performance/ArraySemiInfiniteRangeSlice
end

def to_yaml
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/cleanup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ def cleanup_unreferenced_downloads

downloads = (cache/"downloads").children

referenced_downloads = cache_files.map { |file| file[:path] }.select(&:symlink?).map(&:resolved_path)
referenced_downloads = cache_files.map { |file| file[:path] }.filter_map { _1.resolved_path if _1.symlink? }

(downloads - referenced_downloads).each do |download|
if self.class.incomplete?(download)
Expand Down
6 changes: 3 additions & 3 deletions Library/Homebrew/cli/args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ def set_arg(name, value)
@table[name] = value
end

sig { override.params(_blk: T.nilable(T.proc.params(x: T.untyped).void)).returns(T.untyped) }
def tap(&_blk)
return super if block_given? # Object#tap
sig { override.params(blk: T.nilable(T.proc.params(x: T.untyped).void)).returns(T.untyped) }
def tap(&blk)
return super if blk # Object#tap

@table[:tap]
end
Expand Down
4 changes: 2 additions & 2 deletions Library/Homebrew/cmd/update-report.rb
Original file line number Diff line number Diff line change
Expand Up @@ -769,8 +769,8 @@ def dump(auto_update: false)
dump_deleted_formula_report
dump_deleted_cask_report

outdated_formulae = Formula.installed.select(&:outdated?).map(&:name)
outdated_casks = Cask::Caskroom.casks.select(&:outdated?).map(&:token)
outdated_formulae = Formula.installed.filter_map { _1.name if _1.outdated? }
outdated_casks = Cask::Caskroom.casks.filter_map { _1.token if _1.outdated? }
unless auto_update
output_dump_formula_or_cask_report "Outdated Formulae", outdated_formulae
output_dump_formula_or_cask_report "Outdated Casks", outdated_casks
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/commands.rb
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,7 @@ def self.find_internal_commands(path)

def self.external_commands
tap_cmd_directories.flat_map do |path|
find_commands(path).select(&:executable?)
.map { basename_without_extension(_1) }
find_commands(path).filter_map { basename_without_extension(_1) if _1.executable? }
.map { |p| p.to_s.delete_prefix("brew-").strip }
end.map(&:to_s)
.sort
Expand Down
8 changes: 4 additions & 4 deletions Library/Homebrew/dev-cmd/bottle.rb
Original file line number Diff line number Diff line change
Expand Up @@ -656,11 +656,11 @@ def bottle_formula(formula)
keg_prefix = "#{keg}/"
path_exec_files = [keg/"bin", keg/"sbin"].select(&:exist?)
.flat_map(&:children)
.select(&:executable?)
.map { |path| path.to_s.delete_prefix(keg_prefix) }
.filter_map do |path|
path.to_s.delete_prefix(keg_prefix) if path.executable?
end
all_files = keg.find
.select(&:file?)
.map { |path| path.to_s.delete_prefix(keg_prefix) }
.filter_map { |path| path.to_s.delete_prefix(keg_prefix) if path.file? }
installed_size = keg.disk_usage
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/dev-cmd/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def run

autobump_lists[tap] ||= begin
autobump_path = tap.path/".github/autobump.txt"
autobump_path.exist? ? autobump_path.readlines.map(&:strip) : []
autobump_path.exist? ? autobump_path.each_line.map(&:strip) : []
end

name = formula_or_cask.respond_to?(:token) ? formula_or_cask.token : formula_or_cask.name
Expand Down
11 changes: 6 additions & 5 deletions Library/Homebrew/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,11 @@

files = Dir.chdir(dir) do
(Dir.glob(pattern) - Dir.glob(allow_list))
.select { |f| File.file?(f) && !File.symlink?(f) }
.map do |f|
f.sub!(%r{/.*}, "/*") unless @verbose
File.join(dir, f)
.filter_map do |f|
if File.file?(f) && !File.symlink?(f)
f.sub!(%r{/.*}, "/*") unless @verbose
File.join(dir, f)

Check warning on line 193 in Library/Homebrew/diagnostic.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/diagnostic.rb#L193

Added line #L193 was not covered by tests
end
end
.sort.uniq
end
Expand Down Expand Up @@ -564,7 +565,7 @@

def check_deprecated_official_taps
tapped_deprecated_taps =
Tap.select(&:official?).map(&:repository) & DEPRECATED_OFFICIAL_TAPS
Tap.filter_map { _1.repository if _1.official? } & DEPRECATED_OFFICIAL_TAPS
return if tapped_deprecated_taps.empty?

<<~EOS
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/download_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def chdir(&block)
# @api public
sig { returns(Time) }
def source_modified_time
Pathname.pwd.to_enum(:find).select(&:file?).map(&:mtime).max
Pathname.pwd.to_enum(:find).filter_map { _1.mtime if _1.file? }.max
end

# Remove {#cached_location} and any other files associated with the resource
Expand Down
7 changes: 5 additions & 2 deletions Library/Homebrew/exceptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -712,7 +712,7 @@

sig { returns(String) }
def stderr
Array(output).select { |type,| type == :stderr }.map(&:last).join
Array(output).filter_map { _1.last if _1.first == :stderr }.join
end
end

Expand Down Expand Up @@ -785,9 +785,12 @@
# Raised when one or more formulae have cyclic dependencies.
class CyclicDependencyError < RuntimeError
def initialize(strongly_connected_components)
sentences = strongly_connected_components.filter_map do |packages|

Check warning on line 788 in Library/Homebrew/exceptions.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/exceptions.rb#L788

Added line #L788 was not covered by tests
packages.to_sentence if packages.count > 1
end.join("\n ")
super <<~EOS
The following packages contain cyclic dependencies:
#{strongly_connected_components.select { |packages| packages.count > 1 }.map(&:to_sentence).join("\n ")}
#{sentences}
EOS
end
end
3 changes: 2 additions & 1 deletion Library/Homebrew/extend/os/linux/hardware/cpu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@
# Compatibility with Mac method, which returns lowercase symbols
# instead of strings.
def features
@features ||= flags[1..].map(&:intern)
@features ||= flags.drop(1)
@features.map!(&:intern)

Check warning on line 137 in Library/Homebrew/extend/os/linux/hardware/cpu.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/extend/os/linux/hardware/cpu.rb#L136-L137

Added lines #L136 - L137 were not covered by tests
end

%w[aes altivec avx avx2 lm ssse3 sse4_2].each do |flag|
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/extend/os/mac/diagnostic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -413,8 +413,7 @@ def check_for_multiple_volumes
end

def check_deprecated_caskroom_taps
tapped_caskroom_taps = Tap.select { |t| t.user == "caskroom" || t.name == "phinze/cask" }
.map(&:name)
tapped_caskroom_taps = Tap.filter_map { |t| t.name if t.user == "caskroom" || t.name == "phinze/cask" }
return if tapped_caskroom_taps.empty?

<<~EOS
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3165,7 +3165,7 @@
elsif pinned? && keg == Keg.new(@pin.path.resolved_path)
opoo "Skipping (old) #{keg} due to it being pinned" unless quiet
elsif (keepme = keg/".keepme") && keepme.exist? && keepme.readable? &&
(keepme_refs = keepme.readlines.map(&:strip).select { |ref| Pathname(ref).exist? }.presence)
(keepme_refs = keepme.each_line.map(&:strip).select { |ref| Pathname(ref).exist? }.presence)

Check warning on line 3168 in Library/Homebrew/formula.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/formula.rb#L3168

Added line #L3168 was not covered by tests
opoo "Skipping #{keg} as it needed by #{keepme_refs.join(", ")}" unless quiet
else
eligible_for_cleanup << keg
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/formula_cellar_checks.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,7 @@ def check_python_packages(lib, deps)
return unless lib.directory?

lib_subdirs = lib.children
.select(&:directory?)
.map(&:basename)
.filter_map { _1.basename if _1.directory? }

pythons = lib_subdirs.filter_map do |p|
match = p.to_s.match(/^python(\d+\.\d+)$/)
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/formulary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,10 @@ def self.class_s(name)
end

def self.convert_to_string_or_symbol(string)
# `drop` is not defined on `String`
# rubocop:disable Performance/ArraySemiInfiniteRangeSlice
return string[1..].to_sym if string.start_with?(":")
# rubocop:enable Performance/ArraySemiInfiniteRangeSlice

string
end
Expand Down
3 changes: 1 addition & 2 deletions Library/Homebrew/github_runner_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,7 @@ def initialize(testing_formulae, deleted_formulae, all_supported:, dependent_mat

sig { returns(T::Array[RunnerSpecHash]) }
def active_runner_specs_hash
runners.select(&:active)
.map(&:spec)
runners.filter_map { _1.spec if _1.active }
.map(&:to_h)
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/installed_dependents.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module InstalledDependents
#
# For efficiency, we don't bother trying to get complete data.
def find_some_installed_dependents(kegs, casks: [])
keg_names = kegs.select(&:optlinked?).map(&:name)
keg_names = kegs.filter_map { _1.name if _1.optlinked? }
keg_formulae = []
kegs_by_source = kegs.group_by do |keg|
# First, attempt to resolve the keg to a formula
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/language/node.rb
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ def node_shebang_rewrite_info(node_path)

sig { params(formula: Formula).returns(Utils::Shebang::RewriteInfo) }
def detected_node_shebang(formula = T.cast(self, Formula))
node_deps = formula.deps.select(&:required?).map(&:name).grep(/^node(@.+)?$/)
node_deps = formula.deps.filter_map { _1.name if _1.required? }.grep(/^node(@.+)?$/)
raise ShebangDetectionError.new("Node", "formula does not depend on Node") if node_deps.empty?
raise ShebangDetectionError.new("Node", "formula has multiple Node dependencies") if node_deps.length > 1

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/language/python.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ def detected_python_shebang(formula = T.cast(self, Formula), use_python_from_pat
python_path = if use_python_from_path
"/usr/bin/env python3"
else
python_deps = formula.deps.select(&:required?).map(&:name).grep(/^python(@.+)?$/)
python_deps = formula.deps.filter_map { _1.name if _1.required? }.grep(/^python(@.+)?$/)
raise ShebangDetectionError.new("Python", "formula does not depend on Python") if python_deps.empty?
if python_deps.length > 1
raise ShebangDetectionError.new("Python", "formula has multiple Python dependencies")
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/os/linux/ld.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def self.library_paths(conf_path = Pathname(sysconfdir)/"ld.so.conf")
paths = Set.new
directory = conf_file.realpath.dirname

conf_file.readlines.each do |line|
conf_file.each_line do |line|
# Remove comments and leading/trailing whitespace
line.strip!
line.sub!(/\s*#.*$/, "")
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/requirements/macos_requirement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def initialize(tags = [], comparator: ">=")

# Array of versions: remove the bad ones and try again.
if tags.first.respond_to?(:reject)
tags = [tags.first.reject { |s| s == e.version }, tags[1..]]
tags = [tags.first.reject { |s| s == e.version }, tags.drop(1)]
retry
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/rubocops/cask/array_alphabetization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def on_send(node)
return unless [:zap, :uninstall].include?(node.method_name)

node.each_descendant(:pair).each do |pair|
symbols = pair.children.select(&:sym_type?).map(&:value)
symbols = pair.children.filter_map { _1.value if _1.sym_type? }
next if symbols.intersect?([:signal, :script, :early_script, :args, :input])

pair.each_descendant(:array).each do |array|
Expand Down
7 changes: 2 additions & 5 deletions Library/Homebrew/rubocops/cask/ast/cask_block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,7 @@ def stanzas

@stanzas ||= T.let(
block_body.each_node
.select(&:stanza?)
.select(&is_stanza)
.map { |node| Stanza.new(node, comments) },
.filter_map { |node| Stanza.new(node, comments) if node.stanza? && is_stanza.call(node) },
T.nilable(T::Array[Stanza]),
)
end
Expand Down Expand Up @@ -67,8 +65,7 @@ def stanzas
return [] unless cask_body

@stanzas ||= cask_body.each_node
.select(&:stanza?)
.map { |node| Stanza.new(node, comments) }
.filter_map { |node| Stanza.new(node, comments) if node.stanza? }
end

sig { returns(T::Array[Stanza]) }
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/rubocops/cask/shared_filelist_glob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def on_send(node)
return if node.method_name != :zap

node.each_descendant(:pair).each do |pair|
symbols = pair.children.select(&:sym_type?).map(&:value)
symbols = pair.children.filter_map { _1.value if _1.sym_type? }
next unless symbols.include?(:trash)

pair.each_descendant(:array).each do |array|
Expand Down
3 changes: 3 additions & 0 deletions Library/Homebrew/rubocops/deprecate_disable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ def audit_formula(formula_nodes)

if reason_string.start_with?("it ")
problem "Do not start the reason with `it`" do |corrector|
# `drop` is not defined on `String`
# rubocop:disable Performance/ArraySemiInfiniteRangeSlice
corrector.replace(T.must(@offensive_node).source_range, "\"#{reason_string[3..]}\"")
# rubocop:enable Performance/ArraySemiInfiniteRangeSlice
end
end

Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/rubocops/lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -934,7 +934,7 @@ def audit_formula(formula_nodes)
params = parameters(method)
next unless node_equals?(params[0], "make")

params[1..].each do |arg|
params.drop(1).each do |arg|
next unless regex_match_group(arg, /^(checks?|tests?)$/)

offending_node(method)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/rubocops/livecheck.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def audit_formula(formula_nodes)

offending_node(livecheck_regex_node)
problem "The `regex` call should always use parentheses." do |corrector|
pattern = livecheck_regex_node.source.split[1..].join
pattern = livecheck_regex_node.source.split.drop(1).join
corrector.replace(livecheck_regex_node.source_range, "regex(#{pattern})")
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def audit_formula(formula_nodes)
if (dep = node.arguments.first).hash_type?
dep_types = dep.values.first
dep_types = dep_types.array_type? ? dep_types.values : [dep_types]
dep.keys.first.str_content if dep_types.select(&:sym_type?).map(&:value).include?(:build)
dep.keys.first.str_content if dep_types.filter_map { _1.value if _1.sym_type? }.include?(:build)
else
dep.str_content
end
Expand Down
Loading
Loading