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
max-len: comments: ignores JSX #12213
Comments
Hi @avalanche1, thanks for the issue. Is the issue that we ignore JSX, or that comments are not ignored if they are not the last/only token on the line? If my hypothesis is correct, then this example should not warn: export function ScoringResultsItem() {
return (
<List.Item>
<Checkbox checked={state.checked}>
<Avatar src={bankDatum.logoURL} />
{
/* Some really really really really really really really really really long comment */
}
<a href={bankDatum.PAURL} target="_blank">
{bankDatum.name}
</a>
</Checkbox>
</List.Item>
);
} In this case though, maybe the issue is that it's impossible to write a comment in JSX without going into code block mode first? And that the best way to do that with minimum ugliness is to have the braces on the same line? (Note: I don't know JSX very well, please bear with me.) If I've understood the situation correctly, then I think we can consider an enhancement here (not a bug fix, as according to my understanding, the rule is currently working as designed). |
@platinumazure Taking a quick look at the code, that seems correct! I do think it makes sense for us to account for the opening and closing brackets when checking comments using {
/* Some really really really really really really really really really long comment */
}
{/* Some really really really really really really really really really long comment */} I think it should only ignore/account for the brackets when the brackets only contain a comment, though - otherwise, it should behave as it does now. |
In my understanding, for the moment Eslint treats JSX comment construct (i.e. |
@avalanche1 That's right - just for clarity though, |
This issue looks similar to #11270. I wonder if we can standardize around what we consider a "line that only contains a comment" in JSX across our rules. |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
I am championing this as a semver-minor bug fix to the default behavior (citing the precedence set here). |
👍 I agree that this can be a semver-minor change, and that generally speaking we should consider the curlies part of the comment boundary in JSX. Should we also require that the curlies contain only a comment? For example, I would think the first case below should be valid but not the second: <div>
{/* this long comment should not violate max-len ignoring comments */}
{42 /* this long comment that contains code inside the curlies should be invalid */}
</div> |
@btmills Totally agreed! Sorry I wasn't clearer on this point. |
Ah I see where I missed that you had already written that. My fault! |
This is accepted now. |
Tell us about your environment
^6.1.0
12.9.0
6.9.0
What parser (default, Babel-ESLint, etc.) are you using?
"@typescript-eslint/parser": ^2.0.0
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
What did you expect to happen?
no warnings logged
What actually happened? Please include the actual, raw output from ESLint.
6:1 warning This line has a length of 96. Maximum allowed is 90 max-len
Are you willing to submit a pull request to fix this bug?
nope
The text was updated successfully, but these errors were encountered: