Repository navigation
Conversation
Added locStart import and improved comment handling for decorators.
Prettier now maintains comment placement before exported decorators, preventing additional blank lines during formatting.
Automation signalsActivity patterns show signs of automation. Evidence
Last 5 PRs:
This is an automated analysis by AgentScan |
Updated changelog entry for issue prettier#20180 to reflect changes regarding comments before exported decorators.
✅ 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!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Sorry, this was closed by mistake, reopening. |
| return [ | ||
| path.key === "declaration" && isExportDeclaration(parent) | ||
| ? hardline | ||
| ? hasCommentBeforeDecorator |
There was a problem hiding this comment.
Does it work if we only check that there is a leading comment?
There was a problem hiding this comment.
Yes, it works. A comment placed after a decorator does not attach as a leading comment of the declaration, so the position comparison was redundant. Simplified in ddef773: the check is now just the presence of a leading comment, the unused locStart import is dropped, and the decorator, decorator-comment, and comment format suites all pass unchanged (2,234 tests).
A comment placed after a decorator does not attach as a leading comment of the declaration, so comparing its position against the first decorator was redundant. Checking for the presence of a leading comment covers the same cases. Signed-off-by: Charan Rathore <[email protected]>
| // line on each formatting pass. | ||
| const hasCommentBeforeDecorator = isNonEmptyArray( | ||
| getComments(node, CommentCheckFlags.Leading), | ||
| ); |
There was a problem hiding this comment.
hasComment(node, CommentCheckFlags.Leading)
There was a problem hiding this comment.
Done in 9b19af1 - now on hasComment(node, CommentCheckFlags.Leading). The decorator and comment format suites still pass unchanged.
Signed-off-by: Charan Rathore <[email protected]>
# Conflicts: # src/language-js/print/decorators.js
commit: |
Description
Fixes #20175. A leading comment between
exportand a decorator already prints its own separator. The decorator printer added a hardline too, so formatting the result again added another blank line. It now leaves that extra hardline out when the comment sits before the first decorator. This preserves a blank line if one was already in the input and leaves export declarations without that comment unchanged.The TypeScript fixture covers both issue examples, a pre-existing blank line, multiple decorators, default export, and a comment after a decorator. The snapshot and formatter's two-pass checks confirm the output is stable. Inline block comments remain inline with the decorator, rather than using the multiline layout suggested in the issue.
Instinct assisted with the change and tests.
Checklist
docs/directory). (Not applicable: no API or CLI change.)changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md. (Rename 20175.md and heading to the PR number when known.)