rubocops/cask: Ensure ordering of all the on_#{arch,system} blocks
- Complaining about only `on_arm` and `on_intel` was too restrictive
since casks can have many `on_system` blocks (`on_#{arch}` and
`on_#{os}`).
- We're a bit of the way there, anyway. Still doesn't support stanza
ordering within blocks, but that's for another time (there's a
separate issue that's been open for a while - 14017).
This commit is contained in:
parent
b484a29006
commit
d97ed0a7c2
@ -5,9 +5,11 @@ module RuboCop
|
||||
module Cask
|
||||
# Constants available globally for use in all cask cops.
|
||||
module Constants
|
||||
ON_SYSTEM_METHODS = [:arm, :intel, *MacOSVersions::SYMBOLS.keys].map { |option| :"on_#{option}" }.freeze
|
||||
|
||||
STANZA_GROUPS = [
|
||||
[:arch, :on_arch_conditional],
|
||||
[:on_arm, :on_intel],
|
||||
ON_SYSTEM_METHODS,
|
||||
[:version, :sha256],
|
||||
[:language],
|
||||
[:url, :appcast, :name, :desc, :homepage],
|
||||
@ -56,8 +58,6 @@ module RuboCop
|
||||
end.freeze
|
||||
|
||||
STANZA_ORDER = STANZA_GROUPS.flatten.freeze
|
||||
|
||||
ON_SYSTEM_METHODS = [:arm, :intel, *MacOSVersions::SYMBOLS.keys].map { |option| :"on_#{option}" }.freeze
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -535,4 +535,121 @@ describe RuboCop::Cop::Cask::StanzaOrder do
|
||||
include_examples "reports offenses"
|
||||
include_examples "autocorrects source"
|
||||
end
|
||||
|
||||
# TODO: detect out-of-order stanzas in nested expressions
|
||||
context "when the on_arch and on_os stanzas are nested" do
|
||||
let(:source) do
|
||||
<<~CASK
|
||||
cask 'foo' do
|
||||
on_arm do
|
||||
url "https://foo.brew.sh/foo-arm-all.zip"
|
||||
sha256 :no_check
|
||||
version :latest
|
||||
end
|
||||
|
||||
on_intel do
|
||||
on_ventura do
|
||||
url "https://foo.brew.sh/foo-intel-ventura.zip"
|
||||
sha256 :no_check
|
||||
end
|
||||
on_mojave do
|
||||
url "https://foo.brew.sh/foo-intel-mojave.zip"
|
||||
sha256 :no_check
|
||||
end
|
||||
on_catalina do
|
||||
url "https://foo.brew.sh/foo-intel-catalina.zip"
|
||||
sha256 :no_check
|
||||
end
|
||||
on_big_sur do
|
||||
url "https://foo.brew.sh/foo-intel-big-sur.zip"
|
||||
sha256 :no_check
|
||||
end
|
||||
|
||||
version :latest
|
||||
end
|
||||
|
||||
name "Foo"
|
||||
end
|
||||
CASK
|
||||
end
|
||||
|
||||
include_examples "does not report any offenses"
|
||||
end
|
||||
|
||||
context "when the on_os stanzas are out of order" do
|
||||
let(:source) do
|
||||
<<~CASK
|
||||
cask "foo" do
|
||||
on_ventura do
|
||||
url "https://foo.brew.sh/foo-ventura.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"
|
||||
sha256 :no_check
|
||||
end
|
||||
on_big_sur do
|
||||
url "https://foo.brew.sh/foo-big-sur.zip"
|
||||
sha256 :no_check
|
||||
end
|
||||
|
||||
name "Foo"
|
||||
end
|
||||
CASK
|
||||
end
|
||||
|
||||
let(:expected_offenses) do
|
||||
[{
|
||||
message: "`on_catalina` stanza out of order",
|
||||
severity: :convention,
|
||||
line: 6,
|
||||
column: 2,
|
||||
source: "on_catalina do\n url \"https://foo.brew.sh/foo-catalina.zip\"\n sha256 :no_check\n end",
|
||||
}, {
|
||||
message: "`on_mojave` stanza out of order",
|
||||
severity: :convention,
|
||||
line: 10,
|
||||
column: 2,
|
||||
source: "on_mojave do\n url \"https://foo.brew.sh/foo-mojave.zip\"\n sha256 :no_check\n end",
|
||||
}, {
|
||||
message: "`on_big_sur` stanza out of order",
|
||||
severity: :convention,
|
||||
line: 14,
|
||||
column: 2,
|
||||
source: "on_big_sur do\n url \"https://foo.brew.sh/foo-big-sur.zip\"\n sha256 :no_check\n end",
|
||||
}]
|
||||
end
|
||||
|
||||
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"
|
||||
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"
|
||||
sha256 :no_check
|
||||
end
|
||||
|
||||
name "Foo"
|
||||
end
|
||||
CASK
|
||||
end
|
||||
|
||||
include_examples "reports offenses"
|
||||
include_examples "autocorrects source"
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user