Merge pull request #16581 from bevanjkay/shared_filelist_cop
rubocops/cask: add a cop for specific numbered shared file list files
This commit is contained in:
commit
0782ba112c
37
Library/Homebrew/rubocops/cask/shared_filelist_glob.rb
Normal file
37
Library/Homebrew/rubocops/cask/shared_filelist_glob.rb
Normal file
@ -0,0 +1,37 @@
|
||||
# typed: true
|
||||
# frozen_string_literal: true
|
||||
|
||||
module RuboCop
|
||||
module Cop
|
||||
module Cask
|
||||
class SharedFilelistGlob < Base
|
||||
extend AutoCorrector
|
||||
|
||||
def on_send(node)
|
||||
return if node.method_name != :zap
|
||||
|
||||
node.each_descendant(:pair).each do |pair|
|
||||
symbols = pair.children.select(&:sym_type?).map(&:value)
|
||||
next unless symbols.include?(:trash)
|
||||
|
||||
pair.each_descendant(:array).each do |array|
|
||||
regex = /\.sfl\d"$/
|
||||
message = "Use a glob (*) instead of a specific version (ie. sfl2) for trashing Shared File List paths"
|
||||
|
||||
array.children.each do |item|
|
||||
next unless item.source.match?(regex)
|
||||
|
||||
corrected_item = item.source.sub(/sfl\d"$/, "sfl*\"")
|
||||
|
||||
add_offense(item,
|
||||
message: message) do |corrector|
|
||||
corrector.replace(item, corrected_item)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -18,6 +18,7 @@ require_relative "cask/discontinued"
|
||||
require_relative "cask/homepage_url_trailing_slash"
|
||||
require_relative "cask/no_overrides"
|
||||
require_relative "cask/on_system_conditionals"
|
||||
require_relative "cask/shared_filelist_glob"
|
||||
require_relative "cask/stanza_order"
|
||||
require_relative "cask/stanza_grouping"
|
||||
require_relative "cask/uninstall_methods_order"
|
||||
|
@ -0,0 +1,24 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require "rubocops/rubocop-cask"
|
||||
|
||||
describe RuboCop::Cop::Cask::SharedFilelistGlob, :config do
|
||||
it "reports an offense when a zap trash array includes an .sfl2 or .sfl3 file" do
|
||||
expect_offense(<<~CASK)
|
||||
cask "foo" do
|
||||
url "https://example.com/foo.zip"
|
||||
|
||||
zap trash: ["~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/org.mozilla.firefox.sfl2"]
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use a glob (*) instead of a specific version (ie. sfl2) for trashing Shared File List paths
|
||||
end
|
||||
CASK
|
||||
|
||||
expect_correction(<<~CASK)
|
||||
cask "foo" do
|
||||
url "https://example.com/foo.zip"
|
||||
|
||||
zap trash: ["~/Library/Application Support/com.apple.sharedfilelist/com.apple.LSSharedFileList.ApplicationRecentDocuments/org.mozilla.firefox.sfl*"]
|
||||
end
|
||||
CASK
|
||||
end
|
||||
end
|
Loading…
x
Reference in New Issue
Block a user