Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore calls to a method named innerText #455

Merged
merged 1 commit into from
Jul 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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