Standardize DOM node type checking
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 59.8k
- Forks
- 20.4k
- Avg merge
- 17h 32m
- Merged PRs (30d)
- 4
Description
Description
Our style guide says that we identify DOM elements with (Boolean) object.nodeType, but that's not exactly true. We actually use it to identify DOM nodes, but even setting aside semantics, there is a case where an object with a truthy nodeType property can avoid the DOM node path: setting data.
This means that .data can succeed or fail based on some rather trivial differences, which makes me uncomfortable. We should have a single "is DOM node" test, applied consistently everywhere. nodeType will always have certain characteristics on real DOM nodes (existence, "number" type, integer, positive), but we can use any subset thereof—I'm leaning towards typeof obj.nodeType === "number" or obj && "nodeType" in obj, because any given kind of input seems unlikely to change classification. And whatever we pick, the style guide will also need an update.
A macro would be really nice, because it seems silly not to inline such trivial code, but I think we can continue to live without something like sweet.js for now.
Link to test case
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with src/data/var/acceptData.js and compare its nodeType check with the style guide section linked in the issue. Use the linked jsbin to understand the inconsistent .data behavior, then identify the project-wide checks that need one consistent rule. Done means the checks agree and the style guide reflects the chosen behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- documentation, frontend
- Issue type
- Refactor
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100