@@ -64,6 +64,43 @@ func TestCommentFormatting(t *testing.T) {
6464 assert .Check (t , ! contains (secondFormatted , " sync x()" ), "should not corrupt async to sync" )
6565 assert .Check (t , contains (secondFormatted , "async" ), "should preserve async keyword on second pass" )
6666 })
67+
68+ t .Run ("format JSDoc with tab indentation" , func (t * testing.T ) {
69+ t .Parallel ()
70+ ctx := format .WithFormatCodeSettings (t .Context (), & format.FormatCodeSettings {
71+ EditorSettings : format.EditorSettings {
72+ TabSize : 4 ,
73+ IndentSize : 4 ,
74+ BaseIndentSize : 0 ,
75+ NewLineCharacter : "\n " ,
76+ ConvertTabsToSpaces : false , // Use tabs
77+ IndentStyle : format .IndentStyleSmart ,
78+ TrimTrailingWhitespace : true ,
79+ },
80+ InsertSpaceBeforeTypeAnnotation : core .TSTrue ,
81+ }, "\n " )
82+
83+ // Original code with tab indentation (tabs represented as \t)
84+ originalText := "class Foo {\n \t /**\n \t * @param {string} argument - This is a param description.\n \t */\n \t example(argument) {\n console.log(argument);\n \t }\n }"
85+
86+ sourceFile := parser .ParseSourceFile (ast.SourceFileParseOptions {
87+ FileName : "/test.ts" ,
88+ Path : "/test.ts" ,
89+ }, originalText , core .ScriptKindTS )
90+
91+ // Apply formatting
92+ edits := format .FormatDocument (ctx , sourceFile )
93+ formatted := applyBulkEdits (originalText , edits )
94+
95+ // Check that tabs come before spaces (not spaces before tabs)
96+ // The comment lines should have format: tab followed by space and asterisk
97+ // NOT: space followed by tab and asterisk
98+ assert .Check (t , ! contains (formatted , " \t *" ), "should not have space before tab before asterisk" )
99+ assert .Check (t , contains (formatted , "\t *" ), "should have tab before space before asterisk" )
100+
101+ // Verify console.log is properly indented with tabs
102+ assert .Check (t , contains (formatted , "\t \t console.log" ), "console.log should be indented with two tabs" )
103+ })
67104}
68105
69106func contains (s , substr string ) bool {
0 commit comments