Use numeric literal source text when formatting property access - #64592
Mateusz Burzyński (Andarist) wants to merge 1 commit into
Conversation
|
This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise. |
| return !ast.IsPropertyAccessExpression(context.contextNode) || | ||
| !ast.IsNumericLiteral(context.contextNode.Expression()) || | ||
| strings.Contains(context.contextNode.Expression().Text(), ".") | ||
| strings.Contains(scanner.GetSourceTextOfNodeFromSourceFile(context.SourceFile, context.contextNode.Expression(), false /*includeTrivia*/), ".") |
There was a problem hiding this comment.
this matches Strada that was reading the original source text:
TypeScript/src/services/formatting/rules.ts
Lines 989 to 993 in 050880c
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 1
Open (1)
What changed in this PR
This PR updates the formatter’s integer-literal property access detection to use the numeric literal’s original source text, and re-enables a previously skipped fourslash regression test.
Changes:
- Re-enabled
formatDotAfterNumberfourslash test by removing the unconditional skip. - Updated integer-literal property access detection to inspect the numeric literal’s source text (via
scanner.GetSourceTextOfNodeFromSourceFile) rather than the AST node’sText().
| File | Description |
|---|---|
| tsc/internal/fourslash/tests/formatDotAfterNumber_test.go | Re-enables a regression test covering numeric-literal dot formatting. |
| tsc/internal/format/rulecontext.go | Uses source text for numeric literals to correctly detect . in the literal as written. |
💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
| func isNotPropertyAccessOnIntegerLiteral(context *FormattingContext) bool { | ||
| return !ast.IsPropertyAccessExpression(context.contextNode) || | ||
| !ast.IsNumericLiteral(context.contextNode.Expression()) || | ||
| strings.Contains(context.contextNode.Expression().Text(), ".") | ||
| strings.Contains(scanner.GetSourceTextOfNodeFromSourceFile(context.SourceFile, context.contextNode.Expression(), false /*includeTrivia*/), ".") | ||
| } |
There was a problem hiding this comment.
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
Copilot review overview
Review effort: Lite
Findings: 2
| func isNotPropertyAccessOnIntegerLiteral(context *FormattingContext) bool { | ||
| return !ast.IsPropertyAccessExpression(context.contextNode) || | ||
| !ast.IsNumericLiteral(context.contextNode.Expression()) || | ||
| strings.Contains(context.contextNode.Expression().Text(), ".") | ||
| strings.Contains(scanner.GetSourceTextOfNodeFromSourceFile(context.SourceFile, context.contextNode.Expression(), false /*includeTrivia*/), ".") | ||
| } |

No description provided.