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

Validate JSX nesting #25

Open
joshwilsonvu opened this issue May 18, 2022 · 2 comments
Open

Validate JSX nesting #25

joshwilsonvu opened this issue May 18, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@joshwilsonvu
Copy link
Collaborator

Describe the need
Unless you're an HTML expert, it's not always clear exactly when browsers will consider certain patterns invalid, like <div> inside <table> or <p> inside <p>. Browsers don't warn about these issues; instead, they silently try to work around them. It would be nice to give feedback to developers quickly, so there aren't unpleasant surprises later.

Suggested Solution
Static analysis of JSX nesting would be a good fit for an ESLint rule. It should be possible to check JSXOpeningElements, track the last HTML element seen, and validate nesting for the current HTML element, clearing the last seen element when encountering unknown function components.

Possible Alternatives
There's a very new repo that puts this behavior in a Babel plugin, and it's where I got the idea: https://github.com/MananTank/validate-jsx-nesting. However, I don't think Babel is a great fit for giving warnings during development, it's better suited to producing transformed output.

Though none seem to exist, it's possible for a framework-agnostic JSX validation rule to work okay. However, this kind of rule would not be able to validate children of Show, Match, etc.

@joshwilsonvu joshwilsonvu added the enhancement New feature or request label May 18, 2022
@joshwilsonvu joshwilsonvu self-assigned this May 18, 2022
@joshwilsonvu
Copy link
Collaborator Author

@titoBouzout
Copy link
Contributor

we have included this in dom-expressions ryansolid/dom-expressions#350 and the console will display a warning when nesting will be messed up by the browser. It does so by using parse5
In the linked issue there are details, but so far it goes as deep as it can go (example components cannot be resolved)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants