javascriptjslint

Wrap a ternary expression in parens, with a line break after the left paren


jslint is telling me to do this:

Wrap a ternary expression in parens, with a line break after the left paren.

To this line: "wrapper": (index < allWrappers.length) ? allWrappers[index] : allWrappers[allWrappers.length - 1]

Inside here:

  function findPlayers() {
    const allCovers = document.querySelectorAll(".cover");
    const allWrappers = document.querySelectorAll(".wrap");
    allCovers.forEach(function addToPlayers(cover, index) {
      players.push({
        "cover": cover,
        "wrapper": (index < allWrappers.length) ? allWrappers[index] : allWrappers[allWrappers.length - 1]
      });
    });
  }

What would that line get changed to?


Solution

  • It wants you to do this:

    "wrapper": (
      (index < allWrappers.length) ? allWrappers[index] : allWrappers[allWrappers.length - 1]
    )