Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 3, 2025

  • Understand the issue: multiline ternary expressions with tabs are being formatted with mixed tabs and spaces
  • Create a test to reproduce the issue
  • Investigate the root cause in the indentation calculation logic
  • Fix the indentation calculation for conditional expression branches
  • Verify the fix with the test
  • Run all format tests to ensure no regressions
  • Clean up accidental patch files
  • Run format, lint, and test commands
  • Move test to format_test.go and assert specific output
Original prompt

This section details on the original issue you should resolve

<issue_title>Bad formatting of multiline ternary expression</issue_title>
<issue_description>From microsoft/TypeScript#14494 (original issue was actually fixed in 6, but regressed here)

Format the following code that uses tabs for indentation :

const test = (a: string) => (
	a === '1' ? (
		10
	) : (
		12
	)
)

Bug
You get a mix of tabs and spaces:

const test = (a: string) => (
	a === '1' ? (
   10
	) : (
   12
	)
)
```</issue_description>

## Comments on the Issue (you are @copilot in this section)

<comments>
</comments>

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 3 commits December 3, 2025 21:49
When indentation is -1 (Unknown), prevent arithmetic operations that produce
invalid indentation values. This fixes the issue where multiline ternary
expressions with tabs were being formatted with mixed tabs and spaces.

Co-authored-by: jakebailey <[email protected]>
Copilot AI changed the title [WIP] Fix bad formatting of multiline ternary expression Fix multiline ternary expression formatting with tabs Dec 3, 2025
Copilot AI requested a review from jakebailey December 3, 2025 22:11
Copilot finished work on behalf of jakebailey December 3, 2025 22:11
@jakebailey
Copy link
Member

@copilot You forgot to run test/format/lint/etc

- Format code with dprint
- Use Go 1.22+ integer range syntax in for loops

Co-authored-by: jakebailey <[email protected]>
Copy link
Contributor Author

Copilot AI commented Dec 3, 2025

@copilot You forgot to run test/format/lint/etc

Fixed in a38bd7a. Ran format, lint, and all tests successfully.

Copilot finished work on behalf of jakebailey December 3, 2025 22:27
"github.com/microsoft/typescript-go/internal/parser"
)

func TestTernaryWithTabs(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot just put this in internal/format/format_test.go

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in cbc5012. Moved the test to format_test.go.

Comment on lines 39 to 41
// Check that we don't have mixed tabs and spaces
// The formatted text should only use tabs for indentation
lines := splitLines(newText)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot Just assert a specific output string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in cbc5012. Changed to assert the specific expected output string.

- Moved TestTernaryWithTabs from ternary_test.go to format_test.go
- Changed test to assert specific expected output string
- Removed ternary_test.go file

Co-authored-by: jakebailey <[email protected]>
Copilot AI requested a review from jakebailey December 3, 2025 23:15
Copilot finished work on behalf of jakebailey December 3, 2025 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bad formatting of multiline ternary expression

2 participants