Skip to content

Commit

Permalink
Merge pull request #18214 from Homebrew/audit-result-keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
carlocab authored Sep 2, 2024
2 parents cbc39e3 + c73d08c commit cd5cf4e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
19 changes: 13 additions & 6 deletions Library/Homebrew/formula.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2863,14 +2863,21 @@ def install; end
# @api public
sig {
params(
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,
block: T.nilable(T.proc.params(s: StringInreplaceExtension).void),
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)),
old_audit_result: T.nilable(T::Boolean),
audit_result: T::Boolean,
block: T.nilable(T.proc.params(s: StringInreplaceExtension).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)
rescue Utils::Inreplace::Error => e
onoe e.to_s
Expand Down
16 changes: 13 additions & 3 deletions Library/Homebrew/utils/string_inreplace_extension.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,20 @@ def sub!(before, after)
#
# @api public
sig {
params(before: T.any(Pathname, Regexp, String), after: T.any(Pathname, String), audit_result: T::Boolean)
.returns(T.nilable(String))
params(
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)
result = inreplace_string.gsub!(before, after.to_s)
errors << "expected replacement of #{before.inspect} with #{after.inspect}" if audit_result && result.nil?
Expand Down

0 comments on commit cd5cf4e

Please sign in to comment.