Merge pull request #18214 from Homebrew/audit-result-keyword

This commit is contained in:
Carlo Cabrera 2024-09-02 16:14:30 +08:00 committed by GitHub
commit cd5cf4e2c8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 26 additions and 9 deletions

View File

@ -2863,14 +2863,21 @@ class Formula
# @api public # @api public
sig { sig {
params( params(
paths: T.any(T::Enumerable[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)), before: T.nilable(T.any(Pathname, Regexp, String)),
after: T.nilable(T.any(Pathname, String, Symbol)), after: T.nilable(T.any(Pathname, String, Symbol)),
audit_result: T::Boolean, old_audit_result: T.nilable(T::Boolean),
block: T.nilable(T.proc.params(s: StringInreplaceExtension).void), audit_result: T::Boolean,
block: T.nilable(T.proc.params(s: StringInreplaceExtension).void),
).void ).void
} }
def inreplace(paths, before = nil, after = nil, audit_result = true, &block) # rubocop:disable Style/OptionalBooleanParameter def inreplace(paths, before = nil, after = nil, old_audit_result = nil, audit_result: true, &block)
# NOTE: must check for `#nil?` and not `#blank?`, or else `old_audit_result = false` will not call `odeprecated`.
unless old_audit_result.nil?
# odeprecated "inreplace(paths, before, after, #{old_audit_result})",
# "inreplace(paths, before, after, audit_result: #{old_audit_result})"
audit_result = old_audit_result
end
Utils::Inreplace.inreplace(paths, before, after, audit_result:, &block) Utils::Inreplace.inreplace(paths, before, after, audit_result:, &block)
rescue Utils::Inreplace::Error => e rescue Utils::Inreplace::Error => e
onoe e.to_s onoe e.to_s

View File

@ -29,10 +29,20 @@ class StringInreplaceExtension
# #
# @api public # @api public
sig { sig {
params(before: T.any(Pathname, Regexp, String), after: T.any(Pathname, String), audit_result: T::Boolean) params(
.returns(T.nilable(String)) before: T.any(Pathname, Regexp, String),
after: T.any(Pathname, String),
old_audit_result: T.nilable(T::Boolean),
audit_result: T::Boolean,
).returns(T.nilable(String))
} }
def gsub!(before, after, audit_result = true) # rubocop:disable Style/OptionalBooleanParameter def gsub!(before, after, old_audit_result = nil, audit_result: true)
# NOTE: must check for `#nil?` and not `#blank?`, or else `old_audit_result = false` will not call `odeprecated`.
unless old_audit_result.nil?
# odeprecated "gsub!(before, after, #{old_audit_result})",
# "gsub!(before, after, audit_result: #{old_audit_result})"
audit_result = old_audit_result
end
before = before.to_s if before.is_a?(Pathname) before = before.to_s if before.is_a?(Pathname)
result = inreplace_string.gsub!(before, after.to_s) result = inreplace_string.gsub!(before, after.to_s)
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?