通过JSHint忽略切换 [英] switch fall through being ignored by JSHint

查看:84
本文介绍了通过JSHint忽略切换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在通过 JSHint 运行我的代码,我遇到了这个错误:

I'm running my code through JSHint, and I'm hitting this error:


案例之前预期中断语句

在这段代码中:

switch(true)
{
    // Renames skill1=abc to section_8_1_body=abc
    case Major === 0 && Minor === 0 && Patch < 433:
        upgraded = upgraded.replace(/(\s+)skill(\d)=/gm, '$1section_8_$2_body=');
    /*falls through*/

    // Example
    case Major === 0 && Minor === 0 && Patch < 442:
        console.log('test');
    /*falls through*/
}

代码检查版本信息一个文件,并升级它以与最新版本的软件兼容。因此,有意为案例 s通过,以便可以通过多个版本升级文件。

The code checks version information for a file, and upgrades it to be compatible with the latest version of the software. It's therefore intentional for the cases to fall through, so that a file can be upgraded through multiple versions.

但是,我仍然收到错误消息, / *通过* 添加,即使它应该是有效的

However, I still receive the error message, with /*falls through* added, even though it is supposedly valid.

我怎样才能允许我的 case s在JSHint中成功通过?

How can I allow my cases to fall through successfully in JSHint?

推荐答案

JSHint似乎期望评论是在案例之前的行上。

JSHint seems to expect the comment to be on the line right before the case.

// Example
/* falls through */
case Major === 0 && Minor === 0 && Patch < 442:
    console.log('test');

根据描述中的blob / adbaf51bcbcc96fc58cf4ea78476225e8dba92c5 / src / jshint.js#L3604-L3609>,否则将不会确认评论:

According to the description in the source code, it won't acknowledge the comment otherwise:

// You can tell JSHint that you don't use break intentionally by
// adding a comment /* falls through */ on a line just before
// the next `case`.

这篇关于通过JSHint忽略切换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆