mirror of
https://github.com/Homebrew/brew.git
synced 2025-07-14 16:09:03 +08:00
Treat zap
and uninstall
the same
- Since `zap` can have more than just `trash`.
This commit is contained in:
parent
d5f9eef1b5
commit
693a27d48b
@ -8,14 +8,11 @@ module RuboCop
|
||||
extend AutoCorrector
|
||||
|
||||
def on_send(node)
|
||||
return unless [:zap, :uninstall].include?(name = node.method_name)
|
||||
return unless [:zap, :uninstall].include?(node.method_name)
|
||||
|
||||
node.each_descendant(:pair).each do |pair|
|
||||
symbols = pair.children.select(&:sym_type?).map(&:value)
|
||||
# For `zap`s, we only care about `trash` arrays.
|
||||
next if name == :zap && !symbols.include?(:trash)
|
||||
# Don't order `uninstall` arrays that contain commands.
|
||||
next if name == :uninstall && symbols.intersect?([:signal, :script, :early_script, :args, :input])
|
||||
next if symbols.intersect?([:signal, :script, :early_script, :args, :input])
|
||||
|
||||
pair.each_descendant(:array).each do |array|
|
||||
if array.children.length == 1
|
||||
|
@ -22,7 +22,7 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do
|
||||
CASK
|
||||
end
|
||||
|
||||
it "reports an offense when the `zap trash` paths are not in alphabetical order" do
|
||||
it "reports an offense when the `zap` stanza paths are not in alphabetical order" do
|
||||
expect_offense(<<~CASK)
|
||||
cask "foo" do
|
||||
url "https://example.com/foo.zip"
|
||||
@ -34,6 +34,11 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do
|
||||
"~/Library/Application Support/Foo",
|
||||
"~/.dotfiles/thing",
|
||||
"~/Library/Application Support/Bar",
|
||||
],
|
||||
rmdir: [
|
||||
^ The array elements should be ordered alphabetically
|
||||
"/Applications/foo/nested/blah",
|
||||
"/Applications/foo/",
|
||||
]
|
||||
end
|
||||
CASK
|
||||
@ -48,6 +53,10 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do
|
||||
"~/.dotfiles/thing",
|
||||
"~/Library/Application Support/Bar",
|
||||
"~/Library/Application Support/Foo",
|
||||
],
|
||||
rmdir: [
|
||||
"/Applications/foo/",
|
||||
"/Applications/foo/nested/blah",
|
||||
]
|
||||
end
|
||||
CASK
|
||||
@ -78,19 +87,6 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do
|
||||
CASK
|
||||
end
|
||||
|
||||
it "ignores `zap` methods other than `trash`" do
|
||||
expect_no_offenses(<<~CASK)
|
||||
cask "foo" do
|
||||
url "https://example.com/foo.zip"
|
||||
|
||||
zap delete: [
|
||||
"~/Library/Application Support/Foo",
|
||||
"~/Library/Application Support/Bar",
|
||||
]
|
||||
end
|
||||
CASK
|
||||
end
|
||||
|
||||
it "autocorrects alphabetization in `uninstall` methods" do
|
||||
expect_offense(<<~CASK)
|
||||
cask "foo" do
|
||||
|
@ -9,9 +9,9 @@ cask "with-zap-delete" do
|
||||
|
||||
zap delete: [
|
||||
"#{TEST_TMPDIR}/absolute_path",
|
||||
"~/path_with_tilde",
|
||||
"#{TEST_TMPDIR}/glob_path*",
|
||||
"impermissible/relative/path",
|
||||
"/another/impermissible/../relative/path",
|
||||
"impermissible/relative/path",
|
||||
"~/path_with_tilde",
|
||||
]
|
||||
end
|
||||
|
Loading…
x
Reference in New Issue
Block a user