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

Commit 1d0f8cb

Browse files
committed
Add rule @typescript-eslint/restrict-template-expressions
1 parent af89327 commit 1d0f8cb

File tree

2 files changed

+68
-1
lines changed

2 files changed

+68
-1
lines changed

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import type { NoUnusedVarsRule } from './no-unused-vars';
1010
import type { PreferNullishCoalescingRule } from './prefer-nullish-coalescing';
1111
import type { PreferOptionalChainRule } from './prefer-optional-chain';
1212
import type { PreferReadonlyRule } from './prefer-readonly';
13+
import type { RestrictTemplateExpressionsRule } from './restrict-template-expressions';
1314

1415
/**
1516
* All @typescript-eslint rules.
@@ -25,4 +26,5 @@ export type TypeScriptEslintRules = BanTsCommentRule &
2526
NoUnusedVarsRule &
2627
PreferNullishCoalescingRule &
2728
PreferOptionalChainRule &
28-
PreferReadonlyRule;
29+
PreferReadonlyRule &
30+
RestrictTemplateExpressionsRule;
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
import type { RuleConfig } from '../rule-config';
2+
3+
/**
4+
* Option.
5+
*/
6+
export type RestrictTemplateExpressionsOption = {
7+
/**
8+
* If `true`, also allow number type in template expressions.
9+
*
10+
* @default true
11+
*
12+
* @see [allowNumber](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-template-expressions.md#allownumber)
13+
*/
14+
allowNumber?: boolean;
15+
/**
16+
* If `true`, also allow boolean type in template expressions.
17+
*
18+
* @default false
19+
*
20+
* @see [allowBoolean](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-template-expressions.md#allowboolean)
21+
*/
22+
allowBoolean?: boolean;
23+
/**
24+
* If `true`, also allow any in template expressions.
25+
*
26+
* @default false
27+
*
28+
* @see [allowAny](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-template-expressions.md#allowany)
29+
*/
30+
allowAny?: boolean;
31+
/**
32+
* If `true`, also allow null and undefined in template expressions.
33+
*
34+
* @default false
35+
*
36+
* @see [allowNullish](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-template-expressions.md#allownullish)
37+
*/
38+
allowNullish?: boolean;
39+
};
40+
41+
/**
42+
* Options.
43+
*/
44+
export type RestrictTemplateExpressionsOptions = [RestrictTemplateExpressionsOption?];
45+
46+
/**
47+
* Enforce template literal expressions to be of string type.
48+
*
49+
* @see [restrict-template-expressions](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-template-expressions.md)
50+
*/
51+
export type RestrictTemplateExpressionsRuleConfig = RuleConfig<RestrictTemplateExpressionsOptions>;
52+
53+
/**
54+
* Enforce template literal expressions to be of string type.
55+
*
56+
* @see [restrict-template-expressions](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-template-expressions.md)
57+
*/
58+
export interface RestrictTemplateExpressionsRule {
59+
/**
60+
* Enforce template literal expressions to be of string type.
61+
*
62+
* @see [restrict-template-expressions](https://github.com/typescript-eslint/typescript-eslint/blob/master/packages/eslint-plugin/docs/rules/restrict-template-expressions.md)
63+
*/
64+
'@typescript-eslint/restrict-template-expressions': RestrictTemplateExpressionsRuleConfig;
65+
}

0 commit comments

Comments
 (0)