Skip to content

Commit

Permalink
Ignore calls to a method named innerText
Browse files Browse the repository at this point in the history
  • Loading branch information
camchenry committed Jul 13, 2023
1 parent 8d691db commit af415a6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/rules/no-innerText.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
4 changes: 4 additions & 0 deletions tests/no-innerText.js
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
{
Expand Down

0 comments on commit af415a6

Please sign in to comment.