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

Invalid comment string in jsx, multiline exprassion inside {} #22

Open
MuhammadSawalhy opened this issue Sep 9, 2021 · 2 comments
Open
Labels
bug Something isn't working

Comments

@MuhammadSawalhy
Copy link

Here is the current commentsting:

image

Here is what I expected:

image

JoosepAlviste added a commit that referenced this issue Sep 9, 2021
In JSX, a multi-line call expression should have the normal js
`commentstring`. For example:

```jsx
<div>
  {hello({
    foo: 'bar',
  })}
</div>
```

Commenting the line with `foo: 'bar',` shouldn't use the JSX comment
style.

There are other similar cases that might fail though, for example, a
multi-line array or string, but those are even rarer cases.

Related to #22
@JoosepAlviste
Copy link
Owner

Hey @MuhammadSawalhy, thanks for the bug report!

I added an extra rule for this exact use-case, but in general, it's a bit tricky to detect similar multi-line expressions inside {} with the current logic. I think that it would require thinking through the problem a bit more.

Together with the {}, the treesitter node is called jsx_expression but we can't really configure jsx_expression: '// %s', because then commenting a single-line expression would be incorrect. The first idea I had was that we could detect if the parent of a node is jsx_expression. We could have a hypothetical configuration like so:

javascript = {
  __default = '// %s',
  jsx_element = '{/* %s */}',
  jsx_fragment = '{/* %s */}',
  jsx_attribute = '// %s',
  comment = '// %s',
  __parent = {
    -- if a node has this as the parent, use the `//` commentstring
    jsx_expression = '// %s',
  },
}

Anyways, I'm not sure if I'll have time to implement this soon. Hopefully the current fix is good enough for now 😄

@tbo
Copy link

tbo commented Apr 3, 2022

I've got a similar issue with html string literals:

Screen Shot 2022-04-03 at 11 57 44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants