Javascript: Suggestion to add switch

Created on 8 Apr 2015  路  5Comments  路  Source: airbnb/javascript

Does it make sense to add switch
Because it's not clear add spaces before case or not

switch (expression) {
  case expression:
    statements
    break;
  default:
    statements
}

Or

switch (expression) {
case expression:
  statements
  break;
default:
  statements
}
enhancement

Most helpful comment

You might want to change your eslint config now that 1.0.0 has been released:

"indent": [2, 2, {"SwitchCase": 1}],

All 5 comments

Because you have indentation of 2 spaces and you do indentation after each { + new line, it becomes quite clear you should do.

switch (expression) {
  case expression:
    statements
    break;
  default:
    statements
}

But yeah, could be mentioned because for some reasons autoformatters allow you not to indent case in switch, which is really weird case.

You might want to change your eslint config now that 1.0.0 has been released:

"indent": [2, 2, {"SwitchCase": 1}],

+1 we use extends: "airbnb" and would like "indent": [2, 2, {"SwitchCase": 1}] to be in eslint-config-airbnb.

+1

fwiw I agree that if it's here, the first example (https://github.com/airbnb/javascript/issues/296#issuecomment-91070293) should be the one enforced by the config - however, I'd prefer to ban switch altogether :-) although that should be a different discussion.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ryankask picture ryankask  路  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  路  3Comments

danielfttorres picture danielfttorres  路  3Comments

vsemozhetbyt picture vsemozhetbyt  路  3Comments

tunnckoCore picture tunnckoCore  路  3Comments