From fc6bd2ea1c2a810fa7bdef7e59f7c8ba81c209b2 Mon Sep 17 00:00:00 2001 From: Mike McQuaid Date: Sat, 20 Apr 2019 14:07:29 +0900 Subject: [PATCH] Fixup more frozen string handling. --- Library/Homebrew/cask/artifact/abstract_uninstall.rb | 6 +++--- Library/Homebrew/cask/cmd/abstract_command.rb | 3 +-- Library/Homebrew/cask/cmd/edit.rb | 4 ++-- Library/Homebrew/cask/cmd/info.rb | 4 ++-- Library/Homebrew/cask/installer.rb | 3 ++- Library/Homebrew/caveats.rb | 6 +++--- Library/Homebrew/dev-cmd/bottle.rb | 12 +++++++----- Library/Homebrew/dev-cmd/man.rb | 6 ++++-- Library/Homebrew/diagnostic.rb | 3 ++- Library/Homebrew/exceptions.rb | 4 ++-- Library/Homebrew/formula_installer.rb | 2 +- Library/Homebrew/missing_formula.rb | 4 ++-- Library/Homebrew/test/formula_spec.rb | 2 +- Library/Homebrew/test/inreplace_spec.rb | 2 +- Library/Homebrew/test/string_spec.rb | 2 +- Library/Homebrew/utils.rb | 7 ++++--- Library/Homebrew/utils/inreplace.rb | 4 ++-- 17 files changed, 40 insertions(+), 34 deletions(-) diff --git a/Library/Homebrew/cask/artifact/abstract_uninstall.rb b/Library/Homebrew/cask/artifact/abstract_uninstall.rb index 7261a054f8..82aa4fd467 100644 --- a/Library/Homebrew/cask/artifact/abstract_uninstall.rb +++ b/Library/Homebrew/cask/artifact/abstract_uninstall.rb @@ -94,10 +94,10 @@ module Cask sleep 1 end paths = [ - "/Library/LaunchAgents/#{service}.plist", - "/Library/LaunchDaemons/#{service}.plist", + +"/Library/LaunchAgents/#{service}.plist", + +"/Library/LaunchDaemons/#{service}.plist", ] - paths.each { |elt| elt.prepend(ENV["HOME"]) } unless with_sudo + paths.each { |elt| elt.prepend(ENV["HOME"]).freeze } unless with_sudo paths = paths.map { |elt| Pathname(elt) }.select(&:exist?) paths.each do |path| command.run!("/bin/rm", args: ["-f", "--", path], sudo: with_sudo) diff --git a/Library/Homebrew/cask/cmd/abstract_command.rb b/Library/Homebrew/cask/cmd/abstract_command.rb index faf0dd4edb..b08a3ea897 100644 --- a/Library/Homebrew/cask/cmd/abstract_command.rb +++ b/Library/Homebrew/cask/cmd/abstract_command.rb @@ -61,8 +61,7 @@ module Cask if matches.one? "Did you mean “#{matches.first}”?" elsif !matches.empty? - "Did you mean one of these?\n" - .concat(Formatter.columns(matches.take(20))) + "Did you mean one of these?\n#{Formatter.columns(matches.take(20))}" end end end diff --git a/Library/Homebrew/cask/cmd/edit.rb b/Library/Homebrew/cask/cmd/edit.rb index e7837a477d..7c65b18b27 100644 --- a/Library/Homebrew/cask/cmd/edit.rb +++ b/Library/Homebrew/cask/cmd/edit.rb @@ -12,9 +12,9 @@ module Cask def run exec_editor cask_path rescue CaskUnavailableError => e - reason = e.reason.empty? ? "" : "#{e.reason} " + reason = e.reason.empty? ? +"" : +"#{e.reason} " reason.concat("Run #{Formatter.identifier("brew cask create #{e.token}")} to create a new Cask.") - raise e.class.new(e.token, reason) + raise e.class.new(e.token, reason.freeze) end def cask_path diff --git a/Library/Homebrew/cask/cmd/info.rb b/Library/Homebrew/cask/cmd/info.rb index 0bc8187491..4453889935 100644 --- a/Library/Homebrew/cask/cmd/info.rb +++ b/Library/Homebrew/cask/cmd/info.rb @@ -106,14 +106,14 @@ module Cask end def self.artifact_info(cask) - artifact_output = ohai_title("Artifacts") + artifact_output = ohai_title("Artifacts").dup cask.artifacts.each do |artifact| next unless artifact.respond_to?(:install_phase) next unless DSL::ORDINARY_ARTIFACT_CLASSES.include?(artifact.class) artifact_output << "\n" << artifact.to_s end - artifact_output + artifact_output.freeze end end end diff --git a/Library/Homebrew/cask/installer.rb b/Library/Homebrew/cask/installer.rb index e25af65750..d59d7d3b4f 100644 --- a/Library/Homebrew/cask/installer.rb +++ b/Library/Homebrew/cask/installer.rb @@ -138,9 +138,10 @@ module Cask end def summary - s = "" + s = +"" s << "#{Emoji.install_badge} " if Emoji.enabled? s << "#{@cask} was successfully #{upgrade? ? "upgraded" : "installed"}!" + s.freeze end def download diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index e420867226..620f40dc79 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -42,7 +42,7 @@ class Caveats #{f.name} is keg-only, which means it was not symlinked into #{HOMEBREW_PREFIX}, because #{f.keg_only_reason.to_s.chomp}. EOS - end + end.dup if f.bin.directory? || f.sbin.directory? s << <<~EOS @@ -120,10 +120,10 @@ class Caveats #{root_dir}/share/zsh/site-functions EOS when :fish - fish_caveats = "fish #{installed.join(" and ")} have been installed to:" + fish_caveats = +"fish #{installed.join(" and ")} have been installed to:" fish_caveats << "\n #{root_dir}/share/fish/vendor_completions.d" if completion_installed fish_caveats << "\n #{root_dir}/share/fish/vendor_functions.d" if functions_installed - fish_caveats + fish_caveats.freeze end end diff --git a/Library/Homebrew/dev-cmd/bottle.rb b/Library/Homebrew/dev-cmd/bottle.rb index b5c22b39ef..7ff09281fe 100644 --- a/Library/Homebrew/dev-cmd/bottle.rb +++ b/Library/Homebrew/dev-cmd/bottle.rb @@ -1,4 +1,6 @@ -# frozen_string_literal: true +# Uses ERB so can't use Frozen String Literals until >=Ruby 2.4: +# https://bugs.ruby-lang.org/issues/12031 +# frozen_string_literal: false require "formula" require "utils/bottles" @@ -9,7 +11,7 @@ require "cli/parser" require "utils/inreplace" require "erb" -BOTTLE_ERB = <<-EOS +BOTTLE_ERB = <<-EOS.freeze bottle do <% if !["#{HOMEBREW_BOTTLE_DEFAULT_DOMAIN}/bottles", "https://homebrew.bintray.com/bottles"].include?(root_url) %> root_url "<%= root_url %>" @@ -41,7 +43,7 @@ module Homebrew def bottle_args Homebrew::CLI::Parser.new do - usage_banner <<~EOS + usage_banner <<~EOS.freeze `bottle` [] Generate a bottle (binary package) from a formula that was installed with @@ -378,7 +380,7 @@ module Homebrew "#{key}: old: #{old_value}, new: #{value}" end - odie <<~EOS + odie <<~EOS.freeze --keep-old was passed but there are changes in: #{mismatches.join("\n")} EOS @@ -489,7 +491,7 @@ module Homebrew end unless mismatches.empty? - odie <<~EOS + odie <<~EOS.freeze --keep-old was passed but there are changes in: #{mismatches.join("\n")} EOS diff --git a/Library/Homebrew/dev-cmd/man.rb b/Library/Homebrew/dev-cmd/man.rb index b8e871da0d..5e07666f0c 100644 --- a/Library/Homebrew/dev-cmd/man.rb +++ b/Library/Homebrew/dev-cmd/man.rb @@ -1,4 +1,6 @@ -# frozen_string_literal: true +# Uses ERB so can't use Frozen String Literals until >=Ruby 2.4: +# https://bugs.ruby-lang.org/issues/12031 +# frozen_string_literal: false require "formula" require "erb" @@ -16,7 +18,7 @@ module Homebrew def man_args Homebrew::CLI::Parser.new do - usage_banner <<~EOS + usage_banner <<~EOS.freeze `man` [] Generate Homebrew's manpages. diff --git a/Library/Homebrew/diagnostic.rb b/Library/Homebrew/diagnostic.rb index 23bbcfc890..c713faf749 100644 --- a/Library/Homebrew/diagnostic.rb +++ b/Library/Homebrew/diagnostic.rb @@ -71,7 +71,8 @@ module Homebrew end def inject_file_list(list, string) - list.reduce(string) { |acc, elem| acc << " #{elem}\n" } + list.reduce(string.dup) { |acc, elem| acc << " #{elem}\n" } + .freeze end ############# END HELPERS diff --git a/Library/Homebrew/exceptions.rb b/Library/Homebrew/exceptions.rb index 83bfce4779..5d6ca67cda 100644 --- a/Library/Homebrew/exceptions.rb +++ b/Library/Homebrew/exceptions.rb @@ -531,7 +531,7 @@ class ErrorDuringExecution < RuntimeError status end - s = "Failure while executing; `#{cmd.shelljoin.gsub(/\\=/, "=")}` exited with #{exitstatus}." + s = +"Failure while executing; `#{cmd.shelljoin.gsub(/\\=/, "=")}` exited with #{exitstatus}." unless [*output].empty? format_output_line = lambda do |type_line| @@ -548,7 +548,7 @@ class ErrorDuringExecution < RuntimeError s << "\n" unless s.end_with?("\n") end - super s + super s.freeze end def stderr diff --git a/Library/Homebrew/formula_installer.rb b/Library/Homebrew/formula_installer.rb index 215e45df32..09fd6822b0 100644 --- a/Library/Homebrew/formula_installer.rb +++ b/Library/Homebrew/formula_installer.rb @@ -666,7 +666,7 @@ class FormulaInstaller end def summary - s = "" + s = +"" s << "#{Emoji.install_badge} " if Emoji.enabled? s << "#{formula.prefix.resolved_path}: #{formula.prefix.abv}" s << ", built in #{pretty_duration build_time}" if build_time diff --git a/Library/Homebrew/missing_formula.rb b/Library/Homebrew/missing_formula.rb index b3778677af..7fe246c338 100644 --- a/Library/Homebrew/missing_formula.rb +++ b/Library/Homebrew/missing_formula.rb @@ -200,9 +200,9 @@ module Homebrew return if silent cask = Cask::CaskLoader.load(name) - reason = "Found a cask named \"#{name}\" instead.\n" + reason = +"Found a cask named \"#{name}\" instead.\n" reason << Cask::Cmd::Info.get_info(cask) if show_info - reason + reason.freeze rescue Cask::CaskUnavailableError nil end diff --git a/Library/Homebrew/test/formula_spec.rb b/Library/Homebrew/test/formula_spec.rb index 5e7e885f9a..b762115950 100644 --- a/Library/Homebrew/test/formula_spec.rb +++ b/Library/Homebrew/test/formula_spec.rb @@ -382,7 +382,7 @@ describe Formula do stamps_with_revisions.each do |stamp, revision| version = "HEAD-#{stamp}" - version << "_#{revision}" unless revision.zero? + version = "#{version}_#{revision}" unless revision.zero? prefix = f.rack/version prefix.mkpath diff --git a/Library/Homebrew/test/inreplace_spec.rb b/Library/Homebrew/test/inreplace_spec.rb index 0500e1ca49..2491c8b870 100644 --- a/Library/Homebrew/test/inreplace_spec.rb +++ b/Library/Homebrew/test/inreplace_spec.rb @@ -5,7 +5,7 @@ require "tempfile" require "utils/inreplace" describe StringInreplaceExtension do - subject { string.extend(described_class) } + subject { string.dup.extend(described_class) } describe "#change_make_var!" do context "flag" do diff --git a/Library/Homebrew/test/string_spec.rb b/Library/Homebrew/test/string_spec.rb index 687cf559b3..ed9cdc2deb 100644 --- a/Library/Homebrew/test/string_spec.rb +++ b/Library/Homebrew/test/string_spec.rb @@ -5,7 +5,7 @@ require "extend/string" describe StringInreplaceExtension do subject { string.extend(described_class) } - let(:string) { "foobar" } + let(:string) { +"foobar" } describe "#sub!" do it "adds an error to #errors when no replacement was made" do diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index 057a2881d2..e68d561789 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -113,8 +113,9 @@ def odeprecated(method, replacement = nil, disable: false, disable_on: nil, call break end - message = "Calling #{method} is #{verb}! #{replacement_message}" + message = +"Calling #{method} is #{verb}! #{replacement_message}" message << tap_message if tap_message + message.freeze if ARGV.homebrew_developer? || disable || Homebrew.raise_deprecation_exceptions? exception = MethodDeprecatedError.new(message) @@ -152,12 +153,12 @@ end def pretty_duration(s) s = s.to_i - res = "" + res = +"" if s > 59 m = s / 60 s %= 60 - res = "#{m} #{"minute".pluralize(m)}" + res = +"#{m} #{"minute".pluralize(m)}" return res.freeze if s.zero? res << " " diff --git a/Library/Homebrew/utils/inreplace.rb b/Library/Homebrew/utils/inreplace.rb index 448d08fd8c..3bce563f7c 100644 --- a/Library/Homebrew/utils/inreplace.rb +++ b/Library/Homebrew/utils/inreplace.rb @@ -3,10 +3,10 @@ module Utils class InreplaceError < RuntimeError def initialize(errors) - formatted_errors = errors.reduce("inreplace failed\n") do |s, (path, errs)| + formatted_errors = errors.reduce(+"inreplace failed\n") do |s, (path, errs)| s << "#{path}:\n" << errs.map { |e| " #{e}\n" }.join end - super formatted_errors + super formatted_errors.freeze end end