forked from microsoft/DefinitelyTyped-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
no-any-union.ts
34 lines (32 loc) · 830 Bytes
/
no-any-union.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
import { createRule } from "../util";
import { AST_NODE_TYPES } from "@typescript-eslint/utils";
const rule = createRule({
name: "no-any-union",
defaultOptions: [],
meta: {
type: "problem",
docs: {
description: "Forbid a union to contain `any`",
recommended: "error",
},
messages: {
anyUnion: "Including `any` in a union will override all other members of the union.",
},
schema: [],
},
create(context) {
return {
// eslint-disable-next-line @typescript-eslint/naming-convention
TSUnionType(node) {
const hasAnyType = node.types.some((t) => t.type === AST_NODE_TYPES.TSAnyKeyword);
if (hasAnyType) {
context.report({
messageId: "anyUnion",
node,
});
}
},
};
},
});
export = rule;