Fix JSDoc comment formatting with tab indentation #1900
Merged
+38
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
When formatting TypeScript/JavaScript files with tab indentation (
ConvertTabsToSpaces: false
), the formatter incorrectly placed spaces before tabs in JSDoc comment lines, resulting in malformed indentation.For example, formatting this code:
Would produce incorrect output with spaces before tabs:
Notice how the comment lines now have the pattern
space tab *
instead of the correcttab space *
.Root Cause
The bug was in the
getIndentationString
function ininternal/format/span.go
. When generating indentation with tabs, the function was concatenating spaces before tabs instead of tabs before spaces:This was opposite to the TypeScript reference implementation in
src/services/formatting/formatting.ts
:Solution
Fixed the concatenation order to match the TypeScript implementation:
This ensures that tabs always come before spaces in indentation strings, which is the standard convention and matches editor expectations.
Testing
Added a comprehensive test case
format JSDoc with tab indentation
that validates:\t *
(tab, space, asterisk)\t*
(space, tab, asterisk) is not presentAll existing tests continue to pass, confirming no regressions.
Fixes the issue described in the problem statement where JSDoc comments with tab indentation were being incorrectly formatted.
Original prompt
Fixes #1899
💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.