Add rubocop to enforce deprecate! over discontinued
This commit is contained in:
parent
254fcf7c1f
commit
8d8cd23414
43
Library/Homebrew/rubocops/cask/discontinued.rb
Normal file
43
Library/Homebrew/rubocops/cask/discontinued.rb
Normal file
@ -0,0 +1,43 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
# TODO: Remove this when we remove `caveats { discontinued }` (likely for Homebrew 4.5.0)
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Cask
|
||||
# This cop corrects `caveats { discontinued }` to `deprecate!`.
|
||||
class Discontinued < Base
|
||||
include CaskHelp
|
||||
extend AutoCorrector
|
||||
|
||||
MESSAGE = "Use `deprecate!` instead of `caveats { discontinued }`."
|
||||
|
||||
def on_cask_stanza_block(stanza_block)
|
||||
stanza_block.stanzas.select(&:caveats?).each do |stanza|
|
||||
find_discontinued_method_call(stanza.stanza_node) do |node|
|
||||
if caveats_constains_only_discontinued?(node.parent)
|
||||
add_offense(node.parent, message: MESSAGE) do |corrector|
|
||||
corrector.replace(node.parent.source_range,
|
||||
"deprecate! date: \"#{Date.today}\", because: :discontinued")
|
||||
end
|
||||
else
|
||||
add_offense(node, message: MESSAGE)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def_node_matcher :caveats_constains_only_discontinued?, <<~EOS
|
||||
(block
|
||||
(send nil? :caveats)
|
||||
(args)
|
||||
(send nil? :discontinued))
|
||||
EOS
|
||||
|
||||
def_node_search :find_discontinued_method_call, <<~EOS
|
||||
$(send nil? :discontinued)
|
||||
EOS
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
25
Library/Homebrew/rubocops/cask/discontinued.rbi
Normal file
25
Library/Homebrew/rubocops/cask/discontinued.rbi
Normal file
@ -0,0 +1,25 @@
|
||||
# typed: strict
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Cask
|
||||
class Discontinued < Base
|
||||
sig {
|
||||
params(
|
||||
base_node: RuboCop::AST::BlockNode,
|
||||
block: T.nilable(T.proc.params(node: RuboCop::AST::SendNode).void),
|
||||
).returns(T::Boolean)
|
||||
}
|
||||
def caveats_constains_only_discontinued?(base_node, &block); end
|
||||
|
||||
sig {
|
||||
params(
|
||||
base_node: RuboCop::AST::BlockNode,
|
||||
block: T.proc.params(node: RuboCop::AST::SendNode).void,
|
||||
).void
|
||||
}
|
||||
def find_discontinued_method_call(base_node, &block); end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -13,6 +13,7 @@ require_relative "cask/mixin/cask_help"
|
||||
require_relative "cask/mixin/on_homepage_stanza"
|
||||
require_relative "cask/mixin/on_url_stanza"
|
||||
require_relative "cask/desc"
|
||||
require_relative "cask/discontinued"
|
||||
require_relative "cask/homepage_url_trailing_slash"
|
||||
require_relative "cask/no_overrides"
|
||||
require_relative "cask/on_system_conditionals"
|
||||
|
||||
65
Library/Homebrew/test/rubocops/cask/discontinued_spec.rb
Normal file
65
Library/Homebrew/test/rubocops/cask/discontinued_spec.rb
Normal file
@ -0,0 +1,65 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rubocops/rubocop-cask"
|
||||
|
||||
describe RuboCop::Cop::Cask::Discontinued, :config do
|
||||
it "reports no offenses when there is no `caveats` stanza" do
|
||||
expect_no_offenses <<~CASK
|
||||
cask "foo" do
|
||||
url "https://example.com/download/foo-v1.2.0.dmg",
|
||||
verified: "example.com/download/"
|
||||
end
|
||||
CASK
|
||||
end
|
||||
|
||||
it "reports no offenses when there is a `caveats` stanza without `discontinued`" do
|
||||
expect_no_offenses <<~CASK
|
||||
cask "foo" do
|
||||
url "https://example.com/download/foo-v1.2.0.dmg",
|
||||
verified: "example.com/download/"
|
||||
|
||||
caveats do
|
||||
files_in_usr_local
|
||||
end
|
||||
end
|
||||
CASK
|
||||
end
|
||||
|
||||
it "reports an offense when there is a `caveats` stanza with `discontinued` and other caveats" do
|
||||
expect_offense <<~CASK
|
||||
cask "foo" do
|
||||
url "https://example.com/download/foo-v1.2.0.dmg",
|
||||
verified: "example.com/download/"
|
||||
|
||||
caveats do
|
||||
discontinued
|
||||
^^^^^^^^^^^^ Use `deprecate!` instead of `caveats { discontinued }`.
|
||||
files_in_usr_local
|
||||
end
|
||||
end
|
||||
CASK
|
||||
end
|
||||
|
||||
it "corrects `caveats { discontinued }` to `deprecate!`" do
|
||||
expect_offense <<~CASK
|
||||
cask "foo" do
|
||||
url "https://example.com/download/foo-v1.2.0.dmg",
|
||||
verified: "example.com/download/"
|
||||
|
||||
caveats do
|
||||
^^^^^^^^^^ Use `deprecate!` instead of `caveats { discontinued }`.
|
||||
discontinued
|
||||
end
|
||||
end
|
||||
CASK
|
||||
|
||||
expect_correction <<~CASK
|
||||
cask "foo" do
|
||||
url "https://example.com/download/foo-v1.2.0.dmg",
|
||||
verified: "example.com/download/"
|
||||
|
||||
deprecate! date: "#{Date.today}", because: :discontinued
|
||||
end
|
||||
CASK
|
||||
end
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user