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

fix(jsx): correctly comment first line of JSX #56

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

JoosepAlviste
Copy link
Owner

The first and last lines of JSX should be commented with // %s, rather than {/* %s */}. However, the current way of configuring the plugin does not allow us to check if the current node is a jsx_element with a parent of parenthesized_expression. We could allow checking the parent node in the configuration, but that would be a bit tricky and a lot of work.

Since this is (hopefully) a 1-time exception, then it seems okay to add an explicit check for this. If we have similar cases in the future though, then we should think of making this configurable somehow.

Fixes #29

The first and last lines of JSX should be commented with `// %s`, rather
than `{/* %s */}`. However, the current way of configuring the plugin
does not allow us to check if the current node is a `jsx_element` with a
parent of `parenthesized_expression`. We could allow checking the parent
node in the configuration, but that would be a bit tricky and a lot of
work.

Since this is (hopefully) a 1-time exception, then it seems okay to add
an explicit check for this. If we have similar cases in the future
though, then we should think of making this configurable somehow.

Fixes #29
@JoosepAlviste JoosepAlviste self-assigned this Dec 31, 2022
@JoosepAlviste JoosepAlviste marked this pull request as draft December 31, 2022 21:43
@Slotos
Copy link
Contributor

Slotos commented Nov 15, 2023

A maybe viable idea - generalize this to alternates with an optional "only child" configuration directive. E.g.:

object = { '// %s', { '/* %s */', only_child = "comment" }}, -- first line
jsx_expression = {{ '/* %s */', only_child = "comment" }}, -- later lines

Then, when checking the node, alternates can be checked with something like (node:child_count() != 1 or node:child(1):type() != match.only_child). If it matches, use the alternate, use default if present, fallback to parent otherwise.

A similar "parent" directive could be employed too.

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.

Top-level jsx elements cannot be uncommented
2 participants