javascript - eslint 对象简写错误,传入变量

标签 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);

但是,当我尝试运行此代码时,eslint 检查器给我一个错误(在上面显示的行上):

error Expected property shorthand object-shorthand

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

有没有办法让这个工作正常,或者我应该禁用该行的规则?

最佳答案

excerpt来自 eslint 关于该问题的信息:

Require Object Literal Shorthand Syntax (object-shorthand) - Rule Details

This rule enforces the use of the shorthand syntax. This applies to all methods (including generators) defined in object literals and any properties defined where the key name matches name of the assigned variable.

改变

closeOnSelect: closeOnSelect

只是

closeOnSelect

关于javascript - eslint 对象简写错误,传入变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47635509/

相关文章:

javascript - 将列表项设置为负顶部的动画会使其他列表项下降

c# - JavaScript 在本地工作,但在部署到网络服务器时无法工作

javascript - 如何使用 TypeScript 和 Angular 2 向 ng2-ckeditor 添加插件?

javascript - 调整图像特定区域的大小

Javascript将多个对象插入一个空对象

reactjs - 忽略 react hook 返回数组中的值 -

javascript - 规则 "eqeqeq"的 ESLint 配置无效

javascript - 用 map (或循环)展平对象数组

javascript - 通过逻辑运算符分配变量值的 typescript 仅使用后一种类型

javascript - 如何修复 'warning Expected ' this' to be use by class method ' eslint 错误?