简体   繁体   中英

VS2012 : Indentation of switch case in JavaScript when used with JSHint

The default indentation of Switch case in Visual Studio 2012 in JavaScript is like,

switch (dropdownNumber) {
    case 1:
        console.log('reset in 1');
        break;
    case 2:
        console.log('reset in 2');
        break;
    case 3:
        console.log('reset in 3');
        break;
}

I am using JShint to validate the JavaScript code, which screams at me saying the indentation is incorrect. It expects the case to align just below switch

Are there any editor settings which can align the switch cases as JSHint expects it to be? or is there a property in JSHint which will ignore this style of indentation?

What am I missing?

See https://cn.eslint.org/docs/2.13.1/rules/indent#switchcase

You can use:

/*eslint indent: ["error", 2, { "SwitchCase": 1 }]*/

Or, in .eslintrc.yml :

# ...
rules:
  indent:
    - error
    - 2
    - SwitchCase: 1 # <<< Add this
# ...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM