From 0852e1d7b650465c0e73f40521e3841ba20a73a8 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 8 Jan 2024 13:26:41 -0800 Subject: [PATCH 1/2] Refactor away String#indent --- Library/Homebrew/test/dev-cmd/bottle_spec.rb | 22 +++++++++---------- .../spec/shared_context/integration_test.rb | 2 +- Library/Homebrew/test/utils/ast/ast_spec.rb | 18 +++++++-------- .../test/utils/ast/formula_ast_spec.rb | 8 +++---- Library/Homebrew/utils/ast.rb | 2 +- 5 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Library/Homebrew/test/dev-cmd/bottle_spec.rb b/Library/Homebrew/test/dev-cmd/bottle_spec.rb index b8a6835a60..01f8e53d26 100644 --- a/Library/Homebrew/test/dev-cmd/bottle_spec.rb +++ b/Library/Homebrew/test/dev-cmd/bottle_spec.rb @@ -511,11 +511,11 @@ describe "brew bottle" do bottle.sha256(catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e") expect(homebrew.bottle_output(bottle, nil)).to eq( - <<~RUBY.indent(2), - bottle do - root_url "https://example.com" - sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e" - end + <<-RUBY, + bottle do + root_url "https://example.com" + sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e" + end RUBY ) end @@ -526,12 +526,12 @@ describe "brew bottle" do bottle.sha256(catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e") expect(homebrew.bottle_output(bottle, "ExampleStrategy")).to eq( - <<~RUBY.indent(2), - bottle do - root_url "https://example.com", - using: ExampleStrategy - sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e" - end + <<-RUBY, + bottle do + root_url "https://example.com", + using: ExampleStrategy + sha256 catalina: "109c0cb581a7b5d84da36d84b221fb9dd0f8a927b3044d82611791c9907e202e" + end RUBY ) end diff --git a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb index 1d24822506..9bbb0d1cba 100644 --- a/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb +++ b/Library/Homebrew/test/support/helper/spec/shared_context/integration_test.rb @@ -177,7 +177,7 @@ RSpec.shared_context "integration test" do # rubocop:disable RSpec/ContextWordin Formulary.core_path(name).tap do |formula_path| formula_path.write <<~RUBY class #{Formulary.class_s(name)} < Formula - #{content.indent(2)} + #{content.gsub(/^(?!$)/, " ")} end RUBY end diff --git a/Library/Homebrew/test/utils/ast/ast_spec.rb b/Library/Homebrew/test/utils/ast/ast_spec.rb index 6eaf5f94f7..38fb349b69 100644 --- a/Library/Homebrew/test/utils/ast/ast_spec.rb +++ b/Library/Homebrew/test/utils/ast/ast_spec.rb @@ -5,12 +5,12 @@ require "utils/ast" describe Utils::AST do describe ".stanza_text" do let(:compound_license) do - <<~RUBY.chomp - license all_of: [ - :public_domain, - "MIT", - "GPL-3.0-or-later" => { with: "Autoconf-exception-3.0" }, - ] + <<-RUBY + license all_of: [ + :public_domain, + "MIT", + "GPL-3.0-or-later" => { with: "Autoconf-exception-3.0" }, + ] RUBY end @@ -36,14 +36,14 @@ describe Utils::AST do it "adds indent to stanza text if specified" do expect(described_class.stanza_text(:revision, "revision 1", indent: 2)).to eq(" revision 1") expect(described_class.stanza_text(:license, 'license "MIT"', indent: 2)).to eq(' license "MIT"') - expect(described_class.stanza_text(:license, compound_license, indent: 2)).to eq(compound_license.indent(2)) + expect(described_class.stanza_text(:license, compound_license, indent: 2)).to eq(compound_license) end it "does not add indent if already indented" do expect(described_class.stanza_text(:revision, " revision 1", indent: 2)).to eq(" revision 1") expect( - described_class.stanza_text(:license, compound_license.indent(2), indent: 2), - ).to eq(compound_license.indent(2)) + described_class.stanza_text(:license, compound_license, indent: 2), + ).to eq(compound_license) end end end diff --git a/Library/Homebrew/test/utils/ast/formula_ast_spec.rb b/Library/Homebrew/test/utils/ast/formula_ast_spec.rb index 386729b2c5..643b874f60 100644 --- a/Library/Homebrew/test/utils/ast/formula_ast_spec.rb +++ b/Library/Homebrew/test/utils/ast/formula_ast_spec.rb @@ -248,10 +248,10 @@ describe Utils::AST::FormulaAST do describe "#add_bottle_block" do let(:bottle_output) do - <<~RUBY.chomp.indent(2) - bottle do - sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sierra - end + <<-RUBY + bottle do + sha256 "f7b1fc772c79c20fddf621ccc791090bc1085fcef4da6cca03399424c66e06ca" => :sierra + end RUBY end diff --git a/Library/Homebrew/utils/ast.rb b/Library/Homebrew/utils/ast.rb index 116853d0f7..77ad0687b6 100644 --- a/Library/Homebrew/utils/ast.rb +++ b/Library/Homebrew/utils/ast.rb @@ -35,7 +35,7 @@ module Utils value if (node.is_a?(SendNode) || node.is_a?(BlockNode)) && node.method_name == name end text ||= "#{name} #{value.inspect}" - text = text.indent(indent) if indent && !text.match?(/\A\n* +/) + text = text.gsub(/^(?!$)/, " " * indent) if indent && !text.match?(/\A\n* +/) text end From 7b1a3c7535dd0a75d8196ecd2433cc1ff7a33519 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Mon, 8 Jan 2024 13:28:09 -0800 Subject: [PATCH 2/2] Remove ActiveSupport String indent core extension --- .gitignore | 1 - Library/Homebrew/global.rb | 1 - .../active_support/core_ext/string/indent.rb | 45 ------------------- 3 files changed, 47 deletions(-) delete mode 100644 Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/string/indent.rb diff --git a/.gitignore b/.gitignore index ea397973de..459a668d06 100644 --- a/.gitignore +++ b/.gitignore @@ -72,7 +72,6 @@ !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/deep_dup.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/object/duplicable.rb !**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/exclude.rb -!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/string/indent.rb # Ignore partially included gems where we don't need all files **/vendor/gems/mechanize-*/.* diff --git a/Library/Homebrew/global.rb b/Library/Homebrew/global.rb index fb76398eeb..691f5a3f98 100644 --- a/Library/Homebrew/global.rb +++ b/Library/Homebrew/global.rb @@ -18,7 +18,6 @@ require "active_support/core_ext/file/atomic" require "active_support/core_ext/hash/deep_merge" require "active_support/core_ext/hash/keys" require "active_support/core_ext/string/exclude" -require "active_support/core_ext/string/indent" HOMEBREW_API_DEFAULT_DOMAIN = ENV.fetch("HOMEBREW_API_DEFAULT_DOMAIN").freeze HOMEBREW_BOTTLE_DEFAULT_DOMAIN = ENV.fetch("HOMEBREW_BOTTLE_DEFAULT_DOMAIN").freeze diff --git a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/string/indent.rb b/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/string/indent.rb deleted file mode 100644 index af9d181487..0000000000 --- a/Library/Homebrew/vendor/bundle/ruby/3.1.0/gems/activesupport-6.1.7.6/lib/active_support/core_ext/string/indent.rb +++ /dev/null @@ -1,45 +0,0 @@ -# frozen_string_literal: true - -class String - # Same as +indent+, except it indents the receiver in-place. - # - # Returns the indented string, or +nil+ if there was nothing to indent. - def indent!(amount, indent_string = nil, indent_empty_lines = false) - indent_string = indent_string || self[/^[ \t]/] || " " - re = indent_empty_lines ? /^/ : /^(?!$)/ - gsub!(re, indent_string * amount) - end - - # Indents the lines in the receiver: - # - # < - # def some_method - # some_code - # end - # - # The second argument, +indent_string+, specifies which indent string to - # use. The default is +nil+, which tells the method to make a guess by - # peeking at the first indented line, and fallback to a space if there is - # none. - # - # " foo".indent(2) # => " foo" - # "foo\n\t\tbar".indent(2) # => "\t\tfoo\n\t\t\t\tbar" - # "foo".indent(2, "\t") # => "\t\tfoo" - # - # While +indent_string+ is typically one space or tab, it may be any string. - # - # The third argument, +indent_empty_lines+, is a flag that says whether - # empty lines should be indented. Default is false. - # - # "foo\n\nbar".indent(2) # => " foo\n\n bar" - # "foo\n\nbar".indent(2, nil, true) # => " foo\n \n bar" - # - def indent(amount, indent_string = nil, indent_empty_lines = false) - dup.tap { |_| _.indent!(amount, indent_string, indent_empty_lines) } - end -end