switch-colon-spacing

在 switch 语句的冒号周围强制使用空格

一些该规则报告的问题可以通过 --fix 命令行选项 自动修复

冒号周围的间距提高了 case/default 子句的可读性。

规则详情

此规则控制 switch 语句中 casedefault 子句的冒号周围的间距。此规则仅在连续标记存在于同一行时才进行检查。

此规则有 2 个布尔值选项。

{
    "switch-colon-spacing": ["error", {"after": true, "before": false}]
}
    VBbTTou+IX+f4RnNFvd40KbFMeoMCMO/OT+hIhoPZ93iJf/qQXPcB8cfhK+UgQ3u0NcX2CBpRKGvmjCS0h3OGN9RqRoycmj/mjpKPOejJKuFZgHjTfQkcr7E7e+8oYCjfNpSufW1FF/bDIg60ChQyweNoShexYgVskIjJa8Kvp06yvnuvajaeURRC4GDQu9z1ulL3KmRLBMLyv2ONCwmgVaVjT51Ilfwb1AmoUQpu+md6Ma3KcwcOVj46AhbBu+vEdXdfnvjophtIl+aT+T4HWrgpB/9R70TcK4cX3930SNS7pwgPWFqe3ToTtnVrB6UiRKRA8/hNWX79Nj2M9Hlvt+XaJs9DZAQh/8lyHqWH9EWp6GfjkJjH4etFwPH3B8UQiFIQbQOMtN8/XkHzlgBFgBkeLGjchj5Mtxo8FKQFJc=

IgbHXOREhuUzqrkIHAUBELO1IBTM0/W5rjS4T6KeTRJddVuoa/qPZgBhw0wa2au1

/*eslint switch-colon-spacing: "error"*/

switch (a) {
    case 0 :break;
    default :foo();
}

FphvHt5MK/G5o4JKMpo8wFZScNX7kGyQzE3xqEeYlFcVQkbgr+qufrIGgDR/9BRp

/*eslint switch-colon-spacing: "error"*/

switch (a) {
    case 0: foo(); break;
    case 1:
        bar();
        break;
    default:
        baz();
        break;
}

NBEefc1CN+XRp5pJaWmRQpAh45OKQQ4hybFbx2m0Q1WUKZh+tw2yGXabyGqCcjVIT1K+ZUry3Hw3jaqo18zck2x/oHkYLSyKWiiPnkeSC6+AmBZoKDpXAU8mQ4Qs6CyU

/*eslint switch-colon-spacing: ["error", {"after": false, "before": true}]*/

switch (a) {
    case 0: break;
    default: foo();
}

nQP82WYZJTVvhOZX4UTE6BGa+QzT/v191gP7NeBEE3R9YUr7Y1r81JNk1jlJtKjXSJS6Ms5pK4k3yfF68itI/Lsna1Hn7MewurUeD2A7E6BE2DoiIUBOI5bAOR7JZsiP

/*eslint switch-colon-spacing: ["error", {"after": false, "before": true}]*/

switch (a) {
    case 0 :foo(); break;
    case 1 :
        bar();
        break;
    default :
        baz();
        break;
}

何时不使用

OgAT0/NaMCAsrHQH0W8h2MKE2CzeUUzAVWY6PqZC53fODRQpfp6PRugp2l/V9qL2G4mS5D4O4ref1kDAgjabsa1wNg5jRqnR/XlGpUlejzDuX2q4hzcFZ/Da7I0ArzddTKHVKuVmIJ4qCC+1dwEDrA==