From 2dae2fd63a779670263fd761f6fea232e7092d6a Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Sun, 2 Jul 2017 12:00:43 +1000 Subject: [PATCH] Updates so things work with frozen string literals --- lib/thor/actions.rb | 2 +- lib/thor/actions/file_manipulation.rb | 5 +++-- lib/thor/base.rb | 2 +- lib/thor/command.rb | 8 ++++---- lib/thor/group.rb | 2 +- lib/thor/parser/option.rb | 4 ++-- lib/thor/shell/basic.rb | 12 ++++++------ spec/actions_spec.rb | 2 +- spec/group_spec.rb | 4 ++-- spec/thor_spec.rb | 2 +- 10 files changed, 22 insertions(+), 21 deletions(-) diff --git a/lib/thor/actions.rb b/lib/thor/actions.rb index 4319516c8..b833e71c2 100644 --- a/lib/thor/actions.rb +++ b/lib/thor/actions.rb @@ -140,7 +140,7 @@ def find_in_source_paths(file) end end - message = "Could not find #{file.inspect} in any of your source paths. " + message = "Could not find #{file.inspect} in any of your source paths. ".dup unless self.class.source_root message << "Please invoke #{self.class.name}.source_root(PATH) with the PATH containing your templates. " diff --git a/lib/thor/actions/file_manipulation.rb b/lib/thor/actions/file_manipulation.rb index 63474c053..c8287531e 100644 --- a/lib/thor/actions/file_manipulation.rb +++ b/lib/thor/actions/file_manipulation.rb @@ -340,7 +340,8 @@ def capture(*args) with_output_buffer { yield(*args) } end - def with_output_buffer(buf = "") #:nodoc: + def with_output_buffer(buf = "".dup) #:nodoc: + raise "No: #{buf}" if buf.frozen? old_buffer = output_buffer self.output_buffer = buf yield @@ -355,7 +356,7 @@ class CapturableERB < ERB def set_eoutvar(compiler, eoutvar = "_erbout") compiler.put_cmd = "#{eoutvar}.concat" compiler.insert_cmd = "#{eoutvar}.concat" - compiler.pre_cmd = ["#{eoutvar} = ''"] + compiler.pre_cmd = ["#{eoutvar} = ''.dup"] compiler.post_cmd = [eoutvar] end end diff --git a/lib/thor/base.rb b/lib/thor/base.rb index bb6fd4f73..6c45a90d6 100644 --- a/lib/thor/base.rb +++ b/lib/thor/base.rb @@ -485,7 +485,7 @@ def handle_no_command_error(command, has_namespace = $thor_runner) #:nodoc: def handle_argument_error(command, error, args, arity) #:nodoc: name = [command.ancestor_name, command.name].compact.join(" ") - msg = "ERROR: \"#{basename} #{name}\" was called with " + msg = "ERROR: \"#{basename} #{name}\" was called with ".dup msg << "no arguments" if args.empty? msg << "arguments " << args.inspect unless args.empty? msg << "\nUsage: #{banner(command).inspect}" diff --git a/lib/thor/command.rb b/lib/thor/command.rb index 6ed21d8c6..e3487ce5d 100644 --- a/lib/thor/command.rb +++ b/lib/thor/command.rb @@ -40,14 +40,14 @@ def run(instance, args = []) # and required options into the given usage. def formatted_usage(klass, namespace = true, subcommand = false) if ancestor_name - formatted = "#{ancestor_name} " # add space + formatted = "#{ancestor_name} ".dup # add space elsif namespace namespace = klass.namespace - formatted = "#{namespace.gsub(/^(default)/, '')}:" + formatted = "#{namespace.gsub(/^(default)/, '')}:".dup end - formatted ||= "#{klass.namespace.split(':').last} " if subcommand + formatted ||= "#{klass.namespace.split(':').last} ".dup if subcommand - formatted ||= "" + formatted ||= "".dup # Add usage with required arguments formatted << if klass && !klass.arguments.empty? diff --git a/lib/thor/group.rb b/lib/thor/group.rb index dd435475e..f6c9e20e1 100644 --- a/lib/thor/group.rb +++ b/lib/thor/group.rb @@ -205,7 +205,7 @@ def printable_commands(*) alias_method :printable_tasks, :printable_commands def handle_argument_error(command, error, _args, arity) #:nodoc: - msg = "#{basename} #{command.name} takes #{arity} argument" + msg = "#{basename} #{command.name} takes #{arity} argument".dup msg << "s" if arity > 1 msg << ", but it should not." raise error, msg diff --git a/lib/thor/parser/option.rb b/lib/thor/parser/option.rb index cb34d1ffd..36db2574b 100644 --- a/lib/thor/parser/option.rb +++ b/lib/thor/parser/option.rb @@ -80,12 +80,12 @@ def human_name def usage(padding = 0) sample = if banner && !banner.to_s.empty? - "#{switch_name}=#{banner}" + "#{switch_name}=#{banner}".dup else switch_name end - sample = "[#{sample}]" unless required? + sample = "[#{sample}]".dup unless required? if boolean? sample << ", [#{dasherize('no-' + human_name)}]" unless (name == "force") || name.start_with?("no-") diff --git a/lib/thor/shell/basic.rb b/lib/thor/shell/basic.rb index 0819e852a..eda8ef67a 100644 --- a/lib/thor/shell/basic.rb +++ b/lib/thor/shell/basic.rb @@ -107,7 +107,7 @@ def say_status(status, message, log_status = true) status = set_color status, color, true if color buffer = "#{status}#{spaces}#{message}" - buffer << "\n" unless buffer.end_with?("\n") + buffer = "#{buffer}\n" unless buffer.end_with?("\n") stdout.print(buffer) stdout.flush @@ -162,7 +162,7 @@ def print_table(array, options = {}) # rubocop:disable MethodLength colwidth = options[:colwidth] options[:truncate] = terminal_width if options[:truncate] == true - formats << "%-#{colwidth + 2}s" if colwidth + formats << "%-#{colwidth + 2}s".dup if colwidth start = colwidth ? 1 : 0 colcount = array.max { |a, b| a.size <=> b.size }.size @@ -174,9 +174,9 @@ def print_table(array, options = {}) # rubocop:disable MethodLength maximas << maxima formats << if index == colcount - 1 # Don't output 2 trailing spaces when printing the last column - "%-s" + "%-s".dup else - "%-#{maxima + 2}s" + "%-#{maxima + 2}s".dup end end @@ -184,7 +184,7 @@ def print_table(array, options = {}) # rubocop:disable MethodLength formats << "%s" array.each do |row| - sentence = "" + sentence = "".dup row.each_with_index do |column, index| maxima = maximas[index] @@ -409,7 +409,7 @@ def ask_simply(statement, color, options) return unless result - result.strip! + result = result.strip if default && result == "" default diff --git a/spec/actions_spec.rb b/spec/actions_spec.rb index 12e304311..700d9ae60 100644 --- a/spec/actions_spec.rb +++ b/spec/actions_spec.rb @@ -204,7 +204,7 @@ def file describe "#apply" do before do - @template = <<-TEMPLATE + @template = <<-TEMPLATE.dup @foo = "FOO" say_status :cool, :padding TEMPLATE diff --git a/spec/group_spec.rb b/spec/group_spec.rb index e6fe02d46..5a088c190 100644 --- a/spec/group_spec.rb +++ b/spec/group_spec.rb @@ -190,7 +190,7 @@ class_option :loud, :type => :boolean def hi - name.upcase! if options[:loud] + self.name = name.upcase if options[:loud] "Hi #{name}" end end @@ -207,7 +207,7 @@ def hi class_option :loud, :type => :boolean def hi - name.upcase! if options[:loud] + self.name = name.upcase if options[:loud] out = "Hi #{name}" out << ": " << args.join(", ") unless args.empty? out diff --git a/spec/thor_spec.rb b/spec/thor_spec.rb index b0431f570..413927003 100644 --- a/spec/thor_spec.rb +++ b/spec/thor_spec.rb @@ -531,7 +531,7 @@ def bar; end method_option :loud, :type => :boolean desc "hi NAME", "say hi to name" def hi(name) - name.upcase! if options[:loud] + name = name.upcase if options[:loud] "Hi #{name}" end end