-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
RightCurlyCheck: split option into 2 properties #4086
Comments
@rnveach It took me a long time understanding these examples.
To my mind, they all should be a violation for alone option. These are ok as for me. I agree.
Why? Why it should behave as alone?
And once again this will lead us to misunderstanding in future. |
@rnveach |
That is what it means generally, but remember it applies to the
Since the properties are named
Please remember there is separate
It is to reproduce |
That is a problem, I guess. You try to suggest adding new options which main purpose is to help to resolve other options problems (SAME, ALONE_OR_SINGLELINE), however, ALONE option does not have these problems at all now. ALONE purpose is clear now and does not need additional workarounds. Could you please give an example what is wrong with ALONE, why do we need to have Please, understand what I mean. All your examples are good to resolve problems and incorrect behavior of ALONE_OR_SINGLELINE, SAME brace policies, yet, ALONE is not affected by the problems mentioned now. |
Current documentation on
If you run the first post's example against
If it fixes problems, then what is the matter with combing Also, if we don't split the properties into 2 then that means we need to multiply the options for the single property to get the same result. |
Right now the documentations says that
It does not say that right curly must be alone on the line with some statement before or after. It clearly states that no other tokens should be on the line.
I meant that the options behavior is not controversial as the behavior of SAME and ALONE_OR_SINGLELINE.
Why should it be applied to before or after the curly? It should be applied to the the whole line (before and after), isn't it? OK, lets assume we will have an ability to set before or after for alone. What should the user set for this example? public class A {
void foo1() { } // line 2
} // line 3 beforeOption = ? |
|
@rnveach My proposal: From my point of view, these names for the options and their values will be more verbose, but ```?`` still remains and that is the problem with my proposal ( |
After private discussion with @rnveach we both agreed that I suggested the following names:
where NL - new line, NONL - no new line. In my opinion, the existing option values (ALONE, SAME, SINGLELINE) can be replaced with: ALONE -> beforeBrace = NL, afterBrace = NL; @rnveach does not support my idea about SINGLELINE replacement with the suggested beforeBrace and afterBrace values:
@rnveach |
@rnveach , I tried to understand new design several times , spent a lot of time on it and failed.
this blow my mind...... ================ Example that you have in description is expected behavior, especially with consideration of #5970 ("Bad samples for rcurly of RighCurly") and #5945 ("New Check: RightCurlyOfExpression"). ============= I propose to change strategy and try one more time from scratch. Even more lets think about it as new Check, not as update for existing and use names that are clear and have nothing in common with any other implementation. Lets imagine that there is no validation for right curly at all and we do all from scratch. |
It is whatever you wish to decide but I don't see a reason to keep old RightCurly when it is so vague and misleading. If conflicts ever occurred, we would either be required to make overrides or suppress one of the checks. |
RightCurly might be bad and problematic, but it is in use in Google config. Messing it with such big update will be completed for users and us. In new Check we have freedom to avoid all know problems, make it mature by several releases and eventually substitute in Google config. All who like old Check will continue to use it till find it inconvenient and migrate to new Check. New Check design, as for now, is also far from ideal, so I propose restart discussion from scratch, looks like in last comments there is some light to make it more clear. |
After discussing with @romani on right curly options for
RightCurlyCheck
when reviewing #4085 (comment) and how documentation for them should be expanded, it has become apparent that the rules are not so simple to fit into 3 values for a single property.As example shows, there is no consistency in how brace should be validated. Should it require
\n}
,}\n
, or allowed to be all single line? As it stands now, our own checkstyle config will allow in bad examples if we don't see them first. IMO,RightCurlyCheck
should control every aspect of the curlies placement.I propose we split
option
into 2 properties to control the placement before and after the}
.I propose the names
beforeOption
andafterOption
.beforeOption
will have the valuesalone
andsingleline
.afterOption
will have the valuesalone
andsame
.I don't think
beforeOption
needssame
as I can't imagine anyone writing like that. All my examples useif
andif-else
to show single block, multiple-blocks, and demonstrate behavior of conditional-multiblocks. Examples can apply to any other token liketry
/catch
, etc.alone
means\n
should come before or after curly. 'after' is only considered if it has a multi-block statement after it as documented further down.if (condition) { }
violation for alone beforeif (condition) { \n}
ok for alone beforeif (condition) { \n test(); }
violation for alone beforeif (condition) { } else {
violation for alone afterif (condition) { } \n else {
ok for alone aftersame
means\n
should not come after curly. 'after' is only considered if it has a multi-block statement after it as documented further down.if (condition) { }
ok for same afterif (condition) { } else {
ok for same afterif (condition) { } \n else {
violation for same aftersingleline
means\n
should not come before the right curly unless it is not on the same line as the left curly. If it is not on the same line, it will behave asalone
.if (condition) { }
ok for singlelineif (condition) { \n}
ok for singlelineif (condition) { \n test(); }
violation for singlelineFor
afterOption
, it is connected to the next multi-block statement (Ex:else
ofif
,catch
oftry
). If there is no next multi-block statement (if
with noelse
) and no continuation of the current statement, it will specifically default toalone
and allow nothing after it.beforeOption
has no connection to what comes before it except forsingleline
option as described above.Examples:
if (condition) { } int i = 5;
1 violation using any value ofafterOption
.if (condition) { }\n
ok with any value ofafterOption
.if (condition) { } else {
1 violations withalone
onafterOption
. ok withsame
.if (condition) { }\n else {
1 violations withsame
onafterOption
. ok withalone
.I finally propose that any changes we make to
RightCurlyCheck
should be mirrored inLeftCurlyCheck
. This part could be done in a separate issue. I am just mentioning it so we don't forget.The text was updated successfully, but these errors were encountered: