-
-
Notifications
You must be signed in to change notification settings - Fork 353
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
442 additions
and
98 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,19 +1,35 @@ | ||
# Prefer using `.dataset` on DOM elements over `.setAttribute(…)` | ||
# Prefer using `.dataset` on DOM elements over `.setAttribute(…)` and `.removeAttribute(…)` | ||
|
||
✅ *This rule is part of the [recommended](https://github.com/sindresorhus/eslint-plugin-unicorn#recommended-config) config.* | ||
|
||
🔧 *This rule is [auto-fixable](https://eslint.org/docs/user-guide/command-line-interface#fixing-problems).* | ||
|
||
Use [`.dataset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset) on DOM elements over `.setAttribute(…)`. | ||
Use [`.dataset`](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset) on DOM elements over `.setAttribute(…)` and `.removeAttribute(…)`. | ||
|
||
## Fail | ||
|
||
```js | ||
element.setAttribute('data-unicorn', '🦄'); | ||
``` | ||
|
||
```js | ||
element.removeAttribute('data-unicorn'); | ||
``` | ||
|
||
## Pass | ||
|
||
```js | ||
element.dataset.unicorn = '🦄'; | ||
``` | ||
|
||
```js | ||
delete element.dataset.unicorn; | ||
``` | ||
|
||
```js | ||
element.setAttribute('not-dataset', '🦄'); | ||
``` | ||
|
||
```js | ||
element.removeAttribute('not-dataset'); | ||
``` |
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
Oops, something went wrong.