formula: restore using replacement from disable!#21678
Conversation
Previous behavior before #21644 This allows providing a single `replacement_formula:` on the `disable!` stanza rather than duplicating it in both `disable!` and `deprecate!`.
There was a problem hiding this comment.
Pull request overview
Updates Formula deprecation/disable metadata handling so disable! can supply replacement information used for deprecation (restoring behavior from before #21644), while also simplifying some Sorbet annotations for readability.
Changes:
- Populate deprecation fields from
disable!whendisable!is in the future anddeprecate!hasn’t set them. - Refactor
deprecate!/disable!to reduceT.mustusage and streamlineT.letplacement. - Adjust interaction between
deprecate!anddisable!when both stanzas are present.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| replacement_formula ||= replacement | ||
| replacement_cask ||= replacement |
There was a problem hiding this comment.
Same as in deprecate!: replacement_formula ||= replacement/replacement_cask ||= replacement won’t remap when replacement_formula/replacement_cask is "". Because blanks are treated as absent via .presence in the argument validation (and later when setting @disable_replacement_*), consider using .presence || replacement for the remap to avoid blank replacements being stored/propagated.
| replacement_formula ||= replacement | |
| replacement_cask ||= replacement | |
| replacement_formula = replacement_formula.presence || replacement | |
| replacement_cask = replacement_cask.presence || replacement |
| # Use `disable!` information if not set in `deprecate!` | ||
| @deprecation_reason ||= because | ||
| @deprecation_replacement_formula ||= replacement_formula | ||
| @deprecation_replacement_cask ||= replacement_cask | ||
| @deprecated ||= true |
There was a problem hiding this comment.
The new disable!→deprecation propagation (@deprecation_* ||= ...) changes behavior when both deprecate! and a future disable! are present (e.g., deprecate has no replacement but disable does). There are existing specs for date ordering, but none cover this replacement propagation; please add an RSpec example asserting deprecation_replacement_formula/cask are populated from disable! when missing from deprecate! (in both stanza orders).
| if replacement | ||
| replacement_formula ||= replacement | ||
| replacement_cask ||= replacement |
There was a problem hiding this comment.
replacement_formula ||= replacement/replacement_cask ||= replacement doesn't treat blank strings as absent, but earlier validation uses .presence (so a blank value is effectively treated like nil). This can leave replacement_formula as "" and then set @deprecation_replacement_* to an empty string. Consider normalizing with .presence (and doing the legacy replacement remap using .presence || replacement) before using these values, so blanks don’t propagate into deprecation metadata/API output.
| @deprecation_reason = because if because | ||
| @deprecation_replacement_formula = replacement_formula if replacement_formula | ||
| @deprecation_replacement_cask = replacement_cask if replacement_cask |
There was a problem hiding this comment.
In the deprecated branch, @deprecation_replacement_formula = replacement_formula if replacement_formula will also accept an empty string (truthy) and persist it as the replacement. To match the .presence semantics used elsewhere in this method, consider assigning only replacement_formula.presence/replacement_cask.presence (or normalizing once up-front) so blank values don’t override or block fallback behavior.
| @deprecation_reason = because if because | |
| @deprecation_replacement_formula = replacement_formula if replacement_formula | |
| @deprecation_replacement_cask = replacement_cask if replacement_cask | |
| if (present_because = because.presence) | |
| @deprecation_reason = present_because | |
| end | |
| if (present_replacement_formula = replacement_formula.presence) | |
| @deprecation_replacement_formula = present_replacement_formula | |
| end | |
| if (present_replacement_cask = replacement_cask.presence) | |
| @deprecation_replacement_cask = present_replacement_cask | |
| end |
MikeMcQuaid
left a comment
There was a problem hiding this comment.
Thanks! A comment from me and Copilot ones look worth considering.
Self-merge when happy.
| if replacement | ||
| replacement_formula ||= replacement | ||
| replacement_cask ||= replacement | ||
| odeprecated( |
There was a problem hiding this comment.
Can you add comments here and anywhere else that this odeprecated/odisabled should stay the same between releases 🙇🏻
brew lgtm(style, typechecking and tests) with your changes locally?Previous behavior before #21644
This allows providing a single
replacement_formula:on thedisable!stanza rather than duplicating it in bothdisable!anddeprecate!e.g.
Also remove some
T.mustand move someT.letto the simpler (nil) case for readability.