@@ -203,7 +203,14 @@ def location_for(iseq)
203203 end
204204
205205 def find_constant_path ( insns , index )
206- index -= 1 while index >= 0 && ( insns [ index ] . is_a? ( Integer ) || ( insns [ index ] . is_a? ( Array ) && %i[ swap topn ] . include? ( insns [ index ] [ 0 ] ) ) )
206+ index -= 1 while index >= 0 &&
207+ (
208+ insns [ index ] . is_a? ( Integer ) ||
209+ (
210+ insns [ index ] . is_a? ( Array ) &&
211+ %i[ swap topn ] . include? ( insns [ index ] [ 0 ] )
212+ )
213+ )
207214 insn = insns [ index ]
208215
209216 if insn . is_a? ( Array ) && insn [ 0 ] == :opt_getconstant_path
@@ -252,7 +259,12 @@ def method_definition(nesting, name, location, file_comments)
252259 comments = EntryComments . new ( file_comments , location )
253260
254261 if nesting . last == [ :singletonclass ]
255- SingletonMethodDefinition . new ( nesting [ 0 ...-1 ] , name , location , comments )
262+ SingletonMethodDefinition . new (
263+ nesting [ 0 ...-1 ] ,
264+ name ,
265+ location ,
266+ comments
267+ )
256268 else
257269 MethodDefinition . new ( nesting , name , location , comments )
258270 end
@@ -341,7 +353,12 @@ def index_iseq(iseq, file_comments)
341353 queue << [ class_iseq , next_nesting ]
342354 when :definemethod
343355 location = location_for ( insn [ 2 ] )
344- results << method_definition ( current_nesting , insn [ 1 ] , location , file_comments )
356+ results << method_definition (
357+ current_nesting ,
358+ insn [ 1 ] ,
359+ location ,
360+ file_comments
361+ )
345362 when :definesmethod
346363 if insns [ index - 1 ] != [ :putself ]
347364 warn ( "singleton method with non-self receiver" )
@@ -378,19 +395,35 @@ def index_iseq(iseq, file_comments)
378395 location = Location . new ( line , :unknown )
379396 names . each do |name |
380397 if insn [ 1 ] [ :mid ] != :attr_writer
381- results << method_definition ( current_nesting , name , location , file_comments )
398+ results << method_definition (
399+ current_nesting ,
400+ name ,
401+ location ,
402+ file_comments
403+ )
382404 end
383405
384406 if insn [ 1 ] [ :mid ] != :attr_reader
385- results << method_definition ( current_nesting , :"#{ name } =" , location , file_comments )
407+ results << method_definition (
408+ current_nesting ,
409+ :"#{ name } =" ,
410+ location ,
411+ file_comments
412+ )
386413 end
387414 end
388415 when :"core#set_method_alias"
389416 # Now we have to validate that the alias is happening with a
390417 # non-interpolated value. To do this we'll match the specific
391418 # pattern we're expecting.
392- values = insns [ ( index - 4 ) ...index ] . map { |insn | insn . is_a? ( Array ) ? insn [ 0 ] : insn }
393- next if values != %i[ putspecialobject putspecialobject putobject putobject ]
419+ values =
420+ insns [ ( index - 4 ) ...index ] . map do |insn |
421+ insn . is_a? ( Array ) ? insn [ 0 ] : insn
422+ end
423+ if values !=
424+ %i[ putspecialobject putspecialobject putobject putobject ]
425+ next
426+ end
394427
395428 # Now that we know it's in the structure we want it, we can use
396429 # the values of the putobject to determine the alias.
@@ -441,7 +474,10 @@ def initialize
441474 def visit_alias ( node )
442475 if node . left . is_a? ( SymbolLiteral ) && node . right . is_a? ( SymbolLiteral )
443476 location =
444- Location . new ( node . location . start_line , node . location . start_column )
477+ Location . new (
478+ node . location . start_line ,
479+ node . location . start_column
480+ )
445481
446482 results << AliasMethodDefinition . new (
447483 nesting . dup ,
@@ -457,7 +493,10 @@ def visit_alias(node)
457493 def visit_assign ( node )
458494 if node . target . is_a? ( VarField ) && node . target . value . is_a? ( Const )
459495 location =
460- Location . new ( node . location . start_line , node . location . start_column )
496+ Location . new (
497+ node . location . start_line ,
498+ node . location . start_column
499+ )
461500
462501 results << ConstantDefinition . new (
463502 nesting . dup ,
@@ -507,18 +546,31 @@ def visit_command(node)
507546 when "attr_reader" , "attr_writer" , "attr_accessor"
508547 comments = comments_for ( node )
509548 location =
510- Location . new ( node . location . start_line , node . location . start_column )
549+ Location . new (
550+ node . location . start_line ,
551+ node . location . start_column
552+ )
511553
512554 node . arguments . parts . each do |argument |
513555 next unless argument . is_a? ( SymbolLiteral )
514556 name = argument . value . value . to_sym
515557
516558 if node . message . value != "attr_writer"
517- results << MethodDefinition . new ( nesting . dup , name , location , comments )
559+ results << MethodDefinition . new (
560+ nesting . dup ,
561+ name ,
562+ location ,
563+ comments
564+ )
518565 end
519566
520567 if node . message . value != "attr_reader"
521- results << MethodDefinition . new ( nesting . dup , :"#{ name } =" , location , comments )
568+ results << MethodDefinition . new (
569+ nesting . dup ,
570+ :"#{ name } =" ,
571+ location ,
572+ comments
573+ )
522574 end
523575 end
524576 end
0 commit comments