mardi 5 mai 2020

Javascript: error Unnecessary use of boolean literals in conditional expression no-unneeded-ternary

I am new to javascript and I can't seem to wrap my head around a small issue I have. I looked everywhere, I tried many other options, but nothing seems to work. This function works just fine, but I get this error message:

error  Unnecessary use of boolean literals in conditional expression  no-unneeded-ternary

Here is my code:

const valid = (email) => {
  // TODO: return true if the `email` string has the right pattern!
  const match = (email.match(/^([a-zA-Z0-9_\-.]+)@([a-zA-Z0-9_\-.]+)\.([a-zA-Z]{2,5})$/) ? true : false);
  return match;
};

Anyone knows how I could write this differently? Thank you in advance for your help! Olivier

Aucun commentaire:

Enregistrer un commentaire