diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1739b6d3..d767990f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -125,18 +125,6 @@ Security/Eval: - 'spec/indent_spec.rb' - 'spec/wrapped_module_spec.rb' -# Offense count: 9 -# Configuration parameters: EnforcedStyle. -# SupportedStyles: inline, group -Style/AccessModifierDeclarations: - Exclude: - - 'lib/pry/command.rb' - - 'lib/pry/forwardable.rb' - - 'lib/pry/helpers/base_helpers.rb' - - 'lib/pry/pry_instance.rb' - - 'spec/editor_spec.rb' - - 'spec/method/patcher_spec.rb' - # Offense count: 39 Style/CaseEquality: Enabled: false diff --git a/lib/pry/command.rb b/lib/pry/command.rb index c1ce8094..d10e252b 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -411,40 +411,6 @@ class Pry call_safely(*(captures + args)) end - # Pass a block argument to a command. - # @param [String] arg_string The arguments (as a string) passed to the command. - # We inspect these for a '| do' or a '| {' and if we find it we use it - # to start a block input sequence. Once we have a complete - # block, we save it to an accessor that can be retrieved from the command context. - # Note that if we find the '| do' or '| {' we delete this and the - # elements following it from `arg_string`. - def pass_block(arg_string) - # Workaround for weird JRuby bug where rindex in this case can return nil - # even when there's a match. - arg_string.scan(/\| *(?:do|\{)/) - block_index = $LAST_MATCH_INFO && $LAST_MATCH_INFO.offset(0)[0] - - return unless block_index - - block_init_string = arg_string.slice!(block_index..-1)[1..-1] - prime_string = "proc #{block_init_string}\n" - - block_string = - if !Pry::Code.complete_expression?(prime_string) - pry_instance.r(target, prime_string) - else - prime_string - end - - begin - self.command_block = target.eval(block_string) - rescue Pry::RescuableException - raise CommandError, "Incomplete block definition." - end - end - - private :pass_block - # Run the command with the given `args`. # # This is a public wrapper around `#call` which ensures all preconditions @@ -482,6 +448,38 @@ class Pry private + # Pass a block argument to a command. + # @param [String] arg_string The arguments (as a string) passed to the command. + # We inspect these for a '| do' or a '| {' and if we find it we use it + # to start a block input sequence. Once we have a complete + # block, we save it to an accessor that can be retrieved from the command context. + # Note that if we find the '| do' or '| {' we delete this and the + # elements following it from `arg_string`. + def pass_block(arg_string) + # Workaround for weird JRuby bug where rindex in this case can return nil + # even when there's a match. + arg_string.scan(/\| *(?:do|\{)/) + block_index = $LAST_MATCH_INFO && $LAST_MATCH_INFO.offset(0)[0] + + return unless block_index + + block_init_string = arg_string.slice!(block_index..-1)[1..-1] + prime_string = "proc #{block_init_string}\n" + + block_string = + if !Pry::Code.complete_expression?(prime_string) + pry_instance.r(target, prime_string) + else + prime_string + end + + begin + self.command_block = target.eval(block_string) + rescue Pry::RescuableException + raise CommandError, "Incomplete block definition." + end + end + def find_hooks(event) event_name = "#{event}_#{command_name}" (hooks || self.class.hooks).get_hooks(event_name).values diff --git a/lib/pry/editor.rb b/lib/pry/editor.rb index 1cb531f0..69eab568 100644 --- a/lib/pry/editor.rb +++ b/lib/pry/editor.rb @@ -36,8 +36,6 @@ class Pry end end - private - # Generate the string that's used to start the editor. This includes # all the flags we want as well as the file and line number we # want to open at. @@ -54,6 +52,8 @@ class Pry end end + private + # Start the editor running, using the calculated invocation string def open_editor(editor_invocation) # Note we dont want to use Pry.config.system here as that diff --git a/lib/pry/forwardable.rb b/lib/pry/forwardable.rb index bc432842..1e0674d4 100644 --- a/lib/pry/forwardable.rb +++ b/lib/pry/forwardable.rb @@ -17,7 +17,9 @@ class Pry instance_variable_get(target).__send__(private_delegate, *a, &b) end end - class_eval { private(*private_delegates) } + class_eval do + private(*private_delegates) # rubocop:disable Style/AccessModifierDeclarations + end end end end diff --git a/lib/pry/helpers/base_helpers.rb b/lib/pry/helpers/base_helpers.rb index 94285ca8..b8c6bff6 100644 --- a/lib/pry/helpers/base_helpers.rb +++ b/lib/pry/helpers/base_helpers.rb @@ -23,7 +23,6 @@ class Pry (Module === obj ? Module : Object).instance_method(method) .bind(obj).call(*args, &block) end - public :safe_send def find_command(name, set = Pry::Commands) command_match = set.find do |_, command| diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index 189c8763..e7f99f0e 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -349,7 +349,7 @@ class Pry throw(:breakout) if current_binding.nil? end - private :handle_line + private :handle_line # rubocop:disable Style/AccessModifierDeclarations # Potentially deprecated. Use `Pry::REPL.new(pry, :target => target).start` # (If nested sessions are going to exist, this method is fine, but a goal is @@ -401,7 +401,7 @@ class Pry @eval_string.force_encoding(val.encoding) end end - private :ensure_correct_encoding! + private :ensure_correct_encoding! # rubocop:disable Style/AccessModifierDeclarations # If the given line is a valid command, process it in the context of the # current `eval_string` and binding. @@ -591,13 +591,13 @@ class Pry prompt_proc.call(conf.object, conf.nesting_level, conf.pry_instance) end end - private :generate_prompt + private :generate_prompt # rubocop:disable Style/AccessModifierDeclarations # the array that the prompt stack is stored in def prompt_stack @prompt_stack ||= [] end - private :prompt_stack + private :prompt_stack # rubocop:disable Style/AccessModifierDeclarations # Pushes the current prompt onto a stack that it can be restored from later. # Use this if you wish to temporarily change the prompt. diff --git a/spec/editor_spec.rb b/spec/editor_spec.rb index 5fd2ff99..f23d815a 100644 --- a/spec/editor_spec.rb +++ b/spec/editor_spec.rb @@ -1,12 +1,6 @@ require 'pathname' describe Pry::Editor do - class Pry - class Editor - public :build_editor_invocation_string - end - end - before do # OS-specific tempdir name. For GNU/Linux it's "tmp", for Windows it's # something "Temp". diff --git a/spec/method/patcher_spec.rb b/spec/method/patcher_spec.rb index 2408b03f..24524d02 100644 --- a/spec/method/patcher_spec.rb +++ b/spec/method/patcher_spec.rb @@ -25,7 +25,9 @@ describe Pry::Method::Patcher do end it "should preserve visibility" do - class << @x; private :test; end + class << @x + private :test # rubocop:disable Style/AccessModifierDeclarations + end expect(@method.visibility).to eq :private @method.redefine "def @x.test; :after; end\n" expect(Pry::Method(@x.method(:test)).visibility).to eq :private