eslint对象 - 在

时间:2017-12-04 14:26:09

标签: javascript ecmascript-6 eslint

我有以下功能正在设置一个select2插件,如果它们是多个则需要选择保持打开但如果不是则关闭:

function setUpSelects($selects, closeOnSelect) {
  $selects.each((i, item) => {
    const $item = $(item);

    $item.select2({
      closeOnSelect: closeOnSelect,  // <-- error on this line
      minimumResultsForSearch: Infinity,
      placeholder: $item.data('placeholder') || $item.attr('placeholder'),
    });
  });
}

setUpSelects($('select:not([multiple])'), false);
setUpSelects($('select[multiple]'), true);

然而,当我尝试运行此代码时,对象检查器给出了一个错误(在上面显示的行上):

  

错误预期的属性简写对象 - 简写

我已经完成了搜索并阅读了文档,但它并没有显示您是如何使用变量的,而this question上的未接受的答案似乎认为它可能是一个错误(尽管这是一个错误)我没有发现任何证据支持这一点)

有没有办法让这项工作或我应该禁用该行的规则?

2 个答案:

答案 0 :(得分:37)

来自eslint的关于此问题的excerpt

  

需要对象文字速记语法(对象速记) - 规则详细信息

     

此规则强制使用速记语法。这适用于   在对象文字和任何文件中定义的所有方法(包括生成器)   定义了键名与分配名称匹配的属性   变量

更改

 public string Start_Appl()
    {    string path="C:\\Windows\\System32\\notepad.exe";
         ProcessStartInfo psi = new ProcessStartInfo();
         psi.UseShellExecute = true;
         psi.LoadUserProfile = true;
         psi.WorkingDirectory = path;
         psi.FileName = path;

         Process.Start(psi);


        return "ok";

    }

closeOnSelect: closeOnSelect

答案 1 :(得分:3)

rule检查是否使用了对象文字速记syntax,例如{a, b}而不是{a: a, b: b}。该规则是可配置的,有关更多详细信息,请参见options

尽管这种速记语法很方便,但在某些情况下,您可能不想强制使用它。您可以在配置中禁用检查:

// .eslintrc.json

{
  "rules": {
    // Disables the rule. You can just remove it,
    // if it is not enabled by a parent config.
    "object-shorthand": 0
  }
}

对于 TSLint ,有一个不同的option

// tslint.json

{
  "rules": {
    // Disables the rule. You can just remove it,
    // if it is not enabled by a parent config.
    "object-literal-shorthand": false
  }
}
相关问题