【问题标题】:jshint logs missing semicolon after yield in cojshint 记录 co 中的 yield 后缺少分号
【发布时间】:2016-06-15 07:30:01
【问题描述】:

我正在使用 JSHint 进行 linting,但在使用 co 时遇到了问题,在 yield 语句中的生成器中我收到错误:第 18 行第 28 行缺少分号。

co(function *() {

let orgAccounts = yield OrgAccount.findAll({accountId: account.id});

}).catch((err) => {
  console.log(err);
});

.jshintrc 文件看起来像:

{
 "expr": true,
 "node": true,
 "esversion": 6,
 "bitwise": true,
 "eqeqeq": true,
 "immed": true,
 "latedef": "nofunc",
 "newcap": true,
 "noarg": true,
 "undef": true,
 "smarttabs": true,
 "asi": true,
 "debug": true,
 "noyield": true
}

我该如何解决?

【问题讨论】:

    标签: jshint co yield-keyword


    【解决方案1】:

    我更改了我的 .jshintrc 文件:

    {
     "expr": true,
     "node": true,
     "esversion": 6,
     "bitwise": true,
     "eqeqeq": true,
     "immed": true,
     "latedef": "nofunc",
     "newcap": true,
     "noarg": true,
     "undef": true,
     "smarttabs": true,
     "asi": true,
     "debug": true,
     "noyield": true
    }
    

    "asi": false 需要分号。

    此选项禁止有关缺少分号的警告。社区中有不少人传播了很多关于分号的 FUD。常见的误解是分号始终是必需的(它们不是)并且它们是不可靠的。 JavaScript 有关于分号的规则,所有浏览器都遵循这些规则,因此您可以决定是否应该在代码中使用分号。

    JSHint Options Reference

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-28
      • 2019-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      • 1970-01-01
      • 2021-11-27
      相关资源
      最近更新 更多