Skip to content

Commit

Permalink
Add formatting rule for import type import keyword and open paren (#2…
Browse files Browse the repository at this point in the history
  • Loading branch information
weswigham authored May 3, 2018
1 parent 406ca06 commit 0d7d75e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/services/formatting/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ namespace ts.formatting {
rule("NoSpaceBeforeDot", anyToken, SyntaxKind.DotToken, [isNonJsxSameLineTokenContext], RuleAction.Delete),
rule("NoSpaceAfterDot", SyntaxKind.DotToken, anyToken, [isNonJsxSameLineTokenContext], RuleAction.Delete),

rule("NoSpaceBetweenImportParenInImportType", SyntaxKind.ImportKeyword, SyntaxKind.OpenParenToken, [isNonJsxSameLineTokenContext, isImportTypeContext], RuleAction.Delete),

// Special handling of unary operators.
// Prefix operators generally shouldn't have a space between
// them and their target unary expression.
Expand Down Expand Up @@ -641,6 +643,10 @@ namespace ts.formatting {
return context.contextNode.kind === SyntaxKind.ArrowFunction;
}

function isImportTypeContext(context: FormattingContext): boolean {
return context.contextNode.kind === SyntaxKind.ImportType;
}

function isNonJsxSameLineTokenContext(context: FormattingContext): boolean {
return context.TokensAreOnSameLine() && context.contextNode.kind !== SyntaxKind.JsxText;
}
Expand Down
9 changes: 9 additions & 0 deletions tests/cases/fourslash/importTypeFormatting.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/// <reference path="fourslash.ts"/>

////var y: import("./c2").mytype;
////var z: import ("./c2").mytype;

format.document();
verify.currentFileContentIs(
`var y: import("./c2").mytype;
var z: import("./c2").mytype;`);

0 comments on commit 0d7d75e

Please sign in to comment.