Merge pull request #14976 from issyl0/rubocop-cask-on-arch-block-order
rubocops/cask: Enforce the order of `on_#{arch}` blocks
This commit is contained in:
commit
039a434936
@ -5,9 +5,17 @@ module RuboCop
|
|||||||
module Cask
|
module Cask
|
||||||
# Constants available globally for use in all cask cops.
|
# Constants available globally for use in all cask cops.
|
||||||
module Constants
|
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 = [
|
STANZA_GROUPS = [
|
||||||
[:arch, :on_arch_conditional],
|
[:arch, :on_arch_conditional],
|
||||||
[:version, :sha256],
|
[:version, :sha256],
|
||||||
|
ON_SYSTEM_METHODS_STANZA_ORDER,
|
||||||
[:language],
|
[:language],
|
||||||
[:url, :appcast, :name, :desc, :homepage],
|
[:url, :appcast, :name, :desc, :homepage],
|
||||||
[:livecheck],
|
[:livecheck],
|
||||||
@ -56,8 +64,6 @@ module RuboCop
|
|||||||
end.freeze
|
end.freeze
|
||||||
|
|
||||||
STANZA_ORDER = STANZA_GROUPS.flatten.freeze
|
STANZA_ORDER = STANZA_GROUPS.flatten.freeze
|
||||||
|
|
||||||
ON_SYSTEM_METHODS = [:arm, :intel, *MacOSVersions::SYMBOLS.keys].map { |option| :"on_#{option}" }.freeze
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -474,4 +474,182 @@ describe RuboCop::Cop::Cask::StanzaOrder do
|
|||||||
|
|
||||||
include_examples "does not report any offenses"
|
include_examples "does not report any offenses"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "when `on_arch` blocks are out of order" do
|
||||||
|
let(:source) do
|
||||||
|
<<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
on_intel do
|
||||||
|
url "https://foo.brew.sh/foo-intel.zip"
|
||||||
|
sha256 :no_check
|
||||||
|
version :latest
|
||||||
|
end
|
||||||
|
|
||||||
|
on_arm do
|
||||||
|
url "https://foo.brew.sh/foo-arm.zip"
|
||||||
|
sha256 :no_check
|
||||||
|
version :latest
|
||||||
|
end
|
||||||
|
|
||||||
|
name "Foo"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:expected_offenses) do
|
||||||
|
[{
|
||||||
|
message: "`on_intel` stanza out of order",
|
||||||
|
severity: :convention,
|
||||||
|
line: 2,
|
||||||
|
column: 2,
|
||||||
|
source: "on_intel do\n url \"https://foo.brew.sh/foo-intel.zip\"\n sha256 :no_check\n version :latest\n end", # rubocop:disable Layout/LineLength
|
||||||
|
}, {
|
||||||
|
message: "`on_arm` stanza out of order",
|
||||||
|
severity: :convention,
|
||||||
|
line: 8,
|
||||||
|
column: 2,
|
||||||
|
source: "on_arm do\n url \"https://foo.brew.sh/foo-arm.zip\"\n sha256 :no_check\n version :latest\n end", # rubocop:disable Layout/LineLength
|
||||||
|
}]
|
||||||
|
end
|
||||||
|
|
||||||
|
let(:correct_source) do
|
||||||
|
<<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
on_arm do
|
||||||
|
url "https://foo.brew.sh/foo-arm.zip"
|
||||||
|
sha256 :no_check
|
||||||
|
version :latest
|
||||||
|
end
|
||||||
|
|
||||||
|
on_intel do
|
||||||
|
url "https://foo.brew.sh/foo-intel.zip"
|
||||||
|
sha256 :no_check
|
||||||
|
version :latest
|
||||||
|
end
|
||||||
|
|
||||||
|
name "Foo"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
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_ventura` stanza out of order",
|
||||||
|
severity: :convention,
|
||||||
|
line: 2,
|
||||||
|
column: 2,
|
||||||
|
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,
|
||||||
|
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_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_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
|
||||||
|
|
||||||
|
name "Foo"
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
include_examples "reports offenses"
|
||||||
|
include_examples "autocorrects source"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -2,9 +2,6 @@ cask "with-depends-on-macos-failure" do
|
|||||||
version "1.2.3"
|
version "1.2.3"
|
||||||
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
sha256 "67cdb8a02803ef37fdbf7e0be205863172e41a561ca446cd84f0d7ab35a99d94"
|
||||||
|
|
||||||
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
|
|
||||||
homepage "https://brew.sh/with-depends-on-macos-failure"
|
|
||||||
|
|
||||||
# guarantee a mismatched release
|
# guarantee a mismatched release
|
||||||
on_mojave :or_older do
|
on_mojave :or_older do
|
||||||
depends_on macos: :catalina
|
depends_on macos: :catalina
|
||||||
@ -16,5 +13,8 @@ cask "with-depends-on-macos-failure" do
|
|||||||
depends_on macos: :catalina
|
depends_on macos: :catalina
|
||||||
end
|
end
|
||||||
|
|
||||||
|
url "file://#{TEST_FIXTURE_DIR}/cask/caffeine.zip"
|
||||||
|
homepage "https://brew.sh/with-depends-on-macos-failure"
|
||||||
|
|
||||||
app "Caffeine.app"
|
app "Caffeine.app"
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user