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

Commit f5ac5fe

Browse files
committed
Reformat
1 parent b117c9b commit f5ac5fe

File tree

2 files changed

+64
-50
lines changed

2 files changed

+64
-50
lines changed

lib/syntax_tree/node.rb

Lines changed: 50 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ def trailing_comma?
625625
# If the last argument is a block, then we can't put a trailing comma
626626
# after it without resulting in a syntax error.
627627
false
628-
elsif parts.length == 1 && (part = parts.first) && (part.is_a?(Command) || part.is_a?(CommandCall))
628+
elsif parts.length == 1 && (part = parts.first) &&
629+
(part.is_a?(Command) || part.is_a?(CommandCall))
629630
# If the only argument is a command or command call, then a trailing
630631
# comma would be parsed as part of that expression instead of on this
631632
# one, so we don't want to add a trailing comma.
@@ -1444,7 +1445,8 @@ def format_key(q, key)
14441445
when DynaSymbol
14451446
parts = key.parts
14461447

1447-
if parts.length == 1 && (part = parts.first) && part.is_a?(TStringContent) && part.value.match?(LABEL)
1448+
if parts.length == 1 && (part = parts.first) &&
1449+
part.is_a?(TStringContent) && part.value.match?(LABEL)
14481450
q.format(part)
14491451
q.text(":")
14501452
else
@@ -2054,7 +2056,8 @@ def forced_brace_bounds?(q)
20542056
when Paren, Statements
20552057
# If we hit certain breakpoints then we know we're safe.
20562058
return false
2057-
when If, IfMod, IfOp, Unless, UnlessMod, While, WhileMod, Until, UntilMod
2059+
when If, IfMod, IfOp, Unless, UnlessMod, While, WhileMod, Until,
2060+
UntilMod
20582061
return true if parent.predicate == previous
20592062
previous = parent
20602063
end
@@ -2395,11 +2398,7 @@ def format(q)
23952398
when :"::"
23962399
q.text(".")
23972400
when Op
2398-
if operator.value == "::"
2399-
q.text(".")
2400-
else
2401-
operator.format(q)
2402-
end
2401+
operator.value == "::" ? q.text(".") : operator.format(q)
24032402
else
24042403
operator.format(q)
24052404
end
@@ -2465,7 +2464,8 @@ def format(q)
24652464
# nodes.
24662465
parent = parents[3] if parent.is_a?(DoBlock)
24672466

2468-
if parent.is_a?(MethodAddBlock) && parent.call.is_a?(FCall) && parent.call.value.value == "sig"
2467+
if parent.is_a?(MethodAddBlock) && parent.call.is_a?(FCall) &&
2468+
parent.call.value.value == "sig"
24692469
threshold = 2
24702470
end
24712471
end
@@ -2510,7 +2510,10 @@ def format_chain(q, children)
25102510

25112511
while (child = children.pop)
25122512
if child.is_a?(Call)
2513-
if child.receiver.is_a?(Call) && (child.receiver.message != :call) && (child.receiver.message.value == "where") && (child.message.value == "not")
2513+
if child.receiver.is_a?(Call) &&
2514+
(child.receiver.message != :call) &&
2515+
(child.receiver.message.value == "where") &&
2516+
(child.message.value == "not")
25142517
# This is very specialized behavior wherein we group
25152518
# .where.not calls together because it looks better. For more
25162519
# information, see
@@ -2684,7 +2687,8 @@ def format(q)
26842687
# If we're at the top of a call chain, then we're going to do some
26852688
# specialized printing in case we can print it nicely. We _only_ do this
26862689
# at the top of the chain to avoid weird recursion issues.
2687-
if CallChainFormatter.chained?(receiver) && !CallChainFormatter.chained?(q.parent)
2690+
if CallChainFormatter.chained?(receiver) &&
2691+
!CallChainFormatter.chained?(q.parent)
26882692
q.group do
26892693
q
26902694
.if_break { CallChainFormatter.new(self).format(q) }
@@ -5344,7 +5348,8 @@ def call(q, node)
53445348
# wanted it to be an explicit conditional because there are parentheses
53455349
# around it. So we'll just leave it in place.
53465350
grandparent = q.grandparent
5347-
if grandparent.is_a?(Paren) && (body = grandparent.contents.body) && body.length == 1 && body.first == node
5351+
if grandparent.is_a?(Paren) && (body = grandparent.contents.body) &&
5352+
body.length == 1 && body.first == node
53485353
return false
53495354
end
53505355

@@ -5375,10 +5380,10 @@ def call(q, node)
53755380
# and default instead to breaking them into multiple lines.
53765381
def ternaryable?(statement)
53775382
case statement
5378-
when Alias, Assign, Break, Command, CommandCall, Heredoc, If, IfMod, IfOp,
5379-
Lambda, MAssign, Next, OpAssign, RescueMod, Return, Return0, Super,
5380-
Undef, Unless, UnlessMod, Until, UntilMod, VarAlias, VoidStmt, While,
5381-
WhileMod, Yield, Yield0, ZSuper
5383+
when Alias, Assign, Break, Command, CommandCall, Heredoc, If, IfMod,
5384+
IfOp, Lambda, MAssign, Next, OpAssign, RescueMod, Return, Return0,
5385+
Super, Undef, Unless, UnlessMod, Until, UntilMod, VarAlias,
5386+
VoidStmt, While, WhileMod, Yield, Yield0, ZSuper
53825387
# This is a list of nodes that should not be allowed to be a part of a
53835388
# ternary clause.
53845389
false
@@ -6470,7 +6475,8 @@ def format(q)
64706475
# If we're at the top of a call chain, then we're going to do some
64716476
# specialized printing in case we can print it nicely. We _only_ do this
64726477
# at the top of the chain to avoid weird recursion issues.
6473-
if CallChainFormatter.chained?(call) && !CallChainFormatter.chained?(q.parent)
6478+
if CallChainFormatter.chained?(call) &&
6479+
!CallChainFormatter.chained?(q.parent)
64746480
q.group do
64756481
q
64766482
.if_break { CallChainFormatter.new(self).format(q) }
@@ -7330,9 +7336,10 @@ def format(q)
73307336
q.group do
73317337
q.indent do
73327338
q.breakable_empty
7333-
q.seplist(elements, ArrayLiteral::BREAKABLE_SPACE_SEPARATOR) do |element|
7334-
q.format(element)
7335-
end
7339+
q.seplist(
7340+
elements,
7341+
ArrayLiteral::BREAKABLE_SPACE_SEPARATOR
7342+
) { |element| q.format(element) }
73367343
end
73377344
q.breakable_empty
73387345
end
@@ -7423,9 +7430,10 @@ def format(q)
74237430
q.group do
74247431
q.indent do
74257432
q.breakable_empty
7426-
q.seplist(elements, ArrayLiteral::BREAKABLE_SPACE_SEPARATOR) do |element|
7427-
q.format(element)
7428-
end
7433+
q.seplist(
7434+
elements,
7435+
ArrayLiteral::BREAKABLE_SPACE_SEPARATOR
7436+
) { |element| q.format(element) }
74297437
end
74307438
q.breakable_empty
74317439
end
@@ -8378,7 +8386,7 @@ def format(q)
83788386
q.text("; ")
83798387
q.format(statement)
83808388
end
8381-
8389+
83828390
line = statement.location.end_line
83838391
previous = statement
83848392
end
@@ -8890,9 +8898,10 @@ def format(q)
88908898
q.group do
88918899
q.indent do
88928900
q.breakable_empty
8893-
q.seplist(elements, ArrayLiteral::BREAKABLE_SPACE_SEPARATOR) do |element|
8894-
q.format(element)
8895-
end
8901+
q.seplist(
8902+
elements,
8903+
ArrayLiteral::BREAKABLE_SPACE_SEPARATOR
8904+
) { |element| q.format(element) }
88968905
end
88978906
q.breakable_empty
88988907
end
@@ -9773,15 +9782,17 @@ def format(q)
97739782
def pin(parent)
97749783
replace = PinnedVarRef.new(value: value, location: location)
97759784

9776-
parent.deconstruct_keys([]).each do |key, value|
9777-
if value == self
9778-
parent.instance_variable_set(:"@#{key}", replace)
9779-
break
9780-
elsif value.is_a?(Array) && (index = value.index(self))
9781-
parent.public_send(key)[index] = replace
9782-
break
9785+
parent
9786+
.deconstruct_keys([])
9787+
.each do |key, value|
9788+
if value == self
9789+
parent.instance_variable_set(:"@#{key}", replace)
9790+
break
9791+
elsif value.is_a?(Array) && (index = value.index(self))
9792+
parent.public_send(key)[index] = replace
9793+
break
9794+
end
97839795
end
9784-
end
97859796
end
97869797
end
97879798

@@ -10229,9 +10240,10 @@ def format(q)
1022910240
q.group do
1023010241
q.indent do
1023110242
q.breakable_empty
10232-
q.seplist(elements, ArrayLiteral::BREAKABLE_SPACE_SEPARATOR) do |element|
10233-
q.format(element)
10234-
end
10243+
q.seplist(
10244+
elements,
10245+
ArrayLiteral::BREAKABLE_SPACE_SEPARATOR
10246+
) { |element| q.format(element) }
1023510247
end
1023610248
q.breakable_empty
1023710249
end

lib/syntax_tree/parser.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,12 +1011,13 @@ def on_case(value, consequent)
10111011
consume_operator(:"=>")
10121012
end
10131013

1014-
node = RAssign.new(
1015-
value: value,
1016-
operator: operator,
1017-
pattern: consequent,
1018-
location: value.location.to(consequent.location)
1019-
)
1014+
node =
1015+
RAssign.new(
1016+
value: value,
1017+
operator: operator,
1018+
pattern: consequent,
1019+
location: value.location.to(consequent.location)
1020+
)
10201021

10211022
PinVisitor.visit(node, tokens)
10221023
node
@@ -1973,12 +1974,13 @@ def on_in(pattern, statements, consequent)
19731974
ending.location.start_column
19741975
)
19751976

1976-
node = In.new(
1977-
pattern: pattern,
1978-
statements: statements,
1979-
consequent: consequent,
1980-
location: beginning.location.to(ending.location)
1981-
)
1977+
node =
1978+
In.new(
1979+
pattern: pattern,
1980+
statements: statements,
1981+
consequent: consequent,
1982+
location: beginning.location.to(ending.location)
1983+
)
19821984

19831985
PinVisitor.visit(node, tokens)
19841986
node

0 commit comments

Comments
 (0)