-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
fix(js): Fix comment placement in empty function params #18482
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
base: main
Are you sure you want to change the base?
Conversation
commit: |
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for prettier ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
Description
Fixes an issue where comments in empty function parameters were incorrectly moved after the fat arrow operator (
=>) or into the function body.The problem was caused by
handleCommentInEmptyParensnot being included inhandleOwnLineComment. When a comment is on its own line inside empty parameters, it was processed byhandleOwnLineComment, but sincehandleCommentInEmptyParenswas only inhandleRemainingComment, the comment was incorrectly attached to the function body as a leading comment.Additionally,
handleLastFunctionArgCommentswas being evaluated before the empty params case, causing it to match and move the comment to the function body.Example:
Solution:
handleCommentInEmptyParenstohandleOwnLineCommentbeforehandleLastFunctionArgCommentsChanges
src/language-js/comments/handle-comments.js: AddedhandleCommentInEmptyParenstohandleOwnLineComment, added condition to exclude comments in return value parenthesessrc/language-js/print/function-parameters.js: Added formatting for dangling line comments with proper indentation and line breaksChecklist
docs/directory).changelog_unreleased/javascript/18482.mdfile followingchangelog_unreleased/TEMPLATE.md.Fixes #18208