npmecmascript-695% confidence\u2191 98

eslint object-shorthand error with variable passed in

Full error message
I have the following function that is setting up a select2 plugin, which needs selects to stay open if they are multiple but closed if they are not:

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

However, when I try to run this code, the eslint checker is giving me an error (on the line shown above) of:

  error  Expected property shorthand  object-shorthand

I have done a search and read the docs but it doesn't show how you are meant to use a variable and the unaccepted answer on this question seems to think it may be a bug in eslint (although I have found no evidence to support that)

Is there a way to make this work or should I just disable the rule for that line?

An excerpt from eslint regarding the issue: 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. Change closeOnSelect: closeOnSelect to just closeOnSelect

API access

Get this solution programmatically \u2014 free, no authentication.

curl https://depscope.dev/api/error/8f7daa12bb23507bfed1dfb362aa701edb12a8d1a1896f8737a96f629398821c
hash \u00b7 8f7daa12bb23507bfed1dfb362aa701edb12a8d1a1896f8737a96f629398821c
eslint object-shorthand error with variable passed in — DepScope fix | DepScope