-
-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
prefer-dom-node-text-content
: Check destructuring, Use suggestion i…
…nstead of auto-fix (#1417)
- Loading branch information
Showing
6 changed files
with
276 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,35 @@ | ||
# Prefer `.textContent` over `.innerText` | ||
|
||
Enforces the use of `.textContent` over `.innerText` for DOM nodes. There are [some advantages of using `.textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent), like performance and more predictable behavior when updating it. | ||
Enforces the use of `.textContent` over `.innerText` for DOM nodes. | ||
|
||
This rule is fixable. | ||
There are [some advantages of using `.textContent`](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent), like performance and more predictable behavior when updating it. | ||
|
||
Note that there are [differences](https://developer.mozilla.org/en-US/docs/Web/API/Node/textContent#differences_from_innertext) between them. | ||
|
||
## Fail | ||
|
||
```js | ||
const text = foo.innerText; | ||
``` | ||
|
||
```js | ||
const {innerText} = foo; | ||
``` | ||
|
||
```js | ||
foo.innerText = '🦄'; | ||
``` | ||
|
||
## Pass | ||
|
||
```js | ||
const text = foo.textContent; | ||
``` | ||
|
||
```js | ||
const {textContent} = foo; | ||
``` | ||
|
||
```js | ||
foo.textContent = '🦄'; | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,200 @@ | ||
# Snapshot report for `test/prefer-dom-node-text-content.mjs` | ||
|
||
The actual snapshot is saved in `prefer-dom-node-text-content.mjs.snap`. | ||
|
||
Generated by [AVA](https://avajs.dev). | ||
|
||
## Invalid #1 | ||
1 | node.innerText; | ||
|
||
> Error 1/1 | ||
`␊ | ||
> 1 | node.innerText;␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | node.textContent;␊ | ||
` | ||
|
||
## Invalid #2 | ||
1 | node.innerText = 'foo'; | ||
|
||
> Error 1/1 | ||
`␊ | ||
> 1 | node.innerText = 'foo';␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | node.textContent = 'foo';␊ | ||
` | ||
|
||
## Invalid #3 | ||
1 | innerText.innerText; | ||
|
||
> Error 1/1 | ||
`␊ | ||
> 1 | innerText.innerText;␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | innerText.textContent;␊ | ||
` | ||
|
||
## Invalid #4 | ||
1 | const {innerText} = node; | ||
|
||
> Error 1/2 | ||
`␊ | ||
> 1 | const {innerText} = node;␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | const {textContent: innerText} = node;␊ | ||
` | ||
|
||
> Error 2/2 | ||
`␊ | ||
> 1 | const {innerText} = node;␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | const {textContent: innerText} = node;␊ | ||
` | ||
|
||
## Invalid #5 | ||
1 | const {innerText,} = node; | ||
|
||
> Error 1/2 | ||
`␊ | ||
> 1 | const {innerText,} = node;␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | const {textContent: innerText,} = node;␊ | ||
` | ||
|
||
> Error 2/2 | ||
`␊ | ||
> 1 | const {innerText,} = node;␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | const {textContent: innerText,} = node;␊ | ||
` | ||
|
||
## Invalid #6 | ||
1 | const {innerText: text} = node; | ||
|
||
> Error 1/1 | ||
`␊ | ||
> 1 | const {innerText: text} = node;␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | const {textContent: text} = node;␊ | ||
` | ||
|
||
## Invalid #7 | ||
1 | ({innerText} = node); | ||
|
||
> Error 1/2 | ||
`␊ | ||
> 1 | ({innerText} = node);␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | ({textContent: innerText} = node);␊ | ||
` | ||
|
||
> Error 2/2 | ||
`␊ | ||
> 1 | ({innerText} = node);␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | ({textContent: innerText} = node);␊ | ||
` | ||
|
||
## Invalid #8 | ||
1 | ({innerText: text} = node); | ||
|
||
> Error 1/1 | ||
`␊ | ||
> 1 | ({innerText: text} = node);␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | ({textContent: text} = node);␊ | ||
` | ||
|
||
## Invalid #9 | ||
1 | function foo({innerText}) {return innerText} | ||
|
||
> Error 1/2 | ||
`␊ | ||
> 1 | function foo({innerText}) {return innerText}␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | function foo({textContent: innerText}) {return innerText}␊ | ||
` | ||
|
||
> Error 2/2 | ||
`␊ | ||
> 1 | function foo({innerText}) {return innerText}␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | function foo({textContent: innerText}) {return innerText}␊ | ||
` | ||
|
||
## Invalid #10 | ||
1 | for (const [{innerText}] of elements); | ||
|
||
> Error 1/2 | ||
`␊ | ||
> 1 | for (const [{innerText}] of elements);␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | for (const [{textContent: innerText}] of elements);␊ | ||
` | ||
|
||
> Error 2/2 | ||
`␊ | ||
> 1 | for (const [{innerText}] of elements);␊ | ||
| ^^^^^^^^^ Prefer \`.textContent\` over \`.innerText\`.␊ | ||
␊ | ||
--------------------------------------------------------------------------------␊ | ||
Suggestion 1/1: Switch to \`.textContent\`.␊ | ||
1 | for (const [{textContent: innerText}] of elements);␊ | ||
` |
Binary file not shown.