Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Model call chains as an AbstractTokenTarget #443

Merged
merged 60 commits into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from 59 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
bcb8faf
wip
reese Jul 27, 2023
850216c
This mostly works!
reese Jul 30, 2023
285abc6
wip
reese Aug 7, 2023
b55a612
Fix line length checking for call chain breakables
reese Aug 8, 2023
f20426f
Squash some more bugs
reese Aug 10, 2023
744e817
Fix line winding in calls
reese Aug 11, 2023
7f0e36c
Fix indentation in nested breakables inside call chains
reese Aug 11, 2023
ad42bcf
Assertion fix
reese Aug 14, 2023
cff3121
wip
reese Aug 15, 2023
5be646b
its alive!
reese Aug 16, 2023
a2fa7d4
It's _even more alive_
reese Aug 16, 2023
4cb900c
Fix really long single-dot methods being multilined
reese Aug 16, 2023
c50e057
Get begin/end stuff working
reese Aug 16, 2023
09a6d8b
Fix nested heredocs
reese Aug 17, 2023
1937de0
Fix extra whitespace on empty lines
reese Aug 17, 2023
1c1862a
Fix heredocs in call chains
reese Aug 17, 2023
4fbb2f8
[might delete] try removing my dumb hack
reese Aug 17, 2023
1f08e20
Take another crack at user-multilining
reese Aug 17, 2023
96fa67b
Fix weird line reporting for ArgsAddStar...
reese Aug 17, 2023
9a39f02
Break on call chains before breaking on inner breakables
reese Aug 18, 2023
087a994
Fix precedence
reese Aug 18, 2023
5653f0f
Fix line length check for call chain breakables
reese Aug 18, 2023
dba5aa9
Fix call chains with heredocs embedded in string embedded expressions
reese Aug 18, 2023
86983b6
Reintroduce explicitly single-lining Class.call patterns
reese Aug 18, 2023
825d527
Don't force
reese Aug 18, 2023
a535184
Include leading indentation when calculating bcce line length
reese Aug 19, 2023
b6e42e9
Fix issue with calls in ternaries in embedded expressions
reese Aug 19, 2023
bbb93ba
Fix double quote length
reese Aug 19, 2023
793cf8b
Fix aref line winding
reese Aug 19, 2023
75adc46
Single-line single calls
reese Aug 19, 2023
b856ef0
Fix start_line for parens
reese Aug 19, 2023
a379f3c
Finish todos
reese Aug 19, 2023
d47eb4b
Fix method add args wrapped in parens
reese Aug 19, 2023
9b3e904
Fix comments in methods with visibility modifiers
reese Aug 19, 2023
98d309c
Don't unnecessariliy render expressions in mulitline checking
reese Aug 19, 2023
07aa735
Try simplifying call chain logic
reese Aug 20, 2023
73ecc12
Experiment with new line length checking
reese Aug 20, 2023
f56be0f
Support other user-multilined const expressions
reese Aug 20, 2023
d186036
Fix rendering for const path refs
reese Aug 20, 2023
45fef70
Fix issues with inlined methods and comments
reese Aug 20, 2023
481bf4c
Make conditional modifiers multiline if anything in the conditional i…
reese Aug 20, 2023
73602c8
Fix comment winding for brace blocks
reese Aug 20, 2023
cbc4c2b
Fix paren line winding
reese Aug 20, 2023
0898db8
Skip empty lines in indented heredocs
reese Aug 21, 2023
64d273a
Fix paren expressions with method add args
reese Aug 21, 2023
b47c0cb
Roll back a bunch of unneeded changes
reese Aug 21, 2023
c905b0b
Fix fixture
reese Aug 21, 2023
b4b17eb
Use trait methods instead
reese Aug 21, 2023
55056f7
Fix lint errors
reese Aug 21, 2023
e64fc0e
Actually fix the heredoc whitespace thing this time
reese Aug 21, 2023
7e344a2
Cleanup and some additional commenting
reese Aug 21, 2023
6d6d246
Remove some dead code
reese Aug 21, 2023
3b16c86
Use peekable
reese Aug 21, 2023
9452b63
Use Option instead of making calls unreachable
reese Aug 22, 2023
abb45af
Only clone needed expression when rendering visibility modifers
reese Aug 22, 2023
7052661
Add comment on not shifting comments in block call chain elements
reese Aug 22, 2023
791ed66
Make next_args_list_must_use_parens a bit cleaner
reese Aug 22, 2023
a2bb4e2
Make HeredocStart an actual concrete token
reese Aug 22, 2023
6bc8a3a
Use delims for empty method call parens
reese Aug 22, 2023
24f4b27
Add some tests for call chains with different comment placements
reese Aug 23, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion fixtures/small/aref_in_call_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@
)
.void
end
def foo; end
def foo; end

Array[
@root_fragment,
@lemon_tea_fragment,
@green_tea_fragment,
@cake_fragment
].sort_by(&:name)
7 changes: 7 additions & 0 deletions fixtures/small/aref_in_call_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,10 @@
end
def foo
end

Array[
@root_fragment,
@lemon_tea_fragment,
@green_tea_fragment,
@cake_fragment
].sort_by(&:name)
4 changes: 4 additions & 0 deletions fixtures/small/begin_end_stack_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
a = begin
end
end

begin
end
.freeze
3 changes: 3 additions & 0 deletions fixtures/small/begin_end_stack_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,6 @@
a = begin
end
end

begin
end.freeze
9 changes: 9 additions & 0 deletions fixtures/small/brace_blocks_with_no_args_actual.rb
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
}
}
9 changes: 9 additions & 0 deletions fixtures/small/brace_blocks_with_no_args_expected.rb
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
}
}
4 changes: 4 additions & 0 deletions fixtures/small/conditional_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,7 @@ def foo
puts("hi")
end
end

do_stuff! if it_isnt_dangerous(
i_promise: true
)
6 changes: 6 additions & 0 deletions fixtures/small/conditional_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,9 @@ def foo
puts("hi")
end
end

if it_isnt_dangerous(
i_promise: true
)
do_stuff!
end
11 changes: 11 additions & 0 deletions fixtures/small/heredoc_method_call_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,14 @@ class William::Carlos::Williams
Icarus drowning
LANDSCAPE
end

optp
.on do |value|
<<~EOF
There's some lines here

But that one's a blank line!

There shouldn't be any whitespace on those
EOF
end
11 changes: 11 additions & 0 deletions fixtures/small/heredoc_method_call_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,14 @@ class William::Carlos::Williams
Williams
)
end

optp
.on do |value|
<<~EOF
There's some lines here

But that one's a blank line!

There shouldn't be any whitespace on those
EOF
end
21 changes: 21 additions & 0 deletions fixtures/small/heredocs_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,27 @@ class Foo
rubocop.smash(bad_thing)
end

this_one_is
.in_a_call_chain {
# some stuff
}
.each do
<<~MYHEREDOC
Words are pale shadows of forgotten names.
As names have power, words have power.
Words can light fires in the minds of men.
Words can wring tears from the hardest hearts.
MYHEREDOC
end

def foo
"#{stuff.each do
<<~MESSAGE.strip
#{message.text}
MESSAGE
end.join("\n\n")}"
end


puts a
puts b
Expand Down
22 changes: 22 additions & 0 deletions fixtures/small/heredocs_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,28 @@ class Foo
rubocop.smash(bad_thing)
end

this_one_is
.in_a_call_chain {
# some stuff
}
.each do
<<~MYHEREDOC
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

crimes

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on the downside, i'm currently still debugging even more crimes

Words are pale shadows of forgotten names.
As names have power, words have power.
Words can light fires in the minds of men.
Words can wring tears from the hardest hearts.
MYHEREDOC
end

def foo
"#{stuff.each do
<<~MESSAGE
#{message.text}
MESSAGE
.strip
end.join("\n\n")}"
end

puts(a)
puts(b)
foo
6 changes: 4 additions & 2 deletions fixtures/small/method_annotation_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def do_the_thing(a, b)
params(
a: String,
b: String
).void
)
.void
end
def example(a, b)
end
Expand Down Expand Up @@ -95,7 +96,8 @@ class Bees
first_param: MyClass,
# This one is the second one, nice
second_param: YourClass
).void
)
.void
# Please not the bees!
}
def not_the_bees!
Expand Down
36 changes: 34 additions & 2 deletions fixtures/small/method_chains_actual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
foo.bar
.baz

# If they're all on the same line but different from
# the first receiver, consider that "on one line"
foo
.bar.baz

Expand Down Expand Up @@ -97,6 +95,24 @@ def example
b: ""
)

ThisIs::OnlyOneCall
# but it's explicitly multilined with a
.comment!

OnlyOneCall
# but it's explicitly multilined with a
.comment!

[
# foo
]
# bar
.baz

[]
# Please don't do this
.freeze

Paul::Blart::Mall::Cop::PerformedByTheLegendaryKevinJamesWhoIsAnAbsoluteLegendInAllOfHisFilmsWhichAreAbsolutelyIncredible.consume_pixie_sticks(mall: "downtown").each do |punch_list_type|
end

Expand Down Expand Up @@ -129,3 +145,19 @@ def gather_thanes!
puts "h"
end
&.foo

My::Error.soft(
"",
stuff: {
message_token: message.token,

# Some comments!
value: id_or_email.name
}
)

# rubocop:disable PrisonGuard/PrivateModule
(foo.load_one
# rubocop:enable PrisonGuard/PrivateModule
.bar)
.thing
44 changes: 40 additions & 4 deletions fixtures/small/method_chains_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@
.bar
.baz

# If they're all on the same line but different from
# the first receiver, consider that "on one line"
foo.bar.baz
foo
.bar
.baz

foo::bar&.nil?
foo::bar
&.nil?

foo::bar
&.nil?::klass
Expand Down Expand Up @@ -120,6 +121,24 @@ def example
b: ""
)

ThisIs::OnlyOneCall
# but it's explicitly multilined with a
.comment!

OnlyOneCall
# but it's explicitly multilined with a
.comment!

[
# foo
]
# bar
.baz

[]
# Please don't do this
.freeze

Paul::Blart::Mall::Cop::PerformedByTheLegendaryKevinJamesWhoIsAnAbsoluteLegendInAllOfHisFilmsWhichAreAbsolutelyIncredible
.consume_pixie_sticks(mall: "downtown")
.each do |punch_list_type|
Expand Down Expand Up @@ -160,3 +179,20 @@ def gather_thanes!
puts("h")
end
&.foo

My::Error.soft(
"",
stuff: {
message_token: message.token,

# Some comments!
value: id_or_email.name
}
)

# rubocop:disable PrisonGuard/PrivateModule
(foo
.load_one
# rubocop:enable PrisonGuard/PrivateModule
.bar)
.thing
3 changes: 2 additions & 1 deletion fixtures/small/multiline_chain_in_block_expected.rb
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
Expand Down
3 changes: 2 additions & 1 deletion fixtures/small/multiline_chained_call_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ def blorp
method_call(
arg_a,
arg_b
).chained_call
)
.chained_call
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,11 @@ def stub_server(path:, body: {})
"https://example.com#{path}"
).to_return(body: body.to_json)
end

{
"original_fields" => foo,
"alternative_fields" => (thing_one(id, api) + thing_two(
id,
api
)).sort
}
12 changes: 11 additions & 1 deletion fixtures/small/multiline_method_chain_with_arguments_expected.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,15 @@ def stub_server(path:, body: {})
stub_request(
:get,
"https://example.com#{path}"
).to_return(body: body.to_json)
)
.to_return(body: body.to_json)
end

{
"original_fields" => foo,
"alternative_fields" => (thing_one(id, api) + thing_two(
id,
api
))
.sort
}
14 changes: 14 additions & 0 deletions fixtures/small/paren_expr_calls_actual.rb
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
16 changes: 16 additions & 0 deletions fixtures/small/paren_expr_calls_expected.rb
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
Loading
Loading