heinetz: eslint meckert ...

Hallo Forum,

ich habe mal wieder Probleme mit einer Notation, die eslint nicht mag.

/**
 * Get the closest parentElement of a given element by selector
 *
 * @param  {element} element          The element to start from
 * @param  {string}  parentSelector   The parentSelector to find
 * @return {element}                  The closest element
 */
const getClosest = (element, parentSelector) => {
  let el = element;
  while (el.parentNode.nodeType === 1) {
    el = el.parentNode;
    const matches = (el, selector) => {
      return (
        el.matches ||
        el.matchesSelector ||
        el.msMatchesSelector ||
        el.mozMatchesSelector ||
        el.webkitMatchesSelector ||
        el.oMatchesSelector
      ).call(el, selector);
    };
    if (matches(el, parentSelector)) {
      return el;
    }
  }
  return null;
};

export default getClosest;

arrow-body-style ‘Unexpected block statement surrounding arrow body’

Kann mir jemand verraten, wie ich die Notation so anpasse, dass der Linter zufrieden ist?

danke und

beste gruesse, heinetz

  1. Tach!

    arrow-body-style ‘Unexpected block statement surrounding arrow body’

    Ich rate mal, dass du da abkürzen sollst. Statt

    x => { return x * x; }
    

    kannst du schreiben

    x => x * x;
    

    Also wann immer nur ein einzelnes Return-Statement im Body einer Fat-Arrow-Function steht, kann man die Klammern und das return weglassen.

    dedlfix.

    1. jo, das passt. danke.