Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit dea5da2

Browse files
committed
Reformat
1 parent c187683 commit dea5da2

File tree

2 files changed

+73
-18
lines changed

2 files changed

+73
-18
lines changed

lib/syntax_tree/cli.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,13 @@ def initialize(options)
166166
def run(item)
167167
lines = item.source.lines(chomp: true)
168168

169-
SyntaxTree.index(item.source).each do |entry|
170-
line = lines[entry.location.line - 1]
171-
pattern = "/^#{line.gsub("\\", "\\\\\\\\").gsub("/", "\\/")}$/;\""
169+
SyntaxTree
170+
.index(item.source)
171+
.each do |entry|
172+
line = lines[entry.location.line - 1]
173+
pattern = "/^#{line.gsub("\\", "\\\\\\\\").gsub("/", "\\/")}$/;\""
172174

173-
entries <<
174-
case entry
175+
entries << case entry
175176
when SyntaxTree::Index::ModuleDefinition
176177
parts = [entry.name, item.filepath, pattern, "m"]
177178

@@ -230,7 +231,9 @@ def run(item)
230231
end
231232

232233
def success
233-
puts("!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;\" to lines/")
234+
puts(
235+
"!_TAG_FILE_FORMAT 2 /extended format; --format=1 will not append ;\" to lines/"
236+
)
234237
puts("!_TAG_FILE_SORTED 1 /0=unsorted, 1=sorted, 2=foldcase/")
235238
entries.sort.each { |entry| puts(entry) }
236239
end

lib/syntax_tree/index.rb

Lines changed: 64 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)