From 1012e56fb2c0b5275e6a737181e62f586de991f1 Mon Sep 17 00:00:00 2001 From: Pavel Birukov Date: Wed, 7 Nov 2018 08:29:01 +0200 Subject: [PATCH] Don't check space after import-ed type. Fixes #3987 (#4243) --- src/rules/whitespaceRule.ts | 7 +++-- test/rules/whitespace/all/import-type.lint | 32 ++++++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 test/rules/whitespace/all/import-type.lint diff --git a/src/rules/whitespaceRule.ts b/src/rules/whitespaceRule.ts index b633e529714..e05e591b0bb 100644 --- a/src/rules/whitespaceRule.ts +++ b/src/rules/whitespaceRule.ts @@ -335,11 +335,14 @@ function walk(ctx: Lint.WalkContext) { break; case ts.SyntaxKind.ImportKeyword: if ( - parent.kind === ts.SyntaxKind.CallExpression && - (parent as ts.CallExpression).expression.kind === ts.SyntaxKind.ImportKeyword + utils.isCallExpression(parent) && + parent.expression.kind === ts.SyntaxKind.ImportKeyword ) { return; // Don't check ImportCall } + if (utils.isImportTypeNode(parent)) { + return; // Don't check TypeQuery + } // falls through case ts.SyntaxKind.ExportKeyword: case ts.SyntaxKind.FromKeyword: diff --git a/test/rules/whitespace/all/import-type.lint b/test/rules/whitespace/all/import-type.lint new file mode 100644 index 00000000000..64ef7f5cb5f --- /dev/null +++ b/test/rules/whitespace/all/import-type.lint @@ -0,0 +1,32 @@ +[typescript]: >=2.9.0 + +const foo: import("bar"); +const foo: import ("bar"); + +function foo(a: import("bar")): import("baz") {} +function foo(a: import ("bar")): import ("baz") {} + +const foo = (a: import("bar")): import("baz") => {}; +const foo = (a: import ("bar")): import ("baz") => {}; + +type foo = { bar: import("baz") } & import("qux"); +type foo = { bar: import ("baz") } & import ("qux"); + +interface Foo { + bar: import("baz"); + qux: import ("quux"); +} + +class Foo { + bar: import("baz"); + qux: import ("quux"); +} + +/** + * @param bar { import("qux") } + * @param baz { import ("qux") } + */ +function foo(bar, baz) { } + +type foo = Bar; +type foo = Bar;