cask/audits: on_#{os_version} stanza order is oldest => newest

- This, ie Mojave first, is more common in real Casks than the
  alternative of newest to oldest ie Ventura first.
- Doing it this way reduces the number of offenses from ~500 to ~200.
This commit is contained in:
Issy Long 2023-03-16 23:49:32 +00:00
parent d97ed0a7c2
commit 48b1279b00
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
2 changed files with 17 additions and 12 deletions

View File

@ -6,10 +6,15 @@ module RuboCop
# Constants available globally for use in all cask cops.
module Constants
ON_SYSTEM_METHODS = [:arm, :intel, *MacOSVersions::SYMBOLS.keys].map { |option| :"on_#{option}" }.freeze
ON_SYSTEM_METHODS_STANZA_ORDER = [
:arm,
:intel,
*MacOSVersions::SYMBOLS.reverse_each.to_h.keys, # Oldest OS blocks first since that's more common in Casks.
].map { |option, _| :"on_#{option}" }.freeze
STANZA_GROUPS = [
[:arch, :on_arch_conditional],
ON_SYSTEM_METHODS,
ON_SYSTEM_METHODS_STANZA_ORDER,
[:version, :sha256],
[:language],
[:url, :appcast, :name, :desc, :homepage],

View File

@ -604,11 +604,11 @@ describe RuboCop::Cop::Cask::StanzaOrder do
let(:expected_offenses) do
[{
message: "`on_catalina` stanza out of order",
message: "`on_ventura` stanza out of order",
severity: :convention,
line: 6,
line: 2,
column: 2,
source: "on_catalina do\n url \"https://foo.brew.sh/foo-catalina.zip\"\n sha256 :no_check\n end",
source: "on_ventura do\n url \"https://foo.brew.sh/foo-ventura.zip\"\n sha256 :no_check\n end",
}, {
message: "`on_mojave` stanza out of order",
severity: :convention,
@ -627,20 +627,20 @@ describe RuboCop::Cop::Cask::StanzaOrder do
let(:correct_source) do
<<~CASK
cask "foo" do
on_ventura do
url "https://foo.brew.sh/foo-ventura.zip"
sha256 :no_check
end
on_big_sur do
url "https://foo.brew.sh/foo-big-sur.zip"
on_mojave do
url "https://foo.brew.sh/foo-mojave.zip"
sha256 :no_check
end
on_catalina do
url "https://foo.brew.sh/foo-catalina.zip"
sha256 :no_check
end
on_mojave do
url "https://foo.brew.sh/foo-mojave.zip"
on_big_sur do
url "https://foo.brew.sh/foo-big-sur.zip"
sha256 :no_check
end
on_ventura do
url "https://foo.brew.sh/foo-ventura.zip"
sha256 :no_check
end