-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Model call chains as an
AbstractTokenTarget
(#443)
This PR implements call chains as a new AbstractTokenTarget: BreakableCallChainEntry. This means that multilining for call chains -- just like for existing breakables -- will be decided on-the-fly during rendering, where we have more contextual information and can better enforce line length. This is done with a combination of the normal breakable machinery and some additional "magic tokens." Specifically, this adds tokens at the beginning and end of the indent-able portion of the call chain, and then during rendering, we maintain a count of how many nested call chains we're in and adjust indentation accordingly. This isn't exactly the cleanest implementation, but given the complexity in use-cases for call chains, it was the best I could muster in a way that functioned how users would generally expect. This is a fairly large PR, but there's primarily three main portions which each are about a third of the total diff each: fixtures, the boilerplate in ripper_tree_types to support getting expression starting lines, and finally the main formatting changes. I've done my best to comment these areas appropriately, but it's helpful to add further explanation there, I'm more than happy to add more.
- Loading branch information
Showing
35 changed files
with
1,385 additions
and
496 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,7 @@ | |
a = begin | ||
end | ||
end | ||
|
||
begin | ||
end | ||
.freeze |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,6 @@ | |
a = begin | ||
end | ||
end | ||
|
||
begin | ||
end.freeze |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
def func | ||
brace_block_with_no_args { p 'hi' } | ||
end | ||
|
||
{ | ||
"/v1/transfers" => lambda { | ||
foo | ||
bar | ||
# TODO: add baz here | ||
# Oh and maybe quux if you have time | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,12 @@ | ||
def func | ||
brace_block_with_no_args { p("hi") } | ||
end | ||
|
||
{ | ||
"/v1/transfers" => lambda { | ||
foo | ||
bar | ||
# TODO: add baz here | ||
# Oh and maybe quux if you have time | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,7 @@ def foo | |
puts("hi") | ||
end | ||
end | ||
|
||
do_stuff! if it_isnt_dangerous( | ||
i_promise: true | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,9 @@ def foo | |
puts("hi") | ||
end | ||
end | ||
|
||
if it_isnt_dangerous( | ||
i_promise: true | ||
) | ||
do_stuff! | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,8 @@ | ||
sig { | ||
params( | ||
route: String | ||
).void | ||
) | ||
.void | ||
} | ||
def ajax_get(route) | ||
super | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ def blorp | |
method_call( | ||
arg_a, | ||
arg_b | ||
).chained_call | ||
) | ||
.chained_call | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,16 @@ | ||
a (1) | ||
other_cool_method (a + b).round(4) | ||
|
||
# rubocop:disable PrisonGuard/PrivateModule | ||
(foo( | ||
foo # rubocop:enable PrisonGuard/PrivateModule | ||
)).flatten | ||
|
||
# rubocop:disable Style/Stuff | ||
(MyModel::InSomeNamespace | ||
.load_one( | ||
# rubocop:enable Style/Stuff | ||
{name: "name"} | ||
) | ||
&.rules) | ||
.freeze |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,18 @@ | ||
a(1) | ||
other_cool_method((a + b).round(4)) | ||
|
||
# rubocop:disable PrisonGuard/PrivateModule | ||
(foo( | ||
# rubocop:enable PrisonGuard/PrivateModule | ||
foo | ||
)) | ||
.flatten | ||
|
||
# rubocop:disable Style/Stuff | ||
(MyModel::InSomeNamespace | ||
.load_one( | ||
# rubocop:enable Style/Stuff | ||
{name: "name"} | ||
) | ||
&.rules) | ||
.freeze |
Oops, something went wrong.