From 0e06fc6ab27a88f7c451fc7de9645f7cab050ad9 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sun, 11 Sep 2022 15:15:36 -0700 Subject: [PATCH 1/2] Complete Style/SymbolArray todo --- .rubocop.yml | 4 ---- lib/pry/basic_object.rb | 2 +- lib/pry/commands/ls/constants.rb | 4 ++-- lib/pry/commands/watch_expression.rb | 2 +- lib/pry/indent.rb | 12 ++++++------ lib/pry/input_completer.rb | 2 +- lib/pry/wrapped_module/candidate.rb | 6 +++--- spec/commands/show_source_spec.rb | 18 +++++++++--------- spec/integration/cli_spec.rb | 2 +- 9 files changed, 24 insertions(+), 28 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c86553e5..b2d48332 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -51,10 +51,6 @@ Style/SingleLineMethods: Style/StringLiterals: Enabled: false -# TODO: delete this rule when we drop Ruby 1.9.3 support. -Style/SymbolArray: - EnforcedStyle: brackets - Metrics/LineLength: Max: 90 diff --git a/lib/pry/basic_object.rb b/lib/pry/basic_object.rb index 73e58eba..fca81d86 100644 --- a/lib/pry/basic_object.rb +++ b/lib/pry/basic_object.rb @@ -2,7 +2,7 @@ class Pry class BasicObject < BasicObject - [:Kernel, :File, :Dir, :LoadError, :ENV, :Pry].each do |constant| + %i[Kernel File Dir LoadError ENV Pry].each do |constant| const_set constant, ::Object.const_get(constant) end include Kernel diff --git a/lib/pry/commands/ls/constants.rb b/lib/pry/commands/ls/constants.rb index c0f50458..b70a12df 100644 --- a/lib/pry/commands/ls/constants.rb +++ b/lib/pry/commands/ls/constants.rb @@ -4,8 +4,8 @@ class Pry class Command class Ls < Pry::ClassCommand class Constants < Pry::Command::Ls::Formatter - DEPRECATED_CONSTANTS = [ - :Data, :Fixnum, :Bignum, :TimeoutError, :NIL, :FALSE, :TRUE + DEPRECATED_CONSTANTS = %i[ + Data Fixnum Bignum TimeoutError NIL FALSE TRUE ].tap do |constants| constants << :JavaPackageModuleTemplate if Helpers::Platform.jruby? end diff --git a/lib/pry/commands/watch_expression.rb b/lib/pry/commands/watch_expression.rb index f732a53f..3bdb3998 100644 --- a/lib/pry/commands/watch_expression.rb +++ b/lib/pry/commands/watch_expression.rb @@ -96,7 +96,7 @@ class Pry end def add_hook - hook = [:after_eval, :watch_expression] + hook = %i[after_eval watch_expression] return if pry_instance.hooks.hook_exists?(*hook) pry_instance.hooks.add_hook(*hook) do |_, pry_instance| diff --git a/lib/pry/indent.rb b/lib/pry/indent.rb index 2d19d87e..7ef284a7 100644 --- a/lib/pry/indent.rb +++ b/lib/pry/indent.rb @@ -57,8 +57,8 @@ class Pry # # :pre_constant and :preserved_constant are the CodeRay 0.9.8 and 1.0.0 # classifications of "true", "false", and "nil". - IGNORE_TOKENS = [:space, :content, :string, :method, :ident, - :constant, :pre_constant, :predefined_constant].freeze + IGNORE_TOKENS = %i[space content string method ident + constant pre_constant predefined_constant].freeze # Tokens that indicate the end of a statement (i.e. that, if they appear # directly before an "if" indicates that that if applies to the same line, @@ -66,10 +66,10 @@ class Pry # # :reserved and :keywords are the CodeRay 0.9.8 and 1.0.0 respectively # classifications of "super", "next", "return", etc. - STATEMENT_END_TOKENS = IGNORE_TOKENS + [:regexp, :integer, :float, - :keyword, :delimiter, :reserved, - :instance_variable, - :class_variable, :global_variable] + STATEMENT_END_TOKENS = IGNORE_TOKENS + %i[regexp integer float + keyword delimiter reserved + instance_variable + class_variable global_variable] # Collection of tokens that should appear dedented even though they # don't affect the surrounding code. diff --git a/lib/pry/input_completer.rb b/lib/pry/input_completer.rb index 9566b32d..3059d4b6 100644 --- a/lib/pry/input_completer.rb +++ b/lib/pry/input_completer.rb @@ -270,7 +270,7 @@ class Pry end # FIXME: Add Pry here as well? - [:IRB, :SLex, :RubyLex, :RubyToken].each do |module_name| + %i[IRB SLex RubyLex RubyToken].each do |module_name| next unless Object.const_defined?(module_name) scanner.call(Object.const_get(module_name)) diff --git a/lib/pry/wrapped_module/candidate.rb b/lib/pry/wrapped_module/candidate.rb index 7a0c3d66..c333e8e6 100644 --- a/lib/pry/wrapped_module/candidate.rb +++ b/lib/pry/wrapped_module/candidate.rb @@ -20,9 +20,9 @@ class Pry # Methods to delegate to associated `Pry::WrappedModule # instance`. - private_delegates = [:lines_for_file, :method_candidates, :yard_docs?, :name] - public_delegates = [:wrapped, :module?, :class?, :nonblank_name, - :number_of_candidates] + private_delegates = %i[lines_for_file method_candidates yard_docs? name] + public_delegates = %i[wrapped module? class? nonblank_name + number_of_candidates] def_delegators :@wrapper, *public_delegates def_private_delegators :@wrapper, *private_delegates diff --git a/spec/commands/show_source_spec.rb b/spec/commands/show_source_spec.rb index d436ef2a..e6b8acff 100644 --- a/spec/commands/show_source_spec.rb +++ b/spec/commands/show_source_spec.rb @@ -1151,7 +1151,7 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength end after do - [:BetaClass, :AlphaClass].each { |name| Object.remove_const(name) } + %i[BetaClass AlphaClass].each { |name| Object.remove_const(name) } end it "shows docs for the nested classes" do @@ -1176,7 +1176,7 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength end after do - [:BetaClass, :AlphaClass].each { |name| Object.remove_const(name) } + %i[BetaClass AlphaClass].each { |name| Object.remove_const(name) } end it "shows docs for the nested classes" do @@ -1386,7 +1386,7 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength end after do - [:Child, :Parent].each { |name| Object.remove_const(name) } + %i[Child Parent].each { |name| Object.remove_const(name) } end it "shows the docs of the superclass" do @@ -1412,7 +1412,7 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength end after do - [:Grandparent, :Child, :Parent].each { |name| Object.remove_const(name) } + %i[Grandparent Child Parent].each { |name| Object.remove_const(name) } end it "shows the docs of the superclass" do @@ -1437,7 +1437,7 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength end after do - [:Child, :Parent].each { |name| Object.remove_const(name) } + %i[Child Parent].each { |name| Object.remove_const(name) } end it "raises Pry::CommandError" do @@ -1459,7 +1459,7 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength end after do - [:Beta, :Alpha].each { |name| Object.remove_const(name) } + %i[Beta Alpha].each { |name| Object.remove_const(name) } end it "shows the included module's doc" do @@ -1486,7 +1486,7 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength end after do - [:Beta, :Alpha].each { |name| Object.remove_const(name) } + %i[Beta Alpha].each { |name| Object.remove_const(name) } end it "raises Pry::CommandError" do @@ -1512,7 +1512,7 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength end after do - [:Gamma, :Beta, :Alpha].each { |name| Object.remove_const(name) } + %i[Gamma Beta Alpha].each { |name| Object.remove_const(name) } end it "shows nth level included module doc" do @@ -1550,7 +1550,7 @@ describe "show-source" do # rubocop:disable Metrics/BlockLength end after do - [:Grandparent, :Parent, :Child].each { |name| Object.remove_const(name) } + %i[Grandparent Parent Child].each { |name| Object.remove_const(name) } end context "and when it's passed once" do diff --git a/spec/integration/cli_spec.rb b/spec/integration/cli_spec.rb index ec5298e7..b7657dae 100644 --- a/spec/integration/cli_spec.rb +++ b/spec/integration/cli_spec.rb @@ -13,7 +13,7 @@ RSpec.describe 'The bin/pry CLI' do pry_dir, 'bin/pry', *args, - err: [:child, :out]], &:read) + err: %i[child out]], &:read) status = $CHILD_STATUS # Pry will emit silent garbage because of our auto indent feature. From 6c2e2f54aee332b0cc72484d0fc1bb401605a428 Mon Sep 17 00:00:00 2001 From: Douglas Eichelberger Date: Sun, 11 Sep 2022 15:16:17 -0700 Subject: [PATCH 2/2] Complete Style/ExpandPathArguments todo --- .rubocop.yml | 6 ------ pry.gemspec | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b2d48332..e015d7c5 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -33,12 +33,6 @@ Style/ClassAndModuleChildren: Exclude: - 'spec/fixtures/example_nesting.rb' -# TODO: delete exclusions when we drop Ruby 1.9.3 support. -Style/ExpandPathArguments: - Exclude: - - 'lib/pry/commands.rb' - - 'pry.gemspec' - Style/Semicolon: Exclude: - 'spec/method_spec.rb' diff --git a/pry.gemspec b/pry.gemspec index db5826d3..2beef842 100644 --- a/pry.gemspec +++ b/pry.gemspec @@ -1,6 +1,6 @@ # frozen_string_literal: true -require File.expand_path('../lib/pry/version', __FILE__) +require File.expand_path('lib/pry/version', __dir__) Gem::Specification.new do |s| s.name = "pry"