From db72295c2025156574ccbfc477d671b832705595 Mon Sep 17 00:00:00 2001 From: Razvan Azamfirei Date: Wed, 20 Dec 2023 18:37:49 +0200 Subject: [PATCH 1/4] rubocop: order uninstall methods --- .../rubocops/cask/constants/stanza.rb | 14 ++ .../rubocops/cask/uninstall_methods_order.rb | 49 ++++ Library/Homebrew/rubocops/rubocop-cask.rb | 1 + .../cask/uninstall_methods_order_spec.rb | 211 ++++++++++++++++++ 4 files changed, 275 insertions(+) create mode 100644 Library/Homebrew/rubocops/cask/uninstall_methods_order.rb create mode 100644 Library/Homebrew/test/rubocops/cask/uninstall_methods_order_spec.rb diff --git a/Library/Homebrew/rubocops/cask/constants/stanza.rb b/Library/Homebrew/rubocops/cask/constants/stanza.rb index 2fe782a17dc35..64c524d015040 100644 --- a/Library/Homebrew/rubocops/cask/constants/stanza.rb +++ b/Library/Homebrew/rubocops/cask/constants/stanza.rb @@ -65,6 +65,20 @@ module Constants end.freeze STANZA_ORDER = STANZA_GROUPS.flatten.freeze + + UNINSTALL_METHODS_ORDER = [ + :early_script, + :launchctl, + :quit, + :signal, + :login_item, + :kext, + :script, + :pkgutil, + :delete, + :trash, + :rmdir, + ].freeze end end end diff --git a/Library/Homebrew/rubocops/cask/uninstall_methods_order.rb b/Library/Homebrew/rubocops/cask/uninstall_methods_order.rb new file mode 100644 index 0000000000000..07c02166650fe --- /dev/null +++ b/Library/Homebrew/rubocops/cask/uninstall_methods_order.rb @@ -0,0 +1,49 @@ +# typed: strict +# frozen_string_literal: true + +require "rubocops/shared/helper_functions" + +module RuboCop + module Cop + module Cask + # This cop checks for the correct order of methods within the 'uninstall' and 'zap' stanzas. + class UninstallMethodsOrder < Base + extend AutoCorrector + include CaskHelp + include HelperFunctions + + MSG = T.let("`%s` method out of order".freeze, String) + + sig { params(node: AST::SendNode).void } + def on_send(node) + return unless [:zap, :uninstall].include?(node.method_name) + + hash_node = node.arguments.first + return if hash_node.nil? || (!hash_node.is_a?(AST::Node) && !hash_node.hash_type?) + + method_nodes = hash_node.pairs.map(&:key) + expected_order = method_nodes.sort_by { |method| method_order_index(method) } + + method_nodes.each_with_index do |method, index| + next if method == expected_order[index] + + add_offense(method, message: format(MSG, method: method.children.first)) do |corrector| + indentation = " " * (start_column(method) - line_start_column(method)) + ordered_sources = expected_order.map do |expected_method| + hash_node.pairs.find { |pair| pair.key == expected_method }.source + end + new_code = ordered_sources.join(",\n#{indentation}") + corrector.replace(hash_node.source_range, new_code) + end + end + end + + sig { params(method_node: AST::SymbolNode).returns(Integer) } + def method_order_index(method_node) + method_name = method_node.children.first + RuboCop::Cask::Constants::UNINSTALL_METHODS_ORDER.index(method_name) || -1 + end + end + end + end +end diff --git a/Library/Homebrew/rubocops/rubocop-cask.rb b/Library/Homebrew/rubocops/rubocop-cask.rb index 279f2ad467373..dd498fb2615f8 100644 --- a/Library/Homebrew/rubocops/rubocop-cask.rb +++ b/Library/Homebrew/rubocops/rubocop-cask.rb @@ -18,6 +18,7 @@ require_relative "cask/homepage_url_trailing_slash" require_relative "cask/no_overrides" require_relative "cask/on_system_conditionals" +require_relative "cask/uninstall_methods_order" require_relative "cask/stanza_order" require_relative "cask/stanza_grouping" require_relative "cask/url" diff --git a/Library/Homebrew/test/rubocops/cask/uninstall_methods_order_spec.rb b/Library/Homebrew/test/rubocops/cask/uninstall_methods_order_spec.rb new file mode 100644 index 0000000000000..4e7c5180b7e88 --- /dev/null +++ b/Library/Homebrew/test/rubocops/cask/uninstall_methods_order_spec.rb @@ -0,0 +1,211 @@ +# frozen_string_literal: true + +require "rubocops/rubocop-cask" +describe RuboCop::Cop::Cask::UninstallMethodsOrder, :config do + context "with order errors in both the uninstall and zap block" do + it "reports an offense and corrects the order" do + expect_offense(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + uninstall delete: [ + ^^^^^^ `delete` method out of order + "/usr/local/bin/foo", + "/usr/local/bin/foobar", + ], + script: { + ^^^^^^ `script` method out of order + executable: "/usr/local/bin/foo", + sudo: false, + }, + pkgutil: "org.foo.bar" + ^^^^^^^ `pkgutil` method out of order + + zap delete: [ + "~/Library/Application Support/Bar", + "~/Library/Application Support/Foo", + ], + rmdir: "~/Library/Application Support", + ^^^^^ `rmdir` method out of order + trash: "~/Library/Application Support/FooBar" + ^^^^^ `trash` method out of order + end + CASK + + expect_correction(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + uninstall script: { + executable: "/usr/local/bin/foo", + sudo: false, + }, + pkgutil: "org.foo.bar", + delete: [ + "/usr/local/bin/foo", + "/usr/local/bin/foobar", + ] + + zap delete: [ + "~/Library/Application Support/Bar", + "~/Library/Application Support/Foo", + ], + trash: "~/Library/Application Support/FooBar", + rmdir: "~/Library/Application Support" + end + CASK + end + end + + context "with incorrectly ordered uninstall methods" do + it "reports an offense and corrects the order" do + expect_offense(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + uninstall delete: [ + ^^^^^^ `delete` method out of order + "/usr/local/bin/foo", + "/usr/local/bin/foobar", + ], + script: { + ^^^^^^ `script` method out of order + executable: "/usr/local/bin/foo", + sudo: false, + }, + pkgutil: "org.foo.bar" + ^^^^^^^ `pkgutil` method out of order + end + CASK + + expect_correction(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + uninstall script: { + executable: "/usr/local/bin/foo", + sudo: false, + }, + pkgutil: "org.foo.bar", + delete: [ + "/usr/local/bin/foo", + "/usr/local/bin/foobar", + ] + end + CASK + end + end + + context "with correctly ordered uninstall methods" do + it "does not report an offense" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + uninstall script: { + executable: "/usr/local/bin/foo", + sudo: false, + }, + pkgutil: "org.foo.bar", + delete: [ + "/usr/local/bin/foo", + "/usr/local/bin/foobar", + ] + end + CASK + end + end + + context "with a single method in uninstall block" do + it "does not report an offense" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + uninstall delete: "/usr/local/bin/foo" + end + CASK + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + uninstall pkgutil: [ + "org.foo.bar", + "org.foobar.bar", + ] + end + CASK + end + end + + context "with incorrectly ordered zap methods" do + it "reports an offense and corrects the order" do + expect_offense(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap delete: [ + "~/Library/Application Support/Foo", + "~/Library/Application Support/Bar", + ], + rmdir: "~/Library/Application Support", + ^^^^^ `rmdir` method out of order + trash: "~/Library/Application Support/FooBar" + ^^^^^ `trash` method out of order + end + CASK + + expect_correction(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap delete: [ + "~/Library/Application Support/Foo", + "~/Library/Application Support/Bar", + ], + trash: "~/Library/Application Support/FooBar", + rmdir: "~/Library/Application Support" + end + CASK + end + end + + context "with correctly ordered zap methods" do + it "does not report an offense" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap delete: [ + "~/Library/Application Support/Bar", + "~/Library/Application Support/Foo", + ], + trash: "~/Library/Application Support/FooBar", + rmdir: "~/Library/Application Support" + end + CASK + end + end + + context "with a single method in the zap block" do + it "does not report an offense" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap trash: "~/Library/Application Support/FooBar" + end + CASK + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap trash: [ + "~/Library/Application Support/FooBar", + "~/Library/Application Support/FooBarBar", + ] + end + CASK + end + end +end From 7c540dd3c59963585ed51f498a2655f47a37c771 Mon Sep 17 00:00:00 2001 From: Razvan Azamfirei Date: Mon, 1 Jan 2024 17:11:24 +0200 Subject: [PATCH 2/4] rubocop: add uninstall methods order tests Co-authored-by: Bevan Kay --- .../cask/uninstall_methods_order_spec.rb | 444 ++++++++++++------ 1 file changed, 295 insertions(+), 149 deletions(-) diff --git a/Library/Homebrew/test/rubocops/cask/uninstall_methods_order_spec.rb b/Library/Homebrew/test/rubocops/cask/uninstall_methods_order_spec.rb index 4e7c5180b7e88..c44e31e365f7e 100644 --- a/Library/Homebrew/test/rubocops/cask/uninstall_methods_order_spec.rb +++ b/Library/Homebrew/test/rubocops/cask/uninstall_methods_order_spec.rb @@ -2,11 +2,30 @@ require "rubocops/rubocop-cask" describe RuboCop::Cop::Cask::UninstallMethodsOrder, :config do - context "with order errors in both the uninstall and zap block" do - it "reports an offense and corrects the order" do - expect_offense(<<~CASK) - cask "foo" do - url "https://example.com/foo.zip" + context "with uninstall blocks" do + context "when methods are incorrectly ordered" do + it "detects and corrects ordering offenses in the uninstall block when each method contains a single item" do + expect_offense(<<~CASK) + cask 'foo' do + uninstall quit: "com.example.foo", + ^^^^ `quit` method out of order + launchctl: "com.example.foo" + ^^^^^^^^^ `launchctl` method out of order + end + CASK + + expect_correction(<<~CASK) + cask 'foo' do + uninstall launchctl: "com.example.foo", + quit: "com.example.foo" + end + CASK + end + + it "detects and corrects ordering offenses in the uninstall block when methods contain arrays" do + expect_offense(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" uninstall delete: [ ^^^^^^ `delete` method out of order @@ -20,21 +39,12 @@ }, pkgutil: "org.foo.bar" ^^^^^^^ `pkgutil` method out of order + end + CASK - zap delete: [ - "~/Library/Application Support/Bar", - "~/Library/Application Support/Foo", - ], - rmdir: "~/Library/Application Support", - ^^^^^ `rmdir` method out of order - trash: "~/Library/Application Support/FooBar" - ^^^^^ `trash` method out of order - end - CASK - - expect_correction(<<~CASK) - cask "foo" do - url "https://example.com/foo.zip" + expect_correction(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" uninstall script: { executable: "/usr/local/bin/foo", @@ -45,165 +55,301 @@ "/usr/local/bin/foo", "/usr/local/bin/foobar", ] + end + CASK + end + end - zap delete: [ - "~/Library/Application Support/Bar", - "~/Library/Application Support/Foo", - ], - trash: "~/Library/Application Support/FooBar", - rmdir: "~/Library/Application Support" - end - CASK + context "when methods are correctly ordered" do + it "does not report an offense" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + uninstall script: { + executable: "/usr/local/bin/foo", + sudo: false, + }, + pkgutil: "org.foo.bar", + delete: [ + "/usr/local/bin/foo", + "/usr/local/bin/foobar", + ] + end + CASK + end end - end - context "with incorrectly ordered uninstall methods" do - it "reports an offense and corrects the order" do - expect_offense(<<~CASK) - cask "foo" do - url "https://example.com/foo.zip" - - uninstall delete: [ - ^^^^^^ `delete` method out of order - "/usr/local/bin/foo", - "/usr/local/bin/foobar", - ], - script: { - ^^^^^^ `script` method out of order - executable: "/usr/local/bin/foo", - sudo: false, - }, - pkgutil: "org.foo.bar" - ^^^^^^^ `pkgutil` method out of order - end - CASK + context "with a single method" do + it "does not report an offense when a single item is present in the method" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" - expect_correction(<<~CASK) - cask "foo" do - url "https://example.com/foo.zip" - - uninstall script: { - executable: "/usr/local/bin/foo", - sudo: false, - }, - pkgutil: "org.foo.bar", - delete: [ - "/usr/local/bin/foo", - "/usr/local/bin/foobar", - ] - end - CASK + uninstall delete: "/usr/local/bin/foo" + end + CASK + end + + it "does not report an offense when the method contains an array" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + uninstall pkgutil: [ + "org.foo.bar", + "org.foobar.bar", + ] + end + CASK + end end end - context "with correctly ordered uninstall methods" do - it "does not report an offense" do - expect_no_offenses(<<~CASK) - cask "foo" do - url "https://example.com/foo.zip" + context "with zap blocks" do + context "when methods are incorrectly ordered" do + it "detects and corrects ordering offenses in the zap block when each method contains a single item" do + expect_offense(<<~CASK) + cask 'foo' do + zap rmdir: "/Library/Foo", + ^^^^^ `rmdir` method out of order + trash: "com.example.foo" + ^^^^^ `trash` method out of order + end + CASK - uninstall script: { - executable: "/usr/local/bin/foo", - sudo: false, - }, - pkgutil: "org.foo.bar", - delete: [ - "/usr/local/bin/foo", - "/usr/local/bin/foobar", - ] - end - CASK + expect_correction(<<~CASK) + cask 'foo' do + zap trash: "com.example.foo", + rmdir: "/Library/Foo" + end + CASK + end + + it "detects and corrects ordering offenses in the zap block when methods contain arrays" do + expect_offense(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap delete: [ + "~/Library/Application Support/Foo", + "~/Library/Application Support/Bar", + ], + rmdir: "~/Library/Application Support", + ^^^^^ `rmdir` method out of order + trash: "~/Library/Application Support/FooBar" + ^^^^^ `trash` method out of order + end + CASK + + expect_correction(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap delete: [ + "~/Library/Application Support/Foo", + "~/Library/Application Support/Bar", + ], + trash: "~/Library/Application Support/FooBar", + rmdir: "~/Library/Application Support" + end + CASK + end + end + + context "when methods are correctly ordered" do + it "does not report an offense" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap delete: [ + "~/Library/Application Support/Bar", + "~/Library/Application Support/Foo", + ], + trash: "~/Library/Application Support/FooBar", + rmdir: "~/Library/Application Support" + end + CASK + end + end + + context "with a single method" do + it "does not report an offense when a single item is present in the method" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap trash: "~/Library/Application Support/FooBar" + end + CASK + end + + it "does not report an offense when the method contains an array" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap trash: [ + "~/Library/Application Support/FooBar", + "~/Library/Application Support/FooBarBar", + ] + end + CASK + end end end - context "with a single method in uninstall block" do - it "does not report an offense" do - expect_no_offenses(<<~CASK) - cask "foo" do - url "https://example.com/foo.zip" + context "with both uninstall and zap blocks" do + context "when both uninstall and zap methods are incorrectly ordered" do + it "detects offenses and auto-corrects to the correct order" do + expect_offense(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" - uninstall delete: "/usr/local/bin/foo" - end - CASK - expect_no_offenses(<<~CASK) - cask "foo" do - url "https://example.com/foo.zip" + uninstall delete: [ + ^^^^^^ `delete` method out of order + "/usr/local/bin/foo", + "/usr/local/bin/foobar", + ], + script: { + ^^^^^^ `script` method out of order + executable: "/usr/local/bin/foo", + sudo: false, + }, + pkgutil: "org.foo.bar" + ^^^^^^^ `pkgutil` method out of order - uninstall pkgutil: [ - "org.foo.bar", - "org.foobar.bar", - ] - end - CASK + zap delete: [ + "~/Library/Application Support/Bar", + "~/Library/Application Support/Foo", + ], + rmdir: "~/Library/Application Support", + ^^^^^ `rmdir` method out of order + trash: "~/Library/Application Support/FooBar" + ^^^^^ `trash` method out of order + end + CASK + + expect_correction(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + uninstall script: { + executable: "/usr/local/bin/foo", + sudo: false, + }, + pkgutil: "org.foo.bar", + delete: [ + "/usr/local/bin/foo", + "/usr/local/bin/foobar", + ] + + zap delete: [ + "~/Library/Application Support/Bar", + "~/Library/Application Support/Foo", + ], + trash: "~/Library/Application Support/FooBar", + rmdir: "~/Library/Application Support" + end + CASK + end + end + + context "when uninstall and zap methods are correctly ordered" do + it "does not report an offense" do + expect_no_offenses(<<~CASK) + cask 'foo' do + uninstall early_script: { + executable: "foo.sh", + args: ["--unattended"], + }, + launchctl: "com.example.foo", + quit: "com.example.foo", + signal: ["TERM", "com.example.foo"], + login_item: "FooApp", + kext: "com.example.foo", + script: { + executable: "foo.sh", + args: ["--unattended"], + }, + pkgutil: "com.example.foo", + delete: "~/Library/Preferences/com.example.foo", + trash: "~/Library/Preferences/com.example.foo", + rmdir: "~/Library/Foo" + + zap early_script: { + executable: "foo.sh", + args: ["--unattended"], + }, + launchctl: "com.example.foo", + quit: "com.example.foo", + signal: ["TERM", "com.example.foo"], + login_item: "FooApp", + kext: "com.example.foo", + script: { + executable: "foo.sh", + args: ["--unattended"], + }, + pkgutil: "com.example.foo", + delete: "~/Library/Preferences/com.example.foo", + trash: "~/Library/Preferences/com.example.foo", + rmdir: "~/Library/Foo" + end + CASK + end end end - context "with incorrectly ordered zap methods" do - it "reports an offense and corrects the order" do - expect_offense(<<~CASK) - cask "foo" do - url "https://example.com/foo.zip" - - zap delete: [ - "~/Library/Application Support/Foo", - "~/Library/Application Support/Bar", - ], - rmdir: "~/Library/Application Support", - ^^^^^ `rmdir` method out of order - trash: "~/Library/Application Support/FooBar" - ^^^^^ `trash` method out of order + context "when in-line comments are present" do + it "keeps associated comments when auto-correcting" do + expect_offense <<~CASK + cask 'foo' do + uninstall quit: "com.example.foo", # comment on same line + ^^^^ `quit` method out of order + launchctl: "com.example.foo" + ^^^^^^^^^ `launchctl` method out of order end CASK - expect_correction(<<~CASK) - cask "foo" do - url "https://example.com/foo.zip" - - zap delete: [ - "~/Library/Application Support/Foo", - "~/Library/Application Support/Bar", - ], - trash: "~/Library/Application Support/FooBar", - rmdir: "~/Library/Application Support" + expect_correction <<~CASK + cask 'foo' do + uninstall launchctl: "com.example.foo", + quit: "com.example.foo" # comment on same line end CASK end end - context "with correctly ordered zap methods" do - it "does not report an offense" do - expect_no_offenses(<<~CASK) + context "when methods are inside an `on_os` block" do + it "detects and corrects offenses within OS-specific blocks" do + expect_offense <<~CASK cask "foo" do - url "https://example.com/foo.zip" - - zap delete: [ - "~/Library/Application Support/Bar", - "~/Library/Application Support/Foo", - ], - trash: "~/Library/Application Support/FooBar", - rmdir: "~/Library/Application Support" + on_catalina do + uninstall trash: "com.example.foo", + ^^^^^ `trash` method out of order + launchctl: "com.example.foo" + ^^^^^^^^^ `launchctl` method out of order + end + on_ventura do + uninstall quit: "com.example.foo", + ^^^^ `quit` method out of order + launchctl: "com.example.foo" + ^^^^^^^^^ `launchctl` method out of order + end end CASK - end - end - - context "with a single method in the zap block" do - it "does not report an offense" do - expect_no_offenses(<<~CASK) - cask "foo" do - url "https://example.com/foo.zip" - zap trash: "~/Library/Application Support/FooBar" - end - CASK - expect_no_offenses(<<~CASK) + expect_correction <<~CASK cask "foo" do - url "https://example.com/foo.zip" - - zap trash: [ - "~/Library/Application Support/FooBar", - "~/Library/Application Support/FooBarBar", - ] + on_catalina do + uninstall launchctl: "com.example.foo", + trash: "com.example.foo" + end + on_ventura do + uninstall launchctl: "com.example.foo", + quit: "com.example.foo" + end end CASK end From 9aabe1ba910127e582bcbcbef82a3b977c6cf1a1 Mon Sep 17 00:00:00 2001 From: Razvan Azamfirei Date: Sat, 27 Jan 2024 16:19:16 -0500 Subject: [PATCH 3/4] rubocop: preserve comments when ordering uninstall methods --- .../rubocops/cask/uninstall_methods_order.rb | 34 ++++++++++++++----- Library/Homebrew/rubocops/rubocop-cask.rb | 2 +- 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/Library/Homebrew/rubocops/cask/uninstall_methods_order.rb b/Library/Homebrew/rubocops/cask/uninstall_methods_order.rb index 07c02166650fe..ae252485af95b 100644 --- a/Library/Homebrew/rubocops/cask/uninstall_methods_order.rb +++ b/Library/Homebrew/rubocops/cask/uninstall_methods_order.rb @@ -9,10 +9,9 @@ module Cask # This cop checks for the correct order of methods within the 'uninstall' and 'zap' stanzas. class UninstallMethodsOrder < Base extend AutoCorrector - include CaskHelp include HelperFunctions - MSG = T.let("`%s` method out of order".freeze, String) + MSG = T.let("`%s` method out of order", String) sig { params(node: AST::SendNode).void } def on_send(node) @@ -23,18 +22,35 @@ def on_send(node) method_nodes = hash_node.pairs.map(&:key) expected_order = method_nodes.sort_by { |method| method_order_index(method) } + comments = processed_source.comments method_nodes.each_with_index do |method, index| next if method == expected_order[index] - add_offense(method, message: format(MSG, method: method.children.first)) do |corrector| - indentation = " " * (start_column(method) - line_start_column(method)) - ordered_sources = expected_order.map do |expected_method| - hash_node.pairs.find { |pair| pair.key == expected_method }.source + report_and_correct_offense(method, hash_node, expected_order, comments) + end + end + + sig { + params(method: AST::Node, + hash_node: AST::HashNode, + expected_order: T::Array[AST::Node], + comments: T::Array[Parser::Source::Comment]).void + } + def report_and_correct_offense(method, hash_node, expected_order, comments) + add_offense(method, message: format(MSG, method: method.children.first)) do |corrector| + indentation = " " * (start_column(method) - line_start_column(method)) + new_code = expected_order.map do |expected_method| + method_pair = hash_node.pairs.find { |pair| pair.key == expected_method } + source = method_pair.source + + # Find and attach a comment on the same line as the method_pair, if any + inline_comment = comments.find do |comment| + comment.location.line == method_pair.loc.line && comment.location.column > method_pair.loc.column end - new_code = ordered_sources.join(",\n#{indentation}") - corrector.replace(hash_node.source_range, new_code) - end + inline_comment ? "#{source} #{inline_comment.text}" : source + end.join(",\n#{indentation}") + corrector.replace(hash_node.source_range, new_code) end end diff --git a/Library/Homebrew/rubocops/rubocop-cask.rb b/Library/Homebrew/rubocops/rubocop-cask.rb index dd498fb2615f8..572db73393352 100644 --- a/Library/Homebrew/rubocops/rubocop-cask.rb +++ b/Library/Homebrew/rubocops/rubocop-cask.rb @@ -18,9 +18,9 @@ require_relative "cask/homepage_url_trailing_slash" require_relative "cask/no_overrides" require_relative "cask/on_system_conditionals" -require_relative "cask/uninstall_methods_order" require_relative "cask/stanza_order" require_relative "cask/stanza_grouping" +require_relative "cask/uninstall_methods_order" require_relative "cask/url" require_relative "cask/url_legacy_comma_separators" require_relative "cask/variables" From 82cdf27eb866b533ef147e74a29f79e797a4f6ba Mon Sep 17 00:00:00 2001 From: Razvan Azamfirei Date: Sat, 27 Jan 2024 16:22:07 -0500 Subject: [PATCH 4/4] fixture/cask: fix style violations --- .../test/support/fixtures/cask/Casks/everything.rb | 6 +++--- .../test/support/fixtures/cask/Casks/with-installable.rb | 4 ++-- .../test/support/fixtures/cask/Casks/with-pkgutil-zap.rb | 4 ++-- .../Homebrew/test/support/fixtures/cask/Casks/with-zap.rb | 6 +++--- .../Homebrew/test/support/fixtures/cask/everything.json | 8 ++++---- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/everything.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/everything.rb index 1f0cfe08f53c4..fd8e30cb54d16 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/everything.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/everything.rb @@ -32,12 +32,12 @@ } uninstall launchctl: "com.every.thing.agent", - delete: "/Library/EverythingHelperTools", - kext: "com.every.thing.driver", signal: [ ["TERM", "com.every.thing.controller#{version.major}"], ["TERM", "com.every.thing.bin"], - ] + ], + kext: "com.every.thing.driver", + delete: "/Library/EverythingHelperTools" zap trash: [ "~/.everything", diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-installable.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-installable.rb index d6f8ad75b694f..67d58c52d24ea 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-installable.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-installable.rb @@ -7,9 +7,9 @@ pkg "MyFancyPkg/Fancy.pkg" - uninstall script: { executable: "MyFancyPkg/FancyUninstaller.tool", args: ["--please"] }, - quit: "my.fancy.package.app", + uninstall quit: "my.fancy.package.app", login_item: "Fancy", + script: { executable: "MyFancyPkg/FancyUninstaller.tool", args: ["--please"] }, delete: [ "#{TEST_TMPDIR}/absolute_path", "#{TEST_TMPDIR}/glob_path*", diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-pkgutil-zap.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-pkgutil-zap.rb index b19a54de0425b..560d5cd581e61 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-pkgutil-zap.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-pkgutil-zap.rb @@ -7,7 +7,7 @@ pkg "Fancy.pkg" - zap pkgutil: "my.fancy.package.*", + zap launchctl: "my.fancy.package.service", kext: "my.fancy.package.kernelextension", - launchctl: "my.fancy.package.service" + pkgutil: "my.fancy.package.*" end diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap.rb index 9027e38bfa23d..69f49f5dcfb70 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap.rb @@ -9,11 +9,11 @@ uninstall quit: "my.fancy.package.app.from.uninstall" - zap script: { + zap quit: "my.fancy.package.app", + login_item: "Fancy", + script: { executable: "MyFancyPkg/FancyUninstaller.tool", args: ["--please"], }, - quit: "my.fancy.package.app", - login_item: "Fancy", delete: "~/Library/Preferences/my.fancy.app.plist" end diff --git a/Library/Homebrew/test/support/fixtures/cask/everything.json b/Library/Homebrew/test/support/fixtures/cask/everything.json index 9f8243f9ae4a8..6efdcaa095993 100644 --- a/Library/Homebrew/test/support/fixtures/cask/everything.json +++ b/Library/Homebrew/test/support/fixtures/cask/everything.json @@ -28,8 +28,6 @@ "uninstall": [ { "launchctl": "com.every.thing.agent", - "delete": "/Library/EverythingHelperTools", - "kext": "com.every.thing.driver", "signal": [ [ "TERM", @@ -39,7 +37,9 @@ "TERM", "com.every.thing.bin" ] - ] + ], + "kext": "com.every.thing.driver", + "delete": "/Library/EverythingHelperTools" } ] }, @@ -101,6 +101,6 @@ ], "ruby_source_path": "Casks/everything.rb", "ruby_source_checksum": { - "sha256": "0c4af571cce1632fc6a3dcf3e75ba82a3283077ef12399428192c26f9d6f779b" + "sha256": "d8d0d6b2e5ff65388eccb82236fd3aa157b4a29bb043a1f72b97f0e9b70e8320" } }