issue #550 - Allow non-indented "break" in "switch" statement #568
Conversation
Thanks for contributing! One of the design approaches for validateIndentation is that it should require almost no configuration. The current validateIndentation, for example, allows both indented case vs. switch or not, depending on the style of the first case statement. You should be able to do a similar technique with case vs. break. Can you please explore that before introducing new options? |
Ok, it seems more easier this way. So I will remove those parameters and let it work as you said for initialization. I just have one question about "You should be able to do a similar technique with case vs. break". switch(value){
case '1':
break;
case '2':
break;
} For "break", do I need to consider the same things and have the same style for all "break" in the same switch statement ? The following example is OK switch(value){
case '1':
break;
case '2':
break;
} But this one should not work switch(value){
case '1':
break;
case '2':
break;
} |
Yes. Thanks for tackling this! |
I think this should be OK |
So how do I enforce the following? switch (foo) {
case 'bar':
break;
case 'bob':
break;
} (Crockford style) |
Hi Ronkorving, By default, crockford style indentation is working fine (even before this issue).
If you're looking for a way to be more strict, only accept this indentation style and refuse all others. Unfortunately there is no way to do this for the moment. |
db9f580
to
2fa147c
Compare
Hi, something new here? Bests |
In #550 @mikesherov said 3 weeks ago :
but after that nothing changed, this issue is still a "new rule value" and the #550 is still open. |
@kefniark thanks for contributing. Occasionally, I have other priorities that get in the way of developing and maintaining free software. As soon as I find some time, this will be reviewed and merged, just like the dozens of releases that came before it. |
@kefniark reviewing now. Thanks again for the patience. |
var loc = node.loc; | ||
if (indents === 0) { | ||
linesToCheck[loc.end.line - 1].popAfter = false; | ||
if (linesToCheck[loc.end.line - 2].push !== 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
save linesToCheck[loc.end.line - 2]
off into a variable please.
@kefniark ping! |
@mikesherov pong! |
No worries. Whenever you can... we all get busy ;-) |
Ok, so I fixed most importants problems that you have noticed :
I replaced it with a BreakStatement iteration which doesn't need any foreach loop and which is more simple. I don't know why I directly did it like this last month :/ |
@kefniark, can you please rebase this pull request? Also, have you run |
@kefniark I don't know what you did, but whatever it is isn't right. |
Yes I know, I tried to use a tool provided by phpstorm which should have rebase my forked repo. It seems that he have merged all the update since the fork. |
@@ -45,6 +48,21 @@ module.exports.prototype = { | |||
return firstContent; | |||
} | |||
|
|||
function markBreakPop(node, indents) { | |||
var loc = node.loc; | |||
if (indents !== 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this line up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
meaning, move the entire if above the var declaration.
@kefniark thanks again! Once these minor style nits are addressed, this should be good to go! |
Hi, Just updated my
I had I tried: "validateIndentation": {
"indentSize": 4,
"allowBreakUnindented": true
}, or even: "validateIndentation": {
"indentChar": "\t",
"indentSize": 4,
"allowBreakUnindented": true
}, But I have a syntax error. How to use this feature? Bests |
@sylouuu try just {
validateIndentation: 4
} |
That was my old config, and I have the error for break indentation.
|
@sylouuu, JSCS looks at the first break statement it encounters in your code, and uses that as the standard for the rest of your code. Do you have an indented break anywhere in your code? |
@sylouuu, thanks again for contributing. Can you please file an issue rather than comment on a PR so if there is a bug, others will see it? |
@mikesherov Done #689 |
I just modified validate-indentation.js to allow non-indented "break" in a case statement.
I also modified and add new unit tests to match those changes.
List of proposal :
So, this rule default behavior doesn't change at all.
New functionnalities are just options that you can enable or not.
with allowBreakUnindented = false (default)
with allowBreakUnindented = true (fix #550 issue)
And 'allowCaseUnindented' parameter is the same thing for 'case' indentation in the switch statement.
For initialization, you can still use :
validateIndentation: '\t'
validateIndentation: 4
But you can also use an object with optional parameters :
validateIndentation: { indentChar: '\t', indentSize: 2, allowBreakUnindented: true}