brew/Library/Homebrew/deprecate_disable.rb

84 lines
3.0 KiB
Ruby
Raw Normal View History

rubocop: Use `Sorbet/StrictSigil` as it's better than comments - Previously I thought that comments were fine to discourage people from wasting their time trying to bump things that used `undef` that Sorbet didn't support. But RuboCop is better at this since it'll complain if the comments are unnecessary. - Suggested in https://github.com/Homebrew/brew/pull/18018#issuecomment-2283369501. - I've gone for a mixture of `rubocop:disable` for the files that can't be `typed: strict` (use of undef, required before everything else, etc) and `rubocop:todo` for everything else that should be tried to make strictly typed. There's no functional difference between the two as `rubocop:todo` is `rubocop:disable` with a different name. - And I entirely disabled the cop for the docs/ directory since `typed: strict` isn't going to gain us anything for some Markdown linting config files. - This means that now it's easier to track what needs to be done rather than relying on checklists of files in our big Sorbet issue: ```shell $ git grep 'typed: true # rubocop:todo Sorbet/StrictSigil' | wc -l 268 ``` - And this is confirmed working for new files: ```shell $ git status On branch use-rubocop-for-sorbet-strict-sigils Untracked files: (use "git add <file>..." to include in what will be committed) Library/Homebrew/bad.rb Library/Homebrew/good.rb nothing added to commit but untracked files present (use "git add" to track) $ brew style Offenses: bad.rb:1:1: C: Sorbet/StrictSigil: Sorbet sigil should be at least strict got true. ^^^^^^^^^^^^^ 1340 files inspected, 1 offense detected ```
2024-08-12 10:30:59 +01:00
# typed: true # rubocop:todo Sorbet/StrictSigil
# frozen_string_literal: true
# Helper module for handling `disable!` and `deprecate!`.
# @api internal
module DeprecateDisable
module_function
FORMULA_DEPRECATE_DISABLE_REASONS = {
does_not_build: "does not build",
no_license: "has no license",
repo_archived: "has an archived upstream repository",
repo_removed: "has a removed upstream repository",
unmaintained: "is not maintained upstream",
unsupported: "is not supported upstream",
deprecated_upstream: "is deprecated upstream",
versioned_formula: "is a versioned formula",
2022-06-28 10:09:59 +01:00
checksum_mismatch: "was built with an initially released source file that had " \
"a different checksum than the current one. " \
"Upstream's repository might have been compromised. " \
"We can re-package this once upstream has confirmed that they retagged their release",
}.freeze
CASK_DEPRECATE_DISABLE_REASONS = {
discontinued: "is discontinued upstream",
moved_to_mas: "is now exclusively distributed on the Mac App Store",
no_longer_available: "is no longer available upstream",
no_longer_meets_criteria: "no longer meets the criteria for acceptable casks",
unmaintained: "is not maintained upstream",
2024-04-02 11:27:02 -04:00
unsigned: "is unsigned or does not meet signature requirements",
}.freeze
# One year when << or >> to Date.today.
REMOVE_DISABLED_TIME_WINDOW = 12
REMOVE_DISABLED_BEFORE = (Date.today << REMOVE_DISABLED_TIME_WINDOW).freeze
def type(formula_or_cask)
return :deprecated if formula_or_cask.deprecated?
2023-12-16 20:08:42 -05:00
:disabled if formula_or_cask.disabled?
end
def message(formula_or_cask)
return if type(formula_or_cask).blank?
reason = if formula_or_cask.deprecated?
formula_or_cask.deprecation_reason
elsif formula_or_cask.disabled?
formula_or_cask.disable_reason
end
reason = if formula_or_cask.is_a?(Formula) && FORMULA_DEPRECATE_DISABLE_REASONS.key?(reason)
FORMULA_DEPRECATE_DISABLE_REASONS[reason]
elsif formula_or_cask.is_a?(Cask::Cask) && CASK_DEPRECATE_DISABLE_REASONS.key?(reason)
CASK_DEPRECATE_DISABLE_REASONS[reason]
else
reason
end
message = if reason.present?
"#{type(formula_or_cask)} because it #{reason}!"
else
"#{type(formula_or_cask)}!"
end
disable_date = formula_or_cask.disable_date
if !disable_date && formula_or_cask.deprecation_date
disable_date = formula_or_cask.deprecation_date >> REMOVE_DISABLED_TIME_WINDOW
end
message = "#{message} It will be disabled on #{disable_date}." if disable_date
message
end
def to_reason_string_or_symbol(string, type:)
2023-12-04 14:11:31 -05:00
if (type == :formula && FORMULA_DEPRECATE_DISABLE_REASONS.key?(string&.to_sym)) ||
(type == :cask && CASK_DEPRECATE_DISABLE_REASONS.key?(string&.to_sym))
return string.to_sym
end
string
end
end