From 8d8dac0de4072371420ad1b81cd311c084de14ef Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 1 Aug 2023 09:22:48 -0700 Subject: [PATCH 1/2] Narrow member type of inreplace paths enumerable --- Library/Homebrew/formula.rb | 2 +- Library/Homebrew/utils/inreplace.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/formula.rb b/Library/Homebrew/formula.rb index 664e282006..738000ff6f 100644 --- a/Library/Homebrew/formula.rb +++ b/Library/Homebrew/formula.rb @@ -2556,7 +2556,7 @@ class Formula # @api public sig { params( - paths: T.any(T::Enumerable[T.untyped], String, Pathname), + paths: T.any(T::Enumerable[T.any(String, Pathname)], String, Pathname), before: T.nilable(T.any(Pathname, Regexp, String)), after: T.nilable(T.any(Pathname, String, Symbol)), audit_result: T::Boolean, diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 6cb8c25729..4e81b55aa7 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -39,7 +39,7 @@ module Utils # @api public sig { params( - paths: T.any(T::Array[T.untyped], String, Pathname), + paths: T.any(T::Array[T.any(String, Pathname)], String, Pathname), before: T.nilable(T.any(Pathname, Regexp, String)), after: T.nilable(T.any(Pathname, String, Symbol)), audit_result: T::Boolean, From b26c0917c710e4b0eb1c87e2a0c3800da8f489c1 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Tue, 1 Aug 2023 09:32:42 -0700 Subject: [PATCH 2/2] Widen collection type in super call --- Library/Homebrew/utils/inreplace.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 4e81b55aa7..5f51f78169 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -39,21 +39,22 @@ module Utils # @api public sig { params( - paths: T.any(T::Array[T.any(String, Pathname)], String, Pathname), + paths: T.any(T::Enumerable[T.any(String, Pathname)], String, Pathname), before: T.nilable(T.any(Pathname, Regexp, String)), after: T.nilable(T.any(Pathname, String, Symbol)), audit_result: T::Boolean, ).void } def inreplace(paths, before = nil, after = nil, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter + paths = Array(paths) after &&= after.to_s before = before.to_s if before.is_a?(Pathname) errors = {} - errors["`paths` (first) parameter"] = ["`paths` was empty"] if paths.blank? + errors["`paths` (first) parameter"] = ["`paths` was empty"] if paths.all?(&:blank?) - Array(paths).each do |path| + paths.each do |path| str = File.binread(path) s = StringInreplaceExtension.new(str)