-
Notifications
You must be signed in to change notification settings - Fork 235
Incorrect indentation after case statement #298
Comments
^ Same. |
I agree with you guys, but I've looked at the javascript language-settings file and I'm a bit stumped as to how to fix it myself. Anyway, I think this goes back to Crockford (aaargh!) who advocated using 4 spaces for indents which led to very deep indents under |
This is why I hate people. |
I used to be a hater. But I learned to love the 2 space indent and embraced it in all it's glory 😄 🎉 Edit: full disclosure, I still use the tab key, but it gets converted to 2 spaces in code automagically. |
Looks like this is addressed in #372 |
I don't know if anyone is watching this thread, but this is the one I could find on this issue that is still open. Currently this behavior is disabled because "it wouldn't know when to outdent": language-javascript/spec/javascript-spec.coffee Line 1726 in 55af017
I think this is an oversight - it should be possible to tell when to outdent. You should outdent when you see another I would love to see this as at least an opt-in feature. Doesn't have to be the default, but I don't see any theoretical reason it shouldn't be possible. |
I agree that this is not an impossible task, but it is not trivial:
That is actually not correct. The issue is that if you don't use
Indenting the above example as:
would actually mislead the user into thinking that the scope of the first case statement ends when the Now, practically speaking, most people will follow the recommended practice of always using a I'm in the camp of the former, so I would actually aim for a logic where we do indent if there is a BTW, none of this is currently possibly in atom.io given that the indentation is inductive (just from the previously line to the current without look-ahead or anything). But in the new tree-sitter based logic this will be possible, so this is a good time to discuss this. |
I would disagree with the idea that the editor should help the user do things right through indentation in this case. While indentation does help with flow interpretation, here it would be the job of a linter, not indentation. For example, what if a user's (ill-advised) intention with the following block is to execute block A and B on case 1, but only block B on case 2?
In this situation the indentation makes perfect sense - it would be up to a linter to advise the user on the poor design. Further indenting
This I was not aware of, and is very interesting. I do hope that with new indentation logic, this issue might be revisited. |
Just in terms of soliciting input, do you think the following would make sense? switch (i) {
case 1:
// block A
case 2:
// block B
break;
} The logic being that I'm really not clear what the right thing to do is, so discovering all perspectives seems important. We are actually revisiting this in the new logic -- that's why I'm chiming in here, because I'm trying to contribute a logic that works for everyone (to the degree possible, given that some of it is seems to be a matter of opinion). You can get a sense of where my mind is at by using my sane-indentation package, which is where I'm developing a new logic I want to propose. |
Personally, there are two perspectives I've seen on switch indentation, the only difference being in the indentation level of the
Type B is all I ever see in javascript - type A is found in the linux kernel style guide and other older guides. I've grow accustomed to type B since I've been writing mostly js lately. I do think that all Thank you for your work on these packages! I just installed sane-indentation and will check it out. |
My two cents would be to have this be the default indentation: switch (i) {
case 1:
//code
case 2:
//fall through code
break;
case 3:
//more code
default:
//etc.
} Simple, clean and concise. |
At the very least, the indentation that @adamreisnz demonstrates should at least be possible if not the default. |
I want the indentation shown in @adamreisnz's post. But I also want it to work for other tabspacings, such as 4-spaced tabbing |
Year passed, time to bring this up. It's quite annoying bug. |
Not sure if this is the right repo or if the language deals with indentation rules, but consider the following:
Pressing
enter
after thecase 'bar
:' statement indents the next line at the same level ascase
. I would expect it to increase indentation by one unit.The text was updated successfully, but these errors were encountered: