Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions 13 src/services/formatting/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,7 @@ namespace ts.formatting {

rule("NoSpaceBeforeNonNullAssertionOperator", anyToken, SyntaxKind.ExclamationToken, [isNonJsxSameLineTokenContext, isNonNullAssertionContext], RuleAction.Delete),
rule("NoSpaceAfterNewKeywordOnConstructorSignature", SyntaxKind.NewKeyword, SyntaxKind.OpenParenToken, [isNonJsxSameLineTokenContext, isConstructorSignatureContext], RuleAction.Delete),
rule("SpaceLessThanAndNonJSXTypeAnnotation", SyntaxKind.LessThanToken, SyntaxKind.LessThanToken, [isNonJsxSameLineTokenContext], RuleAction.Space),
];

// These rules are applied after high priority
Expand Down Expand Up @@ -349,6 +350,18 @@ namespace ts.formatting {
];
}

/**
* A rule takes a two tokens (left/right) and a particular context
* for which you're meant to look at them. You then declare what should the
* whitespace annotation be between these tokens via the action param.
*
* @param debugName Name to print
* @param left The left side of the comparison
* @param right The right side of the comparison
* @param context A set of filters to narrow down the space in which this formatter rule applies
* @param action a declaration of the expected whitespace
* @param flags whether the rule deletes a line or not, defaults to no-op
*/
function rule(
debugName: string,
left: SyntaxKind | ReadonlyArray<SyntaxKind> | TokenRange,
Expand Down
8 changes: 8 additions & 0 deletions 8 tests/cases/fourslash/formattingDoubleLessThan.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
///<reference path="fourslash.ts"/>
// https://github.com/microsoft/TypeScript/issues/14589

/////*1*/if (<number>foo < <number>bar) {}

format.document();
goTo.marker("1")
verify.currentLineContentIs(`if (<number>foo < <number>bar) { }`)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.