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

🐛 noDelete is trying to fix unsetting HTMLElement dataset properties #1765

Closed
1 task done
chrisj opened this issue Feb 7, 2024 · 4 comments · Fixed by #1820
Closed
1 task done

🐛 noDelete is trying to fix unsetting HTMLElement dataset properties #1765

chrisj opened this issue Feb 7, 2024 · 4 comments · Fixed by #1820
Assignees
Labels
A-Linter Area: linter S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project

Comments

@chrisj
Copy link

chrisj commented Feb 7, 2024

Environment information

https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/dataset

>  When the attribute is set, its value is always converted to a string. For example: element.dataset.example = null is converted into data-example="null".

> To remove an attribute, you can use the delete operator: delete element.dataset.keyname.

What happened?

delete el.dataset.dateOfBirth;
changed to
el.dataset.dateOfBirth = undefined;

Expected result

delete el.dataset.dateOfBirth;
left as is or...
el.removeAttribute('data-date-of-birth');

I'm not sure which is preferable at least in terms of performance.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@ematipico
Copy link
Member

ematipico commented Feb 7, 2024

Doesn't this work with the code action provided?

@chrisj
Copy link
Author

chrisj commented Feb 7, 2024

@ematipico could you explain, I'm not that familiar with biome.
We are using "@biomejs/biome": "1.4.1", and run it via biome lint .

@ematipico
Copy link
Member

Is the code suggested by Biome still work for what you're doing?

el.dataset.dateOfBirth = undefined;

@chrisj
Copy link
Author

chrisj commented Feb 7, 2024

No because When the attribute is set, its value is always converted to a string so dateOfBirth becomes the string "undefined"

el = document.createElement("div");
el.dataset.dateOfBirth = undefined;
<div data-date-of-birth="undefined"></div>

@ematipico ematipico added S-Help-wanted Status: you're familiar with the code base and want to help the project A-Linter Area: linter S-Bug-confirmed Status: report has been confirmed as a valid bug labels Feb 7, 2024
@ematipico ematipico self-assigned this Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter S-Bug-confirmed Status: report has been confirmed as a valid bug S-Help-wanted Status: you're familiar with the code base and want to help the project
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants