简体   繁体   English

VS2012:与JSHint一起使用时缩进JavaScript中的switch case

[英]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, JavaScript中Visual Studio 2012中的Switch case的默认缩进是,

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. 我正在使用JShint来验证JavaScript代码,它尖叫着我说缩进是不正确的。 It expects the case to align just below switch 它希望caseswitch下方对齐

Are there any editor settings which can align the switch cases as JSHint expects it to be? 是否有任何编辑器设置可以对齐开关案例,因为JSHint期望它? or is there a property in JSHint which will ignore this style of indentation? 或者JSHint中是否有一个属性会忽略这种缩进方式?

What am I missing? 我错过了什么?

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

You can use: 您可以使用:

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

Or, in .eslintrc.yml : 或者,在.eslintrc.yml

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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