Repository navigation
Preserve trailing double spaces in JSDoc - #18594
Conversation
commit: |
✅ Deploy Preview for prettier ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
| return [" ", line.trimStart()]; | ||
| } | ||
| const content = [" ", line.trim()]; | ||
| if (isJSDoc && line.endsWith(" ")) { |
There was a problem hiding this comment.
There's another choice: ignore after tag (e.g * @type {any} - blah blah ).
There was a problem hiding this comment.
Let's not make things complicated; we can ignore the content.
| * | ||
| * @type {any} | ||
| */ | ||
| let b; |
There was a problem hiding this comment.
Since the character is invisible, please use snippets to test https://github.com/prettier/prettier/blob/main/CONTRIBUTING.md#tests, and assert output directly.
There was a problem hiding this comment.
I moved them to snippets.
| { | ||
| name: "Remove on blank line", | ||
| code: outdent` | ||
| /** | ||
| *${" ".repeat(2)} | ||
| */ | ||
| `, | ||
| output: outdent` | ||
| /** | ||
| * | ||
| */\n | ||
| `, | ||
| }, |
There was a problem hiding this comment.
How should this work? 0 or 2 or 3 spaces?
There was a problem hiding this comment.
I'm going to consider (practical) edge cases more.
There was a problem hiding this comment.
There are more patterns safe to remove trailing double spaces in JSDoc.
/**
* ```
* ^^ spaces here aren't significant
* ```
*
* >
* > ^^ spaces here aren't significant
*/The best change is not obvious since exact behavior will require md parser finally. I'm considering:
- It's worth to handle simple & practical edge case.
- For complex edge cases, both false removal and false preservation won't be so harmful as long as they are rare.
- For false removal, it's same as Prettier stable so not introdured by this change.
- For false preservation, it's new bug introduced by this change. But users can remove them by themselves and Prettier won't revive them. It should rarely happen, though.
There was a problem hiding this comment.
Nah, too much, let's pretend it's not markdown. Only make sure we preserve trailing space. User can use a jsdoc plugin.
|
@seiyab I rewrote the tests to read more easily, and I have a question #18594 (comment), can you check how it works on blank line in markdown? |
| * This is a JSDoc comment with trailing spaces. | ||
| */ | ||
| let x; | ||
| ``` |
There was a problem hiding this comment.
Let's use the API to show the difference
await require('prettier').format('/**\n * With 2 spaces \n */', {parser: 'babel'});
# Prettier stable
// -> '/**\n * With 2 spaces \n */\n'
# Prettier main
// -> '/**\n * With 2 spaces\n */\n'Update code block syntax from JavaScript to Bash in JSDoc entry.
Prettier keeps a trailing double space on the middle lines of a `/**` comment (prettier/prettier#18594, in the pinned 3.9.6): it is a Markdown hard line break that doc tooling renders (prettier/prettier#6793). We printed every aligned line through `trim()`, so the spaces were dropped: ```tsx /** * JSDoc with new line using double space * It's on another line */ ``` Match Prettier's `printIndentableBlockComment`: in a `/**` comment (not `/***`), a middle line whose source ends with two or more spaces keeps exactly two after its trimmed content. A bare `*` line, a single trailing space, the opening line, and non-JSDoc block comments are trimmed as before. The check is textual rather than `comment.is_jsdoc()` because the parser also tags `/***` as JSDoc and Prettier's test is textual. The printer never trims text at a line end, so writing the two spaces before the next hard line break is enough. Fixture `js/comments/jsdoc-trailing-double-space.js` mirrors Prettier's `tests/format/js/comments/trailing-spaces` cases plus a plain `/*` block; its output is byte-identical to Prettier 3.9.8. One line added to `js/crlf/block-comment.js` pins the CRLF output. `cargo test -p oxc_formatter`, clippy and fmt are clean; I did not run the `tasks/coverage` idempotency suites locally. Written with help from an AI assistant (Claude); reviewed and tested by me. Closes #26854 --------- Co-authored-by: leaysgur <[email protected]>
Description
Closes: #6793
I'm not sure whether this is approved as feature by members. Feel free to reject this PR.
Checklist
docs/directory).changelog_unreleased/*/XXXX.mdfile followingchangelog_unreleased/TEMPLATE.md.