-
Notifications
You must be signed in to change notification settings - Fork 63
add a new no-innerText rule
#30
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
Conversation
| node: node.property, | ||
| message: 'Prefer textContent to innerText', | ||
| fix(fixer) { | ||
| return fixer.replaceText(node.property, 'textContent') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can run this on a codebase with --fix and it will fix it! ✨
| type: 'Identifier' | ||
| } | ||
| ], | ||
| output: 'document.querySelector("js-flash-text").textContent = "bar"' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will assert the output if this rule was run with --fix.
dgraham
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As innerText is aware of CSS styling, it will trigger a reflow, whereas textContent will not.
As good a reason as any to prefer textContent.
keithamus
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🆒
|
I want to merge and publish this but I'm not sure if I have the rights on npm to do that. @josh are you the one that publishes? |
I just added you to our |
textContentseems like a better alternative and we seem to favor that already so if nothing else we can be consistent 😸There are some slight differences between the two and there is probably some code that relies on those differences but there aren't many instances so I can manually check over those to make sure nothing is breaking.
Reading 📚
textContenton MDNinnerTexton MDN