Skip to content
This repository was archived by the owner on Mar 7, 2025. It is now read-only.

Commit 2c29025

Browse files
committed
Add rule @typescript-eslint/ban-types
1 parent 01c4a95 commit 2c29025

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export type BanTypesOption = {
7+
/**
8+
* An object whose keys are the types you want to ban, and the values are error messages.
9+
*
10+
* @see [types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
11+
*/
12+
types?: Record<
13+
string,
14+
| false
15+
| string
16+
| {
17+
/**
18+
* The message to display when the type is matched.
19+
*
20+
* @see [types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
21+
*/
22+
message: string;
23+
/**
24+
* A string to replace the banned type with when the fixer is run. If this is omitted, no fix will be done.
25+
*
26+
* @see [types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
27+
*/
28+
fixWith?: string;
29+
}
30+
>;
31+
32+
/**
33+
* If you're specifying custom `types`, you can set this to `true` to extend the default types configuration.
34+
*
35+
* @see [extendDefaults](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
36+
*/
37+
extendDefaults?: boolean;
38+
};
39+
40+
/**
41+
* Options.
42+
*/
43+
export type BanTypesOptions = [BanTypesOption?];
44+
45+
/**
46+
* Bans specific types from being used.
47+
*
48+
* @see [ban-types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
49+
*/
50+
export type BanTypesRuleConfig = RuleConfig<BanTypesOptions>;
51+
52+
/**
53+
* Bans specific types from being used.
54+
*
55+
* @see [ban-types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
56+
*/
57+
export interface BanTypesRule {
58+
/**
59+
* Bans specific types from being used.
60+
*
61+
* @see [ban-types](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/ban-types.md)
62+
*/
63+
'@typescript-eslint/ban-types': BanTypesRuleConfig;
64+
}

src/rules/typescript-eslint/index.d.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { AdjacentOverloadSignaturesRule } from './adjacent-overload-signatu
22
import type { ArrayTypeRule } from './array-type';
33
import type { AwaitThenableRule } from './await-thenable';
44
import type { BanTsCommentRule } from './ban-ts-comment';
5+
import type { BanTypesRule } from './ban-types';
56
import type { ExplicitFunctionReturnTypeRule } from './explicit-function-return-type';
67
import type { InterfaceNamePrefixRule } from './interface-name-prefix';
78
import type { MemberOrderingRule } from './member-ordering';
@@ -23,6 +24,7 @@ export type TypeScriptEslintRules = AdjacentOverloadSignaturesRule &
2324
ArrayTypeRule &
2425
AwaitThenableRule &
2526
BanTsCommentRule &
27+
BanTypesRule &
2628
ExplicitFunctionReturnTypeRule &
2729
InterfaceNamePrefixRule &
2830
MemberOrderingRule &

0 commit comments

Comments
 (0)