-
-
Notifications
You must be signed in to change notification settings - Fork 265
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
Analyzer that checks the breaking behavior of expression bodies #1575
Comments
@cbersch I think you are looking for this one: https://josefpihrt.github.io/docs/roslynator/analyzers/RCS0032 |
@josefpihrt Awesome, this is indeed, what I was looking for. Thank you! |
@josefpihrt Maybe I was too fast to close this issue: public int[] Allocate(int size) => new int[size];
public int[] Allocate2(int size) =>
new int[size]; With settings
Expected public int[] Allocate(int size)
=> new int[size];
public int[] Allocate2(int size)
=> new int[size]; Actual public int[] Allocate(int size) => new int[size];
public int[] Allocate2(int size)
=> new int[size]; |
Ok, so first of all, RCS0032 (and also RCS0027, RCS0028, RCS0052) are designed to change the position of an operator (e.g. What you want is something like: always put expression-body (of method, property etc.) on the next line. Right? It could be something like this (just a proposal):
or
Position of arrow token would still be determined by RCS0032. |
Yes.
Yes, both should work. I can't judge, which one fits best in the naming scheme, yet.
That's also, what I would expect. |
@josefpihrt To get started I implemented an analyzer for this. I'm not yet sure, how different analyzers are supposed to interact. As existing analyzers for this situation we have
Now I implemented an additional analyzer (see https://github.com/cbersch/roslynator/tree/put-expression-body-on-its-own-line) object Foo() => null; After object Foo()
=> null; The break position also depends on the option Is that a valid approach for an additional analyzer? What do you think? If that's fine, I'll proceed. |
Hi @cbersch, sorry for late response, I was busy at work. Please proceed with the PR 👍 . I'll review it and add comments after it's created. From what I've seen I think it would be also great to update code fixer for RCS1016 and https://josefpihrt.github.io/docs/roslynator/refactorings/RR0169 |
@josefpihrt arrowExpressionClause = arrowExpressionClause.PrependToLeadingTrivia(CSharpFactory.NewLine()); which had no effect. Can you give me a hint, how to add a new line in these cases? |
@cbersch From this one line of code I'm not sure where is the problem. Could you do the changes directly in the MR (even if it does not work) and we can discuss it there. |
* Add option roslynator_expression_body_style_on_next_line to enable breaking of expression bodies on new line. The line position is determined by option roslynator_arrow_token_new_line.
In our code we prefer having single line methods and properties as expression bodies with
However, we also like to break before
=>
to easier see the actual body.For that I would like to request an analyzer and fix.
Example
What do you think of it?
It could be an option like
The text was updated successfully, but these errors were encountered: