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
Allow JSDoc make arrow parens needed #12995
Comments
I'd support an option to allow existing parentheses if there are any comments inside. |
I would like to work on this. Here is what I am planning as @mdjermanovic suggested to have an option for this.
Example: /*eslint arrow-parens: [2, "as-needed", { "requireCommentsParams": true}]*/
const f = (/** @type {number} */a) => a + a; // correct
const f = (/* */a) => a + a; // Incorrect
const f = (a) => a + a; // Incorrect Though I would even back this without having a separate option for it but having a separate option is good for initial stages then move to default PS: just found out, Espree doesn't have Please correct me if I am wrong ! |
@anikethsaha Thanks for being willing to work on this. Please note that this proposal hasn't been accepted yet, and we generally recommend that you wait until an issue has been accepted before implementing (to avoid throwaway work). Regarding handling comments, ESLint doesn't use |
Sure ! I will wait till it gets accepted.
Thanks for the link ! |
I think there is no need to check if the comment is not empty, just whether there is at least one comment between const f = (/**/a) => a + a;
const g = (//
a) => a + a;
const h = (a/**/) => a + a;
const i = (a/**/,) => a + a;
const j = (a //
) => a + a; |
I see, these cases do make sense to keep it as it is 👍 Lost of comments is not so great options especially for use cases like jsdoc |
Unfortunately, it looks like there wasn't enough interest from the team Thanks for contributing to ESLint and we appreciate your understanding. |
I'll champion this. |
@mdjermanovic Are you still championing this? If so, I think we need to try to reach consensus on its approval. It's been open for quite a while now. |
It looks like a bug to me. Autofix should not remove comments accidentally. |
There is indeed the autofix bug, and there is this request to not warn at all about unneeded parentheses when there's a comment inside (if the new option is set or as the new default behavior). Is it accepted to not warn at all, as the new default behavior (no option) which would solve both the bug and this issue? |
I think it should be default behavior cause removing of comments seems bug right? |
Aside from the autofix bug, the removal of the parentheses changes the semantic under TypeScript --checkjs type checking. // The type annotation applies to parameter x.
const f = (/** @type {string} */ x) => x
// The type annotation applies to the arrow function expression.
const f = /** @type {string} */ x => x |
Yes, but the bug can be fixed by modifying the fixer to remove just parens and keep everything inside, or more likely by not doing the autofix if there are any comments inside (given the @golopot's comment). This is different from not reporting the error at all. Which is also fine, just wanted to doublecheck what's exactly accepted. |
yeah IMO, not to warn should be the default behavior. |
Personally, yes. If there is a comment in a parameter list, I think someone intentionally did so, therefore the relative comment location should be kept. Removing parentheses of a parameter list moves the relative comment location from "before a parameter" to "before a function". We cannot remove the parentheses along with keeping the "before a parameter", so I think the parentheses are needed. |
Agreed, thanks for clarifying! |
Is anyone working on this? if not, I can work on this 👍 |
Most likely not, feel free to work on this! |
…3312) * Fix: no reportin for comments inside (fixes #12995) * Update: handled some cases for comments in parens * Chore: added some more tests * Chore: removed unnecessary blanklines * Update: added docs example and function refactor * Update: changed hasComment checks * Update: refactore and docs update * Docs: added docs example
What rule do you want to change?
Does this change cause the rule to produce more or fewer warnings?
Fewer
How will the change be implemented? (New option, new default behavior, etc.)?
Prefer new option, make default should be fine too.
Please provide some example code that this change will affect:
Demo
What does the rule currently do for this code?
What will the rule do after it's changed?
No error.
Are you willing to submit a pull request to implement this change?
Not.
My IDE seems do not know type of variable
a
in(/** @type {number} */a) => a
if the braces are omitted. I want to make JSDoc a exception of validatingarrow-parens: "as-needed"
.The text was updated successfully, but these errors were encountered: