forked from microsoft/TypeScript
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathno-type-assertion-whitespace.ts
43 lines (38 loc) · 1.35 KB
/
no-type-assertion-whitespace.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { TSESTree } from "@typescript-eslint/experimental-utils";
import { createRule } from "./utils";
export = createRule({
name: "no-type-assertion-whitespace",
meta: {
docs: {
description: ``,
category: "Stylistic Issues",
recommended: "error",
},
messages: {
noTypeAssertionWhitespace: `Excess trailing whitespace found around type assertion`,
},
schema: [],
type: "problem",
},
defaultOptions: [],
create(context) {
const sourceCode = context.getSourceCode();
const checkTypeAssertionWhitespace = (node: TSESTree.TSTypeAssertion) => {
const leftToken = sourceCode.getLastToken(node.typeAnnotation);
const rightToken = sourceCode.getFirstToken(node.expression);
if (!leftToken || !rightToken) {
return;
}
if (sourceCode.isSpaceBetweenTokens(leftToken, rightToken)) {
context.report({
messageId: "noTypeAssertionWhitespace",
node,
loc: { column: leftToken.loc.end.column + 1, line: leftToken.loc.end.line },
});
}
};
return {
TSTypeAssertion: checkTypeAssertionWhitespace,
};
},
});