diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 2ec6971a..47023039 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -203,14 +203,6 @@ Style/AsciiComments: Style/CaseEquality: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: is_a?, kind_of? -Style/ClassCheck: - Exclude: - - 'lib/pry/pry_class.rb' - # Offense count: 1 Style/ClassVars: Exclude: @@ -221,19 +213,6 @@ Style/CommentedKeyword: Exclude: - 'spec/fixtures/example_nesting.rb' -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SingleLineConditionsOnly, IncludeTernaryExpressions. -# SupportedStyles: assign_to_condition, assign_inside_condition -Style/ConditionalAssignment: - Exclude: - - 'lib/pry/command.rb' - - 'lib/pry/commands/easter_eggs.rb' - - 'lib/pry/commands/gist.rb' - - 'lib/pry/indent.rb' - - 'lib/pry/testable/pry_tester.rb' - - 'lib/pry/wrapped_module.rb' - # Offense count: 154 Style/Documentation: Enabled: false @@ -251,53 +230,6 @@ Style/DoubleNegation: - 'lib/pry/slop/option.rb' - 'lib/pry/wrapped_module.rb' -# Offense count: 6 -# Cop supports --auto-correct. -Style/EmptyCaseCondition: - Exclude: - - 'lib/pry/command.rb' - - 'lib/pry/commands/cat.rb' - - 'lib/pry/commands/code_collector.rb' - - 'lib/pry/commands/edit.rb' - - 'lib/pry/commands/hist.rb' - - 'lib/pry/commands/watch_expression.rb' - -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: empty, nil, both -Style/EmptyElse: - Exclude: - - 'lib/pry/code_object.rb' - - 'lib/pry/config/behavior.rb' - - 'lib/pry/pry_instance.rb' - - 'lib/pry/terminal.rb' - - 'lib/pry/wrapped_module.rb' - -# Offense count: 2 -# Cop supports --auto-correct. -Style/EmptyLiteral: - Exclude: - - 'lib/pry/pry_instance.rb' - - 'spec/method_spec.rb' - -# Offense count: 42 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle. -# SupportedStyles: compact, expanded -Style/EmptyMethod: - Exclude: - - 'lib/pry/pager.rb' - - 'spec/code_object_spec.rb' - - 'spec/commands/show_doc_spec.rb' - - 'spec/commands/show_source_spec.rb' - - 'spec/completion_spec.rb' - - 'spec/fixtures/candidate_helper1.rb' - - 'spec/fixtures/candidate_helper2.rb' - - 'spec/fixtures/show_source_doc_examples.rb' - - 'spec/method_spec.rb' - - 'spec/wrapped_module_spec.rb' - # Offense count: 2 # Cop supports --auto-correct. Style/Encoding: diff --git a/lib/pry/code_object.rb b/lib/pry/code_object.rb index f295f90f..f35a8e89 100644 --- a/lib/pry/code_object.rb +++ b/lib/pry/code_object.rb @@ -122,8 +122,6 @@ class Pry Pry::Method(obj) elsif !obj.is_a?(Module) Pry::WrappedModule(obj.class) - else - nil end end rescue Pry::RescuableException diff --git a/lib/pry/command.rb b/lib/pry/command.rb index 68dee7ab..9d7facbd 100644 --- a/lib/pry/command.rb +++ b/lib/pry/command.rb @@ -349,11 +349,12 @@ class Pry # process and pass a block if one is found pass_block(arg_string) if command_options[:takes_block] - if arg_string - args = command_options[:shellwords] ? Shellwords.shellwords(arg_string) : arg_string.split(" ") - else - args = [] - end + args = + if arg_string + command_options[:shellwords] ? Shellwords.shellwords(arg_string) : arg_string.split(" ") + else + [] + end [val[0..pos].rstrip, arg_string, captures, args] end @@ -390,11 +391,12 @@ class Pry block_init_string = arg_string.slice!(block_index..-1)[1..-1] prime_string = "proc #{block_init_string}\n" - if !Pry::Code.complete_expression?(prime_string) - block_string = _pry_.r(target, prime_string) - else - block_string = prime_string - end + block_string = + if !Pry::Code.complete_expression?(prime_string) + _pry_.r(target, prime_string) + else + prime_string + end begin self.command_block = target.eval(block_string) @@ -495,12 +497,11 @@ WARN # @param [Array] args The arguments to pass # @return [Array] A (possibly shorter) array of the arguments to pass def correct_arg_arity(arity, args) - case - when arity < 0 + if arity < 0 args - when arity == 0 + elsif arity == 0 [] - when arity > 0 + elsif arity > 0 args.values_at(*(0..(arity - 1)).to_a) end end diff --git a/lib/pry/commands/cat.rb b/lib/pry/commands/cat.rb index 4bc445f5..6ca2c76c 100644 --- a/lib/pry/commands/cat.rb +++ b/lib/pry/commands/cat.rb @@ -33,10 +33,9 @@ class Pry end def process - output = case - when opts.present?(:ex) + output = if opts.present?(:ex) ExceptionFormatter.new(_pry_.last_exception, _pry_, opts).format - when opts.present?(:in) + elsif opts.present?(:in) InputExpressionFormatter.new(_pry_.input_ring, opts).format else FileFormatter.new(args.first, _pry_, opts).format diff --git a/lib/pry/commands/code_collector.rb b/lib/pry/commands/code_collector.rb index d8344309..6253f2ab 100644 --- a/lib/pry/commands/code_collector.rb +++ b/lib/pry/commands/code_collector.rb @@ -56,12 +56,11 @@ class Pry begin raise CommandError, "Only one of --out, --in, --doc and CODE_OBJECT may be specified." if bad_option_combination? - content = case - when opts.present?(:o) + content = if opts.present?(:o) pry_output_content - when opts.present?(:i) + elsif opts.present?(:i) pry_input_content - when opts.present?(:d) + elsif opts.present?(:d) code_object_doc else code_object_source_or_file diff --git a/lib/pry/commands/easter_eggs.rb b/lib/pry/commands/easter_eggs.rb index 755f78e2..c3cf3145 100644 --- a/lib/pry/commands/easter_eggs.rb +++ b/lib/pry/commands/easter_eggs.rb @@ -95,11 +95,12 @@ class Pry \____/ \________________________| EOS - if Helpers::Platform.windows_ansi? - move_up = proc { |n| "\e[#{n}F" } - else - move_up = proc { |n| "\e[#{n}A\e[0G" } - end + move_up = + if Helpers::Platform.windows_ansi? + proc { |n| "\e[#{n}F" } + else + proc { |n| "\e[#{n}A\e[0G" } + end output.puts "\n" * 6 output.puts picture.lines.map(&:chomp).reverse.join(move_up[1]) diff --git a/lib/pry/commands/edit.rb b/lib/pry/commands/edit.rb index 8861f325..3ea4d5c6 100644 --- a/lib/pry/commands/edit.rb +++ b/lib/pry/commands/edit.rb @@ -183,12 +183,11 @@ class Pry end def initial_temp_file_content - case - when opts.present?(:temp) + if opts.present?(:temp) "" - when opts.present?(:in) + elsif opts.present?(:in) input_expression - when eval_string.strip != "" + elsif eval_string.strip != "" eval_string else _pry_.input_ring.to_a.reverse_each.find { |x| x && x.strip != "" } || "" diff --git a/lib/pry/commands/gist.rb b/lib/pry/commands/gist.rb index 7ce590cf..d9574992 100644 --- a/lib/pry/commands/gist.rb +++ b/lib/pry/commands/gist.rb @@ -72,11 +72,7 @@ class Pry def comment_expression_result_for_gist(result) content = "" result.lines.each_with_index do |line, index| - if index == 0 - content << "# => #{line}" - else - content << "# #{line}" - end + content << index == 0 ? "# => #{line}" : "# #{line}" end content diff --git a/lib/pry/commands/hist.rb b/lib/pry/commands/hist.rb index b37fd97e..16340216 100644 --- a/lib/pry/commands/hist.rb +++ b/lib/pry/commands/hist.rb @@ -45,12 +45,11 @@ class Pry end @history = - case - when opts.present?(:head) + if opts.present?(:head) @history.take_lines(1, opts[:head] || 10) - when opts.present?(:tail) + elsif opts.present?(:tail) @history.take_lines(-(opts[:tail] || 10), opts[:tail] || 10) - when opts.present?(:show) + elsif opts.present?(:show) @history.between(opts[:show]) else @history diff --git a/lib/pry/commands/watch_expression.rb b/lib/pry/commands/watch_expression.rb index c0067850..5a2fd32a 100644 --- a/lib/pry/commands/watch_expression.rb +++ b/lib/pry/commands/watch_expression.rb @@ -36,10 +36,9 @@ class Pry end def process - case - when opts.present?(:delete) + if opts.present?(:delete) delete opts[:delete] - when opts.present?(:list) || args.empty? + elsif opts.present?(:list) || args.empty? list else add_hook diff --git a/lib/pry/config/behavior.rb b/lib/pry/config/behavior.rb index 572c2dd9..dda5d130 100644 --- a/lib/pry/config/behavior.rb +++ b/lib/pry/config/behavior.rb @@ -324,8 +324,6 @@ class Pry elsif @default.respond_to?(name) value = @default.public_send(name, *args, &block) self[key] = __dup(value) - else - nil end end @@ -347,8 +345,6 @@ class Pry obj.to_h elsif obj.respond_to?(:to_hash) obj.to_hash - else - nil end end diff --git a/lib/pry/indent.rb b/lib/pry/indent.rb index 14500582..a3f1b9ef 100644 --- a/lib/pry/indent.rb +++ b/lib/pry/indent.rb @@ -291,11 +291,7 @@ class Pry when @close_heredocs[@heredoc_queue.first] @heredoc_queue.shift else - if @string_start - @string_start = nil - else - @string_start = token - end + @string_start = @string_start ? nil : token end end diff --git a/lib/pry/pager.rb b/lib/pry/pager.rb index d436ab41..48e60dfa 100644 --- a/lib/pry/pager.rb +++ b/lib/pry/pager.rb @@ -81,8 +81,7 @@ class Pry @out.write str end - def close - end + def close; end private diff --git a/lib/pry/pry_class.rb b/lib/pry/pry_class.rb index f71de8e6..08dae87c 100644 --- a/lib/pry/pry_class.rb +++ b/lib/pry/pry_class.rb @@ -237,7 +237,7 @@ you can add "Pry.config.windows_console_warning = false" to your pryrc. def self.view_clip(obj, options = {}) max = options.fetch :max_length, 60 id = options.fetch :id, false - if obj.kind_of?(Module) && obj.name.to_s != "" && obj.name.to_s.length <= max + if obj.is_a?(Module) && obj.name.to_s != "" && obj.name.to_s.length <= max obj.name.to_s elsif Pry.main == obj # special-case to support jruby. diff --git a/lib/pry/pry_instance.rb b/lib/pry/pry_instance.rb index d9fab1df..f6ec1be8 100644 --- a/lib/pry/pry_instance.rb +++ b/lib/pry/pry_instance.rb @@ -373,8 +373,6 @@ class Pry exception_handler.call(output, result, self) elsif should_print? print.call(output, result, self) - else - # nothin' end rescue RescuableException => e # Being uber-paranoid here, given that this exception arose because we couldn't @@ -593,7 +591,7 @@ class Pry # the array that the prompt stack is stored in def prompt_stack - @prompt_stack ||= Array.new + @prompt_stack ||= [] end private :prompt_stack diff --git a/lib/pry/terminal.rb b/lib/pry/terminal.rb index 35e3d257..a0a354c4 100644 --- a/lib/pry/terminal.rb +++ b/lib/pry/terminal.rb @@ -10,8 +10,6 @@ class Pry rows, cols = actual_screen_size if rows.to_i != 0 && cols.to_i != 0 [rows.to_i, cols.to_i] - else - nil end end diff --git a/lib/pry/testable/pry_tester.rb b/lib/pry/testable/pry_tester.rb index e6c3a61e..6572c2e8 100644 --- a/lib/pry/testable/pry_tester.rb +++ b/lib/pry/testable/pry_tester.rb @@ -23,11 +23,12 @@ class Pry end @history.push str if @history - if @pry.process_command(str) - result = last_command_result_or_output - else - result = @pry.evaluate_ruby(str) - end + result = + if @pry.process_command(str) + last_command_result_or_output + else + @pry.evaluate_ruby(str) + end end result diff --git a/lib/pry/wrapped_module.rb b/lib/pry/wrapped_module.rb index 563b9087..bafb051e 100644 --- a/lib/pry/wrapped_module.rb +++ b/lib/pry/wrapped_module.rb @@ -29,8 +29,6 @@ class Pry def self.from_str(mod_name, target = TOPLEVEL_BINDING) if safe_to_evaluate?(mod_name, target) Pry::WrappedModule.new(target.eval(mod_name)) - else - nil end rescue RescuableException nil @@ -268,11 +266,12 @@ class Pry def super(times = 1) return self if times.zero? - if wrapped.is_a?(Class) - sup = ancestors.select { |v| v.is_a?(Class) }[times] - else - sup = ancestors[times] - end + sup = + if wrapped.is_a?(Class) + ancestors.select { |v| v.is_a?(Class) }[times] + else + ancestors[times] + end Pry::WrappedModule(sup) if sup end @@ -368,11 +367,12 @@ class Pry def lines_for_file(file) @lines_for_file ||= {} - if file == Pry.eval_path - @lines_for_file[file] ||= Pry.line_buffer.drop(1) - else - @lines_for_file[file] ||= File.readlines(file) - end + @lines_for_file[file] ||= + if file == Pry.eval_path + Pry.line_buffer.drop(1) + else + File.readlines(file) + end end end end diff --git a/spec/code_object_spec.rb b/spec/code_object_spec.rb index 50ce46ff..6450bef2 100644 --- a/spec/code_object_spec.rb +++ b/spec/code_object_spec.rb @@ -219,15 +219,12 @@ describe Pry::CodeObject do before do class ClassyWassy class Puff - def tiggy - end + def tiggy; end end - def Puff - end + def Puff; end - def piggy - end + def piggy; end end Object.class_eval do diff --git a/spec/commands/show_doc_spec.rb b/spec/commands/show_doc_spec.rb index 69feba17..9e63040e 100644 --- a/spec/commands/show_doc_spec.rb +++ b/spec/commands/show_doc_spec.rb @@ -198,26 +198,22 @@ describe "show-doc" do before do # god this is boring1 class ShowSourceTestClass - def alpha - end + def alpha; end end # god this is boring2 module ShowSourceTestModule - def alpha - end + def alpha; end end # god this is boring3 ShowSourceTestClassWeirdSyntax = Class.new do - def beta - end + def beta; end end # god this is boring4 ShowSourceTestModuleWeirdSyntax = Module.new do - def beta - end + def beta; end end end @@ -273,15 +269,13 @@ describe "show-doc" do temporary_constants(:AlphaClass, :BetaClass) do # top-level beta class BetaClass - def alpha - end + def alpha; end end class AlphaClass # nested beta class BetaClass - def beta - end + def beta; end end end @@ -294,8 +288,7 @@ describe "show-doc" do class AlphaClass # nested beta class BetaClass - def beta - end + def beta; end end end @@ -309,8 +302,7 @@ describe "show-doc" do it 'should show the docs for all monkeypatches defined in different files' do # local monkeypatch class TestClassForShowSource - def epsilon - end + def epsilon; end end result = pry_eval("show-doc TestClassForShowSource -a") @@ -321,8 +313,7 @@ describe "show-doc" do describe "messages relating to -a" do it "displays the original definition by default (not a doc of a monkeypatch)" do class TestClassForCandidatesOrder - def beta - end + def beta; end end result = pry_eval("show-doc TestClassForCandidatesOrder") @@ -334,8 +325,7 @@ describe "show-doc" do '(when -a not used and more than one candidate exists for class)' do # Still reading boring tests, eh? class TestClassForShowSource - def delta - end + def delta; end end result = pry_eval('show-doc TestClassForShowSource') diff --git a/spec/commands/show_source_spec.rb b/spec/commands/show_source_spec.rb index 112c8629..eecb79db 100644 --- a/spec/commands/show_source_spec.rb +++ b/spec/commands/show_source_spec.rb @@ -346,34 +346,28 @@ describe "show-source" do describe "on modules" do before do class ShowSourceTestSuperClass - def alpha - end + def alpha; end end class ShowSourceTestClass < ShowSourceTestSuperClass - def alpha - end + def alpha; end end module ShowSourceTestSuperModule - def alpha - end + def alpha; end end module ShowSourceTestModule include ShowSourceTestSuperModule - def alpha - end + def alpha; end end ShowSourceTestClassWeirdSyntax = Class.new do - def beta - end + def beta; end end ShowSourceTestModuleWeirdSyntax = Module.new do - def beta - end + def beta; end end end @@ -455,14 +449,12 @@ describe "show-source" do it 'should lookup module name with respect to current context' do temporary_constants(:AlphaClass, :BetaClass) do class BetaClass - def alpha - end + def alpha; end end class AlphaClass class BetaClass - def beta - end + def beta; end end end @@ -474,8 +466,7 @@ describe "show-source" do temporary_constants(:AlphaClass) do class AlphaClass class BetaClass - def beta - end + def beta; end end end @@ -489,8 +480,7 @@ describe "show-source" do describe "show-source -a" do it 'should show the source for all monkeypatches defined in different files' do class TestClassForShowSource - def beta - end + def beta; end end result = pry_eval('show-source TestClassForShowSource -a') @@ -500,8 +490,7 @@ describe "show-source" do it 'should show the source for a class_eval-based monkeypatch' do TestClassForShowSourceClassEval.class_eval do - def class_eval_method - end + def class_eval_method; end end result = pry_eval('show-source TestClassForShowSourceClassEval -a') @@ -521,8 +510,7 @@ describe "show-source" do it 'should show the source for an instance_eval-based monkeypatch' do TestClassForShowSourceInstanceEval.instance_eval do - def instance_eval_method - end + def instance_eval_method; end end result = pry_eval('show-source TestClassForShowSourceInstanceEval -a') @@ -532,8 +520,7 @@ describe "show-source" do describe "messages relating to -a" do it 'indicates all available monkeypatches can be shown with -a when (when -a not used and more than one candidate exists for class)' do class TestClassForShowSource - def gamma - end + def gamma; end end result = pry_eval('show-source TestClassForShowSource') diff --git a/spec/completion_spec.rb b/spec/completion_spec.rb index 958eed09..c736b80a 100644 --- a/spec/completion_spec.rb +++ b/spec/completion_spec.rb @@ -227,11 +227,9 @@ describe Pry::InputCompleter do # skip unless Pry::Helpers::Platform.jruby? m = Module.new do - def self.hash(a, b) - end + def self.hash(a, b); end - def aaaa - end + def aaaa; end end completer_test(m, nil, false).call("[].size.aaaa") diff --git a/spec/fixtures/candidate_helper1.rb b/spec/fixtures/candidate_helper1.rb index 46056a5e..7833d52f 100644 --- a/spec/fixtures/candidate_helper1.rb +++ b/spec/fixtures/candidate_helper1.rb @@ -1,11 +1,8 @@ # rank 0 class CandidateTest - def test1 - end + def test1; end - def test2 - end + def test2; end - def test3 - end + def test3; end end diff --git a/spec/fixtures/candidate_helper2.rb b/spec/fixtures/candidate_helper2.rb index ebc22a9c..9de72c8d 100644 --- a/spec/fixtures/candidate_helper2.rb +++ b/spec/fixtures/candidate_helper2.rb @@ -1,8 +1,6 @@ # rank 1 class CandidateTest - def test4 - end + def test4; end - def test5 - end + def test5; end end diff --git a/spec/fixtures/show_source_doc_examples.rb b/spec/fixtures/show_source_doc_examples.rb index aead2da1..bb24960c 100644 --- a/spec/fixtures/show_source_doc_examples.rb +++ b/spec/fixtures/show_source_doc_examples.rb @@ -1,22 +1,18 @@ # used by show_source_spec.rb and show_doc_spec.rb class TestClassForShowSource # doc - def alpha - end + def alpha; end end class TestClassForShowSourceClassEval - def alpha - end + def alpha; end end class TestClassForShowSourceInstanceEval - def alpha - end + def alpha; end end # The first definition (find the second one in show_doc_spec.rb). class TestClassForCandidatesOrder - def alpha - end + def alpha; end end diff --git a/spec/method_spec.rb b/spec/method_spec.rb index 0700c3dc..f4fdd885 100644 --- a/spec/method_spec.rb +++ b/spec/method_spec.rb @@ -508,14 +508,12 @@ describe Pry::Method do describe 'method aliases' do before do @class = Class.new do - def eat - end + def eat; end alias_method :fress, :eat alias_method :omnomnom, :fress - def eruct - end + def eruct; end end end @@ -554,7 +552,7 @@ describe Pry::Method do end it 'should be able to find aliases for methods implemented in C' do - meth = Pry::Method(Hash.new.method(:key?)) + meth = Pry::Method({}.method(:key?)) aliases = Set.new(meth.aliases) expect(aliases).to eq Set.new(["include?", "member?", "has_key?"]) diff --git a/spec/wrapped_module_spec.rb b/spec/wrapped_module_spec.rb index abe12c6a..83778f4d 100644 --- a/spec/wrapped_module_spec.rb +++ b/spec/wrapped_module_spec.rb @@ -14,8 +14,7 @@ describe Pry::WrappedModule do # rank 2 class CandidateTest - def test6 - end + def test6; end end class PitifullyBlank @@ -27,8 +26,7 @@ describe Pry::WrappedModule do class DoublyNested # nested docs class TriplyNested - def nested_method - end + def nested_method; end end end end @@ -103,7 +101,7 @@ describe Pry::WrappedModule do it 'should return source for deeply nested class' do expect(Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source).to match(/nested_method/) - expect(Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source.lines.count).to eq 4 + expect(Pry::WrappedModule(Host::ForeverAlone::DoublyNested::TriplyNested).source.lines.count).to eq(3) end end