K
K
kirillleogky2019-12-28 16:34:30
JavaScript
kirillleogky, 2019-12-28 16:34:30

How to solve no-cond-assign ESLint error?

function findPos(obj) {
  let objCur = obj;
  let curleft = 0;
  let curtop = 0;
  if (objCur.offsetParent) {
    do {
      curleft += objCur.offsetLeft;
      curtop += objCur.offsetTop;
    } while (objCur = objCur.offsetParent);
    return { x: curleft, y: curtop };
  }
  return undefined;
}

In this line, eslint throws an error:
} while (objCur = objCur.offsetParent); - Unexpected assignment within a 'do...while' statement  no-cond-assign

Tell me how to solve the problem
Canvas comes as a value -const canvas = document.getElementById('canvas');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Suha, 2019-12-28
@kirillleogky

objCur === objCur.offsetParent
Linter will not swear, but I think that this code will not work correctly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question