rubocops/cask: Casks with zero on_* blocks are still valid
This commit is contained in:
parent
5ce4966f4a
commit
dec1309140
@ -8,19 +8,22 @@ module RuboCop
|
|||||||
extend T::Sig
|
extend T::Sig
|
||||||
include CaskHelp
|
include CaskHelp
|
||||||
|
|
||||||
|
ON_SYSTEM_METHODS = RuboCop::Cask::Constants::ON_SYSTEM_METHODS
|
||||||
MESSAGE = <<~EOS
|
MESSAGE = <<~EOS
|
||||||
Do not use top-level `%<stanza>s` stanza as the default, add an `on_{system}` block instead.
|
Do not use top-level `%<stanza>s` stanza as the default, add an `on_{system}` block instead.
|
||||||
Use `:or_older` or `:or_newer` to specify a range of macOS versions.
|
Use `:or_older` or `:or_newer` to specify a range of macOS versions.
|
||||||
EOS
|
EOS
|
||||||
|
|
||||||
def on_cask(cask_block)
|
def on_cask(cask_block)
|
||||||
return if cask_block.toplevel_stanzas.empty?
|
return if (cask_stanzas = cask_block.toplevel_stanzas).empty?
|
||||||
|
# Skip if there are no `on_*` blocks.
|
||||||
|
return unless cask_stanzas.any? { |s| ON_SYSTEM_METHODS.include?(s.stanza_name) }
|
||||||
|
|
||||||
cask_block.toplevel_stanzas.each do |stanza|
|
cask_stanzas.each do |stanza|
|
||||||
# TODO: We probably only want to disallow `version`, `url`, and `sha256` stanzas being overridden?
|
# TODO: We probably only want to disallow `version`, `url`, and `sha256` stanzas being overridden?
|
||||||
next unless RuboCop::Cask::Constants::STANZA_ORDER.include?(stanza.stanza_name)
|
next unless RuboCop::Cask::Constants::STANZA_ORDER.include?(stanza.stanza_name)
|
||||||
# Skip if the stanza we detect is already in an `on_*` block.
|
# Skip if the stanza we detect is already in an `on_*` block.
|
||||||
next if stanza.parent_node.block_type? && RuboCop::Cask::Constants::ON_SYSTEM_METHODS.include?(stanza.parent_node.method_name)
|
next if stanza.parent_node.block_type? && ON_SYSTEM_METHODS.include?(stanza.parent_node.method_name)
|
||||||
|
|
||||||
add_offense(stanza.source_range, message: format(MESSAGE, stanza: stanza.stanza_name))
|
add_offense(stanza.source_range, message: format(MESSAGE, stanza: stanza.stanza_name))
|
||||||
end
|
end
|
||||||
|
|||||||
@ -9,6 +9,21 @@ describe RuboCop::Cop::Cask::NoOverrides do
|
|||||||
|
|
||||||
subject(:cop) { described_class.new }
|
subject(:cop) { described_class.new }
|
||||||
|
|
||||||
|
context "when there are no on_system blocks" do
|
||||||
|
let(:source) do
|
||||||
|
<<~CASK
|
||||||
|
cask 'foo' do
|
||||||
|
version '1.2.3'
|
||||||
|
url 'https://brew.sh/foo.pkg'
|
||||||
|
|
||||||
|
name 'Foo'
|
||||||
|
end
|
||||||
|
CASK
|
||||||
|
end
|
||||||
|
|
||||||
|
include_examples "does not report any offenses"
|
||||||
|
end
|
||||||
|
|
||||||
context "when there are no top-level standalone stanzas" do
|
context "when there are no top-level standalone stanzas" do
|
||||||
let(:source) do
|
let(:source) do
|
||||||
<<~CASK
|
<<~CASK
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user