ESLint warning ES6 consistent-return rule

Viewed 55009

I get an ESLint warning:

Expected to return a value art the end of arrow function ( consistent-return)

errors.details.forEach((error) => {
  const errorExists = find(errObj, (item) => {  // <== ESLint warning
    if (item && item.field === error.path && item.location === location) {
      item.messages.push(error.message);
      item.types.push(error.type);
      return item;
    }
  });
  if (!errorExists) {
    errObj.push({
      field: error.path,
      location: error.location,
      messages: [error.message],
      types: [error.type]
    });
  }
});

However if I insert a return

  const errorExists = find(errObj, (item) => {    // <== ESLint warning
    if (item && item.field === error.path && item.location === location) {
      item.messages.push(error.message);
      item.types.push(error.type);
      return item;
    }
    return;   // <== inserted return
  });

Then no more warning on this line , but then I get 2 warnings on the inserted return ...

Arrow function expected a return value (consistently-return) Unnecessary return statement (no-useless-return) I don't see how to solve correctly this issue .. any feedback welcome

2 Answers
Related