-
Notifications
You must be signed in to change notification settings - Fork 56
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
Sorbet: newline inserted between sig and method #253
Comments
Happy to attempt a PR for this if there's consensus that rufo should behave this way, and ideally with a pointer or two for someone new to the project's code. |
@bmulholland Definitely makes sense to group them together in that case. A PR would be great :) I would suggest to add a new test file for sorbet type definition examples and follow your nose from there. |
I managed to create a test fine, but a 4000 line ruby file is a little overwhelming. I'm guessing that I'm looking for something that inserts a newline between a ?command? and a method call? So maybe in Do you have any tips on how to trace through the commands? Should I just drop a breakpoint at some point? If I do that, how do I know what commands I'm currently parsing? |
@bmulholland Definitely a bit overwhelming. Be nice to break it up a bit. Did start working on refactoring it but that was also trying to implement a new approach for formatting. I would try to condense the test to as little code as possible to start with so the AST is small as well. Then put a breakpoint in the visit method and inspect the node data being passed in. Keep an eye on I had a bit of a look but did not find where the newline was coming from. Doesn't look like it is coming from Feel free to push up a branch with any questions and I can take a look. |
Thanks for your tips, that was really helpful. The root cause is here. (And the comment is super obvious once I found it!) That conditional returns true, which then adds a second new line after I'm trying to figure out what the proper fix for this would be. I feel like Do you think this is a good approach? If so, here's the
What's a robust way to parse this? I feel like doing |
@bmulholland A quick hack for preventing extra line after NOTE: Like you said, this approach does not look robust at all; it boils down to removing the newline after the Additionally it would be nice to first detect if if exp[0] == :method_add_block and exp[1][0] == :method_add_arg and exp[1][1][0] = :fcall and exp[1][1][1][1] == "sig"
@output.delete_suffix!("\n")
end |
Thanks for the code @marras. I agree with you - this should probably trigger only when I suppose your usage is also a +1 for adding this feature into |
I landed here because of this issue. It looks like Rufo can't really be used when there are Sorbet annotations. E.g., here's an example of Rufo-formatted code: sig { returns(Statute) }
def s
T.cast(__getobj__, Statute)
end
sig { params(params: T.untyped).returns(String) }
def beautify_my_html(params)
PublicLaw::Html.beautify_html(body, mark: params[:highlight], hide: params[:hide])
end
sig { returns(String) }
def to_s
short_citation + " " + s.name
end
sig { returns(String) }
def short_name
Base.shorten(name)
end Maybe the logic for fixing this could be simpler if there was a |
I would also like to voice my support for this issue. |
I'm adopting sorbet and adding method signatures. Since these are connected things, I expect them to be grouped together, as you can see in the Sorbet docs: https://sorbet.org/docs/sigs. However, when formatting with rufo, a newline is inserted:
The text was updated successfully, but these errors were encountered: