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

Block with long list of block vars doesn't get split onto multiple lines #433

Open
dom-binti opened this issue Jan 31, 2024 · 0 comments
Open

Comments

@dom-binti
Copy link

Blocks with a long list of vars doesn't get split. Eg:

query do |long_arg:, longer_arg:, longerest_arg:, longerester_arg:, very_long_long_long_arg:|
  foo
end

isn't changed when run through stree format.

I started by writing my own plugin for BlockVar adding a group and a couple breakable_emptys, which works and produces output that conforms with line length:

query do |
  long_arg:,
  longer_arg:,
  longerest_arg:,
  longerester_arg:,
  very_long_long_long_arg:
|
  foo
end

The plugin has an issue though with blocks passed to methods with their own long list of args. In its current state, syntax_tree formats it like this:

foo(
  argument,
  argument,
  argument,
  argument,
  argument,
  argument,
  argument,
) { |val| bar }

With the plugin I wrote, that ends up being formatted as

foo(argument, argument, argument, argument, argument, argument, argument) do |
  val
|
  bar
end

presumably because the block var groups are the outermost, and therefore get split first.

Is there a way to tell syntax_tree to break the method call before breaking the block vars?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant