Skip to content

Implement enhanced CLI error formatting #62130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

anivar
Copy link

@anivar anivar commented Jul 26, 2025

Fixes #45717

Summary

This PR implements the enhanced error formatting proposed in #45717, improving the readability and visual structure of TypeScript compiler error messages.

Changes

Before:

index.ts:2:1 - error TS2588: Cannot assign to 'a' because it is a constant.

2 a = "123"
  ~

After:

● index.ts:2:1 TS2588
 | a = "123" 
 ▔ 
 Cannot assign to 'a' because it is a constant.

Implementation Details

  • Added visual bullet points (●) as markers for each diagnostic
  • Moved error codes (TS####) to the right and de-emphasized with grey color
  • Replaced tilde (~) underlines with overlines (▔) for cleaner appearance
  • Added vertical bars (|) to frame code snippets
  • Implemented terminal width detection (minimum 60 columns required)
  • Falls back to original formatting for narrow terminals
  • Maintains full backwards compatibility

Testing

  • Tested with various error types and edge cases
  • Verified fallback behavior for narrow terminals
  • Ensured related information is properly formatted
  • All existing tests pass

Notes

  • The enhanced formatting only activates when terminal width >= 60 columns
  • Environment variables (COLORTERM, TERM_PROGRAM, TERM) are checked for terminal capability detection
  • No breaking changes to existing API

- Add visual bullet points (●) for each diagnostic
- Move error codes (TS####) to the right and de-emphasize with grey
- Replace tilde (~) underlines with overlines (▔)
- Add vertical bars (|) for better code snippet framing
- Terminal width detection with 60+ column requirement
- Fallback to original formatting for narrow terminals
- Full backwards compatibility maintained
@Copilot Copilot AI review requested due to automatic review settings July 26, 2025 04:05
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Jul 26, 2025
@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jul 26, 2025
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR implements enhanced CLI error formatting for TypeScript compiler diagnostics to improve readability and visual structure. The changes introduce a more modern error display format with visual markers, cleaner code presentation, and improved terminal compatibility detection.

Key Changes

  • Replaces traditional tilde underlines with overlines and adds visual bullet points for error markers
  • Implements terminal width detection to determine when to use enhanced formatting (minimum 60 columns)
  • Maintains full backwards compatibility by falling back to original formatting for narrow terminals

- Fix length parameter with proper default value handling
- Add proper bounds checking for overline calculation
- Simplify terminal detection with explicit checks for limited terminals
- Handle multi-line errors gracefully by showing only first line
- Add CI environment detection with opt-in support
- Respect NO_COLOR environment variable
@anivar
Copy link
Author

anivar commented Jul 26, 2025

@microsoft-github-policy-service agree company="Foodhub"

- Fix trailing commas in function parameters
- Fix quote consistency (single quotes to double quotes)
- Fix empty line spacing according to dprint style guide
@i-ayushh18
Copy link

🤖 AI Assistant: Task completed: PR #62130: Implement enhanced CLI error formatting

URL: https://github.com/microsoft/TypeScript/pul...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
For Uncommitted Bug PR for untriaged, rejected, closed or missing bug
Projects
Status: Not started
Development

Successfully merging this pull request may close these issues.

[CLI DX] Improve positioning of compiler error messaging info
3 participants