From af415a614178b8905dbdc6a91c844b56f9cbb36e Mon Sep 17 00:00:00 2001 From: Cam McHenry Date: Thu, 13 Jul 2023 14:28:46 +0000 Subject: [PATCH] Ignore calls to a method named innerText --- lib/rules/no-innerText.js | 4 ++++ tests/no-innerText.js | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/lib/rules/no-innerText.js b/lib/rules/no-innerText.js index daf80491..5f024d09 100644 --- a/lib/rules/no-innerText.js +++ b/lib/rules/no-innerText.js @@ -12,6 +12,10 @@ module.exports = { create(context) { return { MemberExpression(node) { + // If the member expression is part of a call expression like `.innerText()` then it is not the same + // as the `Element.innerText` property, and should not trigger a warning + if (node.parent.type === 'CallExpression') return + if (node.property && node.property.name === 'innerText') { context.report({ meta: { diff --git a/tests/no-innerText.js b/tests/no-innerText.js index ac38001b..d7510f90 100644 --- a/tests/no-innerText.js +++ b/tests/no-innerText.js @@ -11,6 +11,10 @@ ruleTester.run('no-innerText', rule, { { code: 'document.querySelector("js-flash-text").textContent = "bar"', }, + { + // This is unrelated to the `HTMLElement.innerText` property, and should not trigger a warning + code: 'var text = element.textContent()', + }, ], invalid: [ {