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

feat: add jsx-no-comment-text-nodes rule #1352

Merged
merged 4 commits into from
Dec 10, 2024
Merged

Conversation

marvinhagemeister
Copy link
Contributor

Passing code comments as JSX text nodes is a common mistake. This Lint rule checks if a code comment was accidentally passed as JSX text by checking if it starts with // or /*.

src/rules/jsx_no_comment_text_nodes.rs Outdated Show resolved Hide resolved
src/rules/jsx_no_comment_text_nodes.rs Outdated Show resolved Hide resolved
fn jsx_text(&mut self, node: &JSXText, ctx: &mut Context) {
//
let value = &node.inner.value;
if value.starts_with("//") || value.starts_with("/*") {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these be stricter checks? Eg. ensuring there are only single lines or for block comments that it ends with */?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too difficult to do, because of expression nodes. In practice this is imo good enough.

a = <p>/* foo {text}</p>

@marvinhagemeister marvinhagemeister merged commit 26e9df1 into main Dec 10, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants