-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Styling compiler specs uniformly #11291
Comments
I'm not too happy about the handling of multiple heredocs. I would prefer to place the starting delimiters in the same line where feasible. That keeps the call context closely together. assert_error <<-CR, <<-ERROR, flags: "foo"
CR
ERROR If editors have problems with that, let's fix the syntax highlighting instead of working around its issues.
Yes, I think this is another benefit of heredocs. It gives context to the literal. We can use that to apply the formatter to embedded code and for syntax highlighting.
I don't think this needs to be a strict rule. Short mutli-line code in double quoted string literals can be okay for some use cases. Many parser and formatter specs are probably better readable as single-line string literals with escaped linebreaks. |
To be precise the syntax highlighters I'm referring to are the Visual Studio Code one and the Atom one (and by extension, the one on GitHub itself). It appears that the same heredocs are handled properly for Ruby in these places. |
And this is where I note that crystal lack
Letting the contents be indented relative to the end marker makes it so much easier to read. Though that is perhaps a separate discussion.. BTW, I'd definitely not assume heredocs to be intended to be formatted as crystal. By default they should be treated as strings and left alone. If some editors don't recognize them properly then that is a bug in those editors. Perhaps with a special flag though? |
You can already do that. Indentation doesn’t matter in code. |
For most of these particular cases, that is probably true. Unless there are specs where the indentation actually do matter (like for example the specs for heredocs themselves, I assume). Using |
#11269 raised some questions about how compiler specs should be styled. As mentioned there, there is some motivation to at least replace code literals with heredocs because they support better error locations. Due to the sheer number of compiler specs, any attempt to unify their style would require a massive effort to implement or undo, so we should agree upon a common style before doing so. My preferences are:
<<-CR
heredocs. The contents should be indented one level relative to the assertion call:<<-ERROR
heredocs. The heredocs themselves should be indented one level relative to the assertion call, and placed entirely after<<-CR
or any other preceding heredocs: (this is mainly because most Crystal syntax highlighters don't play well with multiple heredocs created on the same line)<<-ERROR
which disrupts the flow of those literals):assert_type
).<<-CR
literals should themselves be properly formatted Crystal code. There is no way to enforce this yet; it would be a good idea for the formatter tool to support this.<<-CR
.The text was updated successfully, but these errors were encountered: