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

jsx-one-expression-per-line: ignoreComments #287

Open
3 of 4 tasks
otomad opened this issue Feb 29, 2024 · 1 comment
Open
3 of 4 tasks

jsx-one-expression-per-line: ignoreComments #287

otomad opened this issue Feb 29, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@otomad
Copy link

otomad commented Feb 29, 2024

Clear and concise description of the problem

Adding a comment at the end of a jsx line can unexpectedly raise jsx-one-expression-per-line. Although I don't assume comment in jsx as a common expression.

For example:

<Foo>bar</Foo>{/* TODO: This line may be deleted. */}

However, the comment {/* */} will be treat as a common expression {}.

Suggested solution

Add a ignoreComments option to the jsx-one-expression-per-line rule.

"@stylistic/jsx/jsx-one-expression-per-line": [<enabled>, { "allow": "none"|"literal"|"single-child", "ignoreComments": boolean }]

Alternative

Or add a new rule jsx-lines-around-comment which similar to lines-around-comment but in JSX, and also ignore comments in jsx-one-expression-per-line.

Additional context

Although maybe it is better to write as

{/* TODO: The next line may be deleted. */}
<Foo>bar</Foo>

I am more accustomed to add a comment after lines in JavaScript.

const foo = "bar"; // TODO: Something todo.

Validations

Contributes

  • If this feature request is accepted, I am willing to submit a PR to fix this issue
@otomad otomad added the enhancement New feature or request label Feb 29, 2024
@otomad otomad closed this as completed Feb 29, 2024
@otomad otomad reopened this Mar 1, 2024
@01taylop
Copy link

01taylop commented Apr 2, 2024

The rule from eslint-plugin-react added a non-jsx option "to allow non-JSX children in one line". I wonder if that change would resolve this issue too?

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