@typescript-eslint/eslint-plugin 8.33.1-alpha.5 → 8.33.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +9 -10
- package/docs/rules/README.md +0 -57
- package/docs/rules/TEMPLATE.md +0 -36
- package/docs/rules/adjacent-overload-signatures.mdx +0 -105
- package/docs/rules/array-type.mdx +0 -126
- package/docs/rules/await-thenable.mdx +0 -184
- package/docs/rules/ban-ts-comment.mdx +0 -165
- package/docs/rules/ban-tslint-comment.mdx +0 -45
- package/docs/rules/ban-types.md +0 -26
- package/docs/rules/block-spacing.md +0 -15
- package/docs/rules/brace-style.md +0 -15
- package/docs/rules/camelcase.md +0 -15
- package/docs/rules/class-literal-property-style.mdx +0 -112
- package/docs/rules/class-methods-use-this.mdx +0 -135
- package/docs/rules/comma-dangle.md +0 -15
- package/docs/rules/comma-spacing.md +0 -15
- package/docs/rules/consistent-generic-constructors.mdx +0 -87
- package/docs/rules/consistent-indexed-object-style.mdx +0 -105
- package/docs/rules/consistent-return.mdx +0 -51
- package/docs/rules/consistent-type-assertions.mdx +0 -196
- package/docs/rules/consistent-type-definitions.mdx +0 -133
- package/docs/rules/consistent-type-exports.mdx +0 -97
- package/docs/rules/consistent-type-imports.mdx +0 -139
- package/docs/rules/default-param-last.mdx +0 -59
- package/docs/rules/dot-notation.mdx +0 -94
- package/docs/rules/explicit-function-return-type.mdx +0 -359
- package/docs/rules/explicit-member-accessibility.mdx +0 -353
- package/docs/rules/explicit-module-boundary-types.mdx +0 -287
- package/docs/rules/func-call-spacing.md +0 -15
- package/docs/rules/indent.md +0 -15
- package/docs/rules/init-declarations.mdx +0 -12
- package/docs/rules/key-spacing.md +0 -15
- package/docs/rules/keyword-spacing.md +0 -15
- package/docs/rules/lines-around-comment.md +0 -15
- package/docs/rules/lines-between-class-members.md +0 -15
- package/docs/rules/max-params.mdx +0 -54
- package/docs/rules/member-delimiter-style.md +0 -15
- package/docs/rules/member-ordering.mdx +0 -1483
- package/docs/rules/method-signature-style.mdx +0 -124
- package/docs/rules/naming-convention.mdx +0 -755
- package/docs/rules/no-array-constructor.mdx +0 -34
- package/docs/rules/no-array-delete.mdx +0 -44
- package/docs/rules/no-base-to-string.mdx +0 -115
- package/docs/rules/no-confusing-non-null-assertion.mdx +0 -75
- package/docs/rules/no-confusing-void-expression.mdx +0 -148
- package/docs/rules/no-deprecated.mdx +0 -119
- package/docs/rules/no-dupe-class-members.mdx +0 -16
- package/docs/rules/no-duplicate-enum-values.mdx +0 -66
- package/docs/rules/no-duplicate-imports.mdx +0 -17
- package/docs/rules/no-duplicate-type-constituents.mdx +0 -89
- package/docs/rules/no-dynamic-delete.mdx +0 -64
- package/docs/rules/no-empty-function.mdx +0 -94
- package/docs/rules/no-empty-interface.mdx +0 -75
- package/docs/rules/no-empty-object-type.mdx +0 -150
- package/docs/rules/no-explicit-any.mdx +0 -177
- package/docs/rules/no-extra-non-null-assertion.mdx +0 -60
- package/docs/rules/no-extra-parens.md +0 -15
- package/docs/rules/no-extra-semi.md +0 -15
- package/docs/rules/no-extraneous-class.mdx +0 -329
- package/docs/rules/no-floating-promises.mdx +0 -282
- package/docs/rules/no-for-in-array.mdx +0 -67
- package/docs/rules/no-implied-eval.mdx +0 -106
- package/docs/rules/no-import-type-side-effects.mdx +0 -80
- package/docs/rules/no-inferrable-types.mdx +0 -113
- package/docs/rules/no-invalid-this.mdx +0 -16
- package/docs/rules/no-invalid-void-type.mdx +0 -119
- package/docs/rules/no-loop-func.mdx +0 -12
- package/docs/rules/no-loss-of-precision.mdx +0 -17
- package/docs/rules/no-magic-numbers.mdx +0 -131
- package/docs/rules/no-meaningless-void-operator.mdx +0 -61
- package/docs/rules/no-misused-new.mdx +0 -53
- package/docs/rules/no-misused-promises.mdx +0 -314
- package/docs/rules/no-misused-spread.mdx +0 -132
- package/docs/rules/no-mixed-enums.mdx +0 -96
- package/docs/rules/no-namespace.mdx +0 -157
- package/docs/rules/no-non-null-asserted-nullish-coalescing.mdx +0 -60
- package/docs/rules/no-non-null-asserted-optional-chain.mdx +0 -46
- package/docs/rules/no-non-null-assertion.mdx +0 -48
- package/docs/rules/no-parameter-properties.mdx +0 -16
- package/docs/rules/no-redeclare.mdx +0 -79
- package/docs/rules/no-redundant-type-constituents.mdx +0 -102
- package/docs/rules/no-require-imports.mdx +0 -114
- package/docs/rules/no-restricted-imports.mdx +0 -84
- package/docs/rules/no-restricted-types.mdx +0 -70
- package/docs/rules/no-shadow.mdx +0 -143
- package/docs/rules/no-this-alias.mdx +0 -124
- package/docs/rules/no-type-alias.mdx +0 -626
- package/docs/rules/no-unnecessary-boolean-literal-compare.mdx +0 -165
- package/docs/rules/no-unnecessary-condition.mdx +0 -293
- package/docs/rules/no-unnecessary-parameter-property-assignment.mdx +0 -42
- package/docs/rules/no-unnecessary-qualifier.mdx +0 -57
- package/docs/rules/no-unnecessary-template-expression.mdx +0 -108
- package/docs/rules/no-unnecessary-type-arguments.mdx +0 -85
- package/docs/rules/no-unnecessary-type-assertion.mdx +0 -97
- package/docs/rules/no-unnecessary-type-constraint.mdx +0 -61
- package/docs/rules/no-unnecessary-type-conversion.mdx +0 -79
- package/docs/rules/no-unnecessary-type-parameters.mdx +0 -255
- package/docs/rules/no-unsafe-argument.mdx +0 -98
- package/docs/rules/no-unsafe-assignment.mdx +0 -101
- package/docs/rules/no-unsafe-call.mdx +0 -120
- package/docs/rules/no-unsafe-declaration-merging.mdx +0 -65
- package/docs/rules/no-unsafe-enum-comparison.mdx +0 -98
- package/docs/rules/no-unsafe-function-type.mdx +0 -65
- package/docs/rules/no-unsafe-member-access.mdx +0 -81
- package/docs/rules/no-unsafe-return.mdx +0 -126
- package/docs/rules/no-unsafe-type-assertion.mdx +0 -63
- package/docs/rules/no-unsafe-unary-minus.mdx +0 -60
- package/docs/rules/no-unused-expressions.mdx +0 -52
- package/docs/rules/no-unused-vars.mdx +0 -136
- package/docs/rules/no-use-before-define.mdx +0 -98
- package/docs/rules/no-useless-constructor.mdx +0 -21
- package/docs/rules/no-useless-empty-export.mdx +0 -53
- package/docs/rules/no-useless-template-literals.mdx +0 -9
- package/docs/rules/no-var-requires.mdx +0 -77
- package/docs/rules/no-wrapper-object-types.mdx +0 -75
- package/docs/rules/non-nullable-type-assertion-style.mdx +0 -47
- package/docs/rules/object-curly-spacing.md +0 -15
- package/docs/rules/only-throw-error.mdx +0 -150
- package/docs/rules/padding-line-between-statements.md +0 -15
- package/docs/rules/parameter-properties.mdx +0 -522
- package/docs/rules/prefer-as-const.mdx +0 -51
- package/docs/rules/prefer-destructuring.mdx +0 -101
- package/docs/rules/prefer-enum-initializers.mdx +0 -68
- package/docs/rules/prefer-find.mdx +0 -45
- package/docs/rules/prefer-for-of.mdx +0 -50
- package/docs/rules/prefer-function-type.mdx +0 -98
- package/docs/rules/prefer-includes.mdx +0 -81
- package/docs/rules/prefer-literal-enum-member.mdx +0 -111
- package/docs/rules/prefer-namespace-keyword.mdx +0 -51
- package/docs/rules/prefer-nullish-coalescing.mdx +0 -349
- package/docs/rules/prefer-optional-chain.mdx +0 -304
- package/docs/rules/prefer-promise-reject-errors.mdx +0 -78
- package/docs/rules/prefer-readonly-parameter-types.mdx +0 -408
- package/docs/rules/prefer-readonly.mdx +0 -111
- package/docs/rules/prefer-reduce-type-parameter.mdx +0 -66
- package/docs/rules/prefer-regexp-exec.mdx +0 -52
- package/docs/rules/prefer-return-this-type.mdx +0 -93
- package/docs/rules/prefer-string-starts-ends-with.mdx +0 -84
- package/docs/rules/prefer-ts-expect-error.mdx +0 -86
- package/docs/rules/promise-function-async.mdx +0 -143
- package/docs/rules/quotes.md +0 -15
- package/docs/rules/related-getter-setter-pairs.mdx +0 -61
- package/docs/rules/require-array-sort-compare.mdx +0 -89
- package/docs/rules/require-await.mdx +0 -53
- package/docs/rules/restrict-plus-operands.mdx +0 -245
- package/docs/rules/restrict-template-expressions.mdx +0 -167
- package/docs/rules/return-await.mdx +0 -339
- package/docs/rules/semi.md +0 -15
- package/docs/rules/sort-type-constituents.mdx +0 -209
- package/docs/rules/sort-type-union-intersection-members.mdx +0 -16
- package/docs/rules/space-before-blocks.md +0 -15
- package/docs/rules/space-before-function-paren.md +0 -15
- package/docs/rules/space-infix-ops.md +0 -15
- package/docs/rules/strict-boolean-expressions.mdx +0 -184
- package/docs/rules/switch-exhaustiveness-check.mdx +0 -280
- package/docs/rules/triple-slash-reference.mdx +0 -129
- package/docs/rules/type-annotation-spacing.md +0 -15
- package/docs/rules/typedef.mdx +0 -350
- package/docs/rules/unbound-method.mdx +0 -114
- package/docs/rules/unified-signatures.mdx +0 -132
- package/docs/rules/use-unknown-in-catch-callback-variable.mdx +0 -97
@@ -1,245 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Require both operands of addition to be the same type and be `bigint`, `number`, or `string`.'
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/restrict-plus-operands** for documentation.
|
11
|
-
|
12
|
-
TypeScript allows `+` adding together two values of any type(s).
|
13
|
-
However, adding values that are not the same type and/or are not the same primitive type is often a sign of programmer error.
|
14
|
-
|
15
|
-
This rule reports when a `+` operation combines two values of different types, or a type that is not `bigint`, `number`, or `string`.
|
16
|
-
|
17
|
-
## Examples
|
18
|
-
|
19
|
-
<Tabs>
|
20
|
-
<TabItem value="❌ Incorrect">
|
21
|
-
|
22
|
-
```ts
|
23
|
-
let foo = 1n + 1;
|
24
|
-
let fn = (a: string, b: never) => a + b;
|
25
|
-
```
|
26
|
-
|
27
|
-
</TabItem>
|
28
|
-
<TabItem value="✅ Correct">
|
29
|
-
|
30
|
-
```ts
|
31
|
-
let foo = 1n + 1n;
|
32
|
-
let fn = (a: string, b: string) => a + b;
|
33
|
-
```
|
34
|
-
|
35
|
-
</TabItem>
|
36
|
-
</Tabs>
|
37
|
-
|
38
|
-
## Options
|
39
|
-
|
40
|
-
:::caution
|
41
|
-
We generally recommend against using these options, as they limit which varieties of incorrect `+` usage can be checked.
|
42
|
-
This in turn severely limits the validation that the rule can do to ensure that resulting strings and numbers are correct.
|
43
|
-
|
44
|
-
Safer alternatives to using the `allow*` options include:
|
45
|
-
|
46
|
-
- Using variadic forms of logging APIs to avoid needing to `+` values.
|
47
|
-
```ts
|
48
|
-
// Remove this line
|
49
|
-
console.log('The result is ' + true);
|
50
|
-
// Add this line
|
51
|
-
console.log('The result is', true);
|
52
|
-
```
|
53
|
-
- Using `.toFixed()` to coerce numbers to well-formed string representations:
|
54
|
-
```ts
|
55
|
-
const number = 1.123456789;
|
56
|
-
const result = 'The number is ' + number.toFixed(2);
|
57
|
-
// result === 'The number is 1.12'
|
58
|
-
```
|
59
|
-
- Calling `.toString()` on other types to mark explicit and intentional string coercion:
|
60
|
-
```ts
|
61
|
-
const arg = '11';
|
62
|
-
const regex = /[0-9]/;
|
63
|
-
const result =
|
64
|
-
'The result of ' +
|
65
|
-
regex.toString() +
|
66
|
-
'.test("' +
|
67
|
-
arg +
|
68
|
-
'") is ' +
|
69
|
-
regex.test(arg).toString();
|
70
|
-
// result === 'The result of /[0-9]/.test("11") is true'
|
71
|
-
```
|
72
|
-
|
73
|
-
:::
|
74
|
-
|
75
|
-
### `allowAny`
|
76
|
-
|
77
|
-
{/* insert option description */}
|
78
|
-
|
79
|
-
Examples of code for this rule with `{ allowAny: true }`:
|
80
|
-
|
81
|
-
<Tabs>
|
82
|
-
<TabItem value="❌ Incorrect">
|
83
|
-
|
84
|
-
```ts option='{ "allowAny": true }'
|
85
|
-
let fn = (a: number, b: []) => a + b;
|
86
|
-
let fn = (a: string, b: []) => a + b;
|
87
|
-
```
|
88
|
-
|
89
|
-
</TabItem>
|
90
|
-
<TabItem value="✅ Correct">
|
91
|
-
|
92
|
-
```ts option='{ "allowAny": true }'
|
93
|
-
let fn = (a: number, b: any) => a + b;
|
94
|
-
let fn = (a: string, b: any) => a + b;
|
95
|
-
```
|
96
|
-
|
97
|
-
</TabItem>
|
98
|
-
</Tabs>
|
99
|
-
|
100
|
-
### `allowBoolean`
|
101
|
-
|
102
|
-
{/* insert option description */}
|
103
|
-
|
104
|
-
Examples of code for this rule with `{ allowBoolean: true }`:
|
105
|
-
|
106
|
-
<Tabs>
|
107
|
-
<TabItem value="❌ Incorrect">
|
108
|
-
|
109
|
-
```ts option='{ "allowBoolean": true }'
|
110
|
-
let fn = (a: number, b: unknown) => a + b;
|
111
|
-
let fn = (a: string, b: unknown) => a + b;
|
112
|
-
```
|
113
|
-
|
114
|
-
</TabItem>
|
115
|
-
<TabItem value="✅ Correct">
|
116
|
-
|
117
|
-
```ts option='{ "allowBoolean": true }'
|
118
|
-
let fn = (a: number, b: boolean) => a + b;
|
119
|
-
let fn = (a: string, b: boolean) => a + b;
|
120
|
-
```
|
121
|
-
|
122
|
-
</TabItem>
|
123
|
-
</Tabs>
|
124
|
-
|
125
|
-
### `allowNullish`
|
126
|
-
|
127
|
-
{/* insert option description */}
|
128
|
-
|
129
|
-
Examples of code for this rule with `{ allowNullish: true }`:
|
130
|
-
|
131
|
-
<Tabs>
|
132
|
-
<TabItem value="❌ Incorrect">
|
133
|
-
|
134
|
-
```ts option='{ "allowNullish": true }'
|
135
|
-
let fn = (a: number, b: unknown) => a + b;
|
136
|
-
let fn = (a: number, b: never) => a + b;
|
137
|
-
let fn = (a: string, b: unknown) => a + b;
|
138
|
-
let fn = (a: string, b: never) => a + b;
|
139
|
-
```
|
140
|
-
|
141
|
-
</TabItem>
|
142
|
-
<TabItem value="✅ Correct">
|
143
|
-
|
144
|
-
```ts option='{ "allowNullish": true }'
|
145
|
-
let fn = (a: number, b: undefined) => a + b;
|
146
|
-
let fn = (a: number, b: null) => a + b;
|
147
|
-
let fn = (a: string, b: undefined) => a + b;
|
148
|
-
let fn = (a: string, b: null) => a + b;
|
149
|
-
```
|
150
|
-
|
151
|
-
</TabItem>
|
152
|
-
</Tabs>
|
153
|
-
|
154
|
-
### `allowNumberAndString`
|
155
|
-
|
156
|
-
{/* insert option description */}
|
157
|
-
|
158
|
-
Examples of code for this rule with `{ allowNumberAndString: true }`:
|
159
|
-
|
160
|
-
<Tabs>
|
161
|
-
<TabItem value="❌ Incorrect">
|
162
|
-
|
163
|
-
```ts option='{ "allowNumberAndString": true }'
|
164
|
-
let fn = (a: number, b: unknown) => a + b;
|
165
|
-
let fn = (a: number, b: never) => a + b;
|
166
|
-
```
|
167
|
-
|
168
|
-
</TabItem>
|
169
|
-
<TabItem value="✅ Correct">
|
170
|
-
|
171
|
-
```ts option='{ "allowNumberAndString": true }'
|
172
|
-
let fn = (a: number, b: string) => a + b;
|
173
|
-
let fn = (a: number, b: number | string) => a + b;
|
174
|
-
let fn = (a: bigint, b: string) => a + b;
|
175
|
-
```
|
176
|
-
|
177
|
-
</TabItem>
|
178
|
-
</Tabs>
|
179
|
-
|
180
|
-
### `allowRegExp`
|
181
|
-
|
182
|
-
{/* insert option description */}
|
183
|
-
|
184
|
-
Examples of code for this rule with `{ allowRegExp: true }`:
|
185
|
-
|
186
|
-
<Tabs>
|
187
|
-
<TabItem value="❌ Incorrect">
|
188
|
-
|
189
|
-
```ts option='{ "allowRegExp": true }'
|
190
|
-
let fn = (a: number, b: RegExp) => a + b;
|
191
|
-
```
|
192
|
-
|
193
|
-
</TabItem>
|
194
|
-
<TabItem value="✅ Correct">
|
195
|
-
|
196
|
-
```ts option='{ "allowRegExp": true }'
|
197
|
-
let fn = (a: string, b: RegExp) => a + b;
|
198
|
-
```
|
199
|
-
|
200
|
-
</TabItem>
|
201
|
-
</Tabs>
|
202
|
-
|
203
|
-
### `skipCompoundAssignments`
|
204
|
-
|
205
|
-
{/* insert option description */}
|
206
|
-
|
207
|
-
Examples of code for this rule with `{ skipCompoundAssignments: false }`:
|
208
|
-
|
209
|
-
<Tabs>
|
210
|
-
<TabItem value="❌ Incorrect">
|
211
|
-
|
212
|
-
```ts option='{ "skipCompoundAssignments": false }'
|
213
|
-
let foo: bigint = 0n;
|
214
|
-
foo += 1;
|
215
|
-
|
216
|
-
let bar: number[] = [1];
|
217
|
-
bar += 1;
|
218
|
-
```
|
219
|
-
|
220
|
-
</TabItem>
|
221
|
-
<TabItem value="✅ Correct">
|
222
|
-
|
223
|
-
```ts option='{ "skipCompoundAssignments": false }'
|
224
|
-
let foo: bigint = 0n;
|
225
|
-
foo += 1n;
|
226
|
-
|
227
|
-
let bar: number = 1;
|
228
|
-
bar += 1;
|
229
|
-
```
|
230
|
-
|
231
|
-
</TabItem>
|
232
|
-
</Tabs>
|
233
|
-
|
234
|
-
## When Not To Use It
|
235
|
-
|
236
|
-
If you don't mind a risk of `"[object Object]"` or incorrect type coercions in your values, then you will not need this rule.
|
237
|
-
|
238
|
-
## Related To
|
239
|
-
|
240
|
-
- [`no-base-to-string`](./no-base-to-string.mdx)
|
241
|
-
- [`restrict-template-expressions`](./restrict-template-expressions.mdx)
|
242
|
-
|
243
|
-
## Further Reading
|
244
|
-
|
245
|
-
- [`Object.prototype.toString()` MDN documentation](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/toString)
|
@@ -1,167 +0,0 @@
|
|
1
|
-
---
|
2
|
-
description: 'Enforce template literal expressions to be of `string` type.'
|
3
|
-
---
|
4
|
-
|
5
|
-
import Tabs from '@theme/Tabs';
|
6
|
-
import TabItem from '@theme/TabItem';
|
7
|
-
|
8
|
-
> 🛑 This file is source code, not the primary documentation location! 🛑
|
9
|
-
>
|
10
|
-
> See **https://typescript-eslint.io/rules/restrict-template-expressions** for documentation.
|
11
|
-
|
12
|
-
JavaScript automatically [converts an object to a string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String#string_coercion) in a string context, such as when concatenating it with a string using `+` or embedding it in a template literal using `${}`.
|
13
|
-
The default `toString()` method of objects uses the format `"[object Object]"`, which is often not what was intended.
|
14
|
-
This rule reports on values used in a template literal string that aren't strings, optionally allowing other data types that provide useful stringification results.
|
15
|
-
|
16
|
-
:::note
|
17
|
-
|
18
|
-
The default settings of this rule intentionally do not allow objects with a custom `toString()` method to be used in template literals, because the stringification result may not be user-friendly.
|
19
|
-
|
20
|
-
For example, arrays have a custom [`toString()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString) method, which only calls `join()` internally, which joins the array elements with commas. This means that (1) array elements are not necessarily stringified to useful results (2) the commas don't have spaces after them, making the result not user-friendly. The best way to format arrays is to use [`Intl.ListFormat`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/ListFormat), which even supports adding the "and" conjunction where necessary.
|
21
|
-
You must explicitly call `object.toString()` if you want to use this object in a template literal, or turn on the `allowArray` option to specifically allow arrays.
|
22
|
-
The [`no-base-to-string`](./no-base-to-string.mdx) rule can be used to guard this case against producing `"[object Object]"` by accident.
|
23
|
-
|
24
|
-
:::
|
25
|
-
|
26
|
-
## Examples
|
27
|
-
|
28
|
-
<Tabs>
|
29
|
-
<TabItem value="❌ Incorrect">
|
30
|
-
|
31
|
-
```ts
|
32
|
-
const arg1 = [1, 2];
|
33
|
-
const msg1 = `arg1 = ${arg1}`;
|
34
|
-
|
35
|
-
const arg2 = { name: 'Foo' };
|
36
|
-
const msg2 = `arg2 = ${arg2 || null}`;
|
37
|
-
```
|
38
|
-
|
39
|
-
</TabItem>
|
40
|
-
<TabItem value="✅ Correct">
|
41
|
-
|
42
|
-
```ts
|
43
|
-
const arg = 'foo';
|
44
|
-
const msg1 = `arg = ${arg}`;
|
45
|
-
const msg2 = `arg = ${arg || 'default'}`;
|
46
|
-
|
47
|
-
const stringWithKindProp: string & { _kind?: 'MyString' } = 'foo';
|
48
|
-
const msg3 = `stringWithKindProp = ${stringWithKindProp}`;
|
49
|
-
```
|
50
|
-
|
51
|
-
</TabItem>
|
52
|
-
</Tabs>
|
53
|
-
|
54
|
-
## Options
|
55
|
-
|
56
|
-
### `allowNumber`
|
57
|
-
|
58
|
-
{/* insert option description */}
|
59
|
-
|
60
|
-
Examples of additional **correct** code for this rule with `{ allowNumber: true }`:
|
61
|
-
|
62
|
-
```ts option='{ "allowNumber": true }' showPlaygroundButton
|
63
|
-
const arg = 123;
|
64
|
-
const msg1 = `arg = ${arg}`;
|
65
|
-
const msg2 = `arg = ${arg || 'zero'}`;
|
66
|
-
```
|
67
|
-
|
68
|
-
This option controls both numbers and BigInts.
|
69
|
-
|
70
|
-
We recommend avoiding using this option if you use any floating point numbers.
|
71
|
-
Although `` `${1}` `` evaluates to `'1'`, `` `${0.1 + 0.2}` `` evaluates to `'0.30000000000000004'`.
|
72
|
-
Consider using [`.toFixed()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed) or [`.toPrecision()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toPrecision) instead.
|
73
|
-
|
74
|
-
### `allowBoolean`
|
75
|
-
|
76
|
-
{/* insert option description */}
|
77
|
-
|
78
|
-
Examples of additional **correct** code for this rule with `{ allowBoolean: true }`:
|
79
|
-
|
80
|
-
```ts option='{ "allowBoolean": true }' showPlaygroundButton
|
81
|
-
const arg = true;
|
82
|
-
const msg1 = `arg = ${arg}`;
|
83
|
-
const msg2 = `arg = ${arg || 'not truthy'}`;
|
84
|
-
```
|
85
|
-
|
86
|
-
### `allowAny`
|
87
|
-
|
88
|
-
{/* insert option description */}
|
89
|
-
|
90
|
-
Examples of additional **correct** code for this rule with `{ allowAny: true }`:
|
91
|
-
|
92
|
-
```ts option='{ "allowAny": true }' showPlaygroundButton
|
93
|
-
const user = JSON.parse('{ "name": "foo" }');
|
94
|
-
const msg1 = `arg = ${user.name}`;
|
95
|
-
const msg2 = `arg = ${user.name || 'the user with no name'}`;
|
96
|
-
```
|
97
|
-
|
98
|
-
### `allowNullish`
|
99
|
-
|
100
|
-
{/* insert option description */}
|
101
|
-
|
102
|
-
Examples of additional **correct** code for this rule with `{ allowNullish: true }`:
|
103
|
-
|
104
|
-
```ts option='{ "allowNullish": true }' showPlaygroundButton
|
105
|
-
const arg = condition ? 'ok' : null;
|
106
|
-
const msg1 = `arg = ${arg}`;
|
107
|
-
```
|
108
|
-
|
109
|
-
### `allowRegExp`
|
110
|
-
|
111
|
-
{/* insert option description */}
|
112
|
-
|
113
|
-
Examples of additional **correct** code for this rule with `{ allowRegExp: true }`:
|
114
|
-
|
115
|
-
```ts option='{ "allowRegExp": true }' showPlaygroundButton
|
116
|
-
const arg = new RegExp('foo');
|
117
|
-
const msg1 = `arg = ${arg}`;
|
118
|
-
```
|
119
|
-
|
120
|
-
```ts option='{ "allowRegExp": true }' showPlaygroundButton
|
121
|
-
const arg = /foo/;
|
122
|
-
const msg1 = `arg = ${arg}`;
|
123
|
-
```
|
124
|
-
|
125
|
-
### `allowNever`
|
126
|
-
|
127
|
-
{/* insert option description */}
|
128
|
-
|
129
|
-
Examples of additional **correct** code for this rule with `{ allowNever: true }`:
|
130
|
-
|
131
|
-
```ts option='{ "allowNever": true }' showPlaygroundButton
|
132
|
-
const arg = 'something';
|
133
|
-
const msg1 = typeof arg === 'string' ? arg : `arg = ${arg}`;
|
134
|
-
```
|
135
|
-
|
136
|
-
### `allowArray`
|
137
|
-
|
138
|
-
{/* insert option description */}
|
139
|
-
|
140
|
-
Examples of additional **correct** code for this rule with `{ allowArray: true }`:
|
141
|
-
|
142
|
-
```ts option='{ "allowArray": true }' showPlaygroundButton
|
143
|
-
const arg = ['foo', 'bar'];
|
144
|
-
const msg1 = `arg = ${arg}`;
|
145
|
-
```
|
146
|
-
|
147
|
-
### `allow`
|
148
|
-
|
149
|
-
{/* insert option description */}
|
150
|
-
|
151
|
-
This option takes the shared [`TypeOrValueSpecifier` format](/packages/type-utils/type-or-value-specifier).
|
152
|
-
|
153
|
-
Examples of additional **correct** code for this rule with the default option `{ allow: [{ from: 'lib', name: 'Error' }, { from: 'lib', name: 'URL' }, { from: 'lib', name: 'URLSearchParams' }] }`:
|
154
|
-
|
155
|
-
```ts showPlaygroundButton
|
156
|
-
const error = new Error();
|
157
|
-
const msg1 = `arg = ${error}`;
|
158
|
-
```
|
159
|
-
|
160
|
-
## When Not To Use It
|
161
|
-
|
162
|
-
If you're not worried about incorrectly stringifying non-string values in template literals, then you likely don't need this rule.
|
163
|
-
|
164
|
-
## Related To
|
165
|
-
|
166
|
-
- [`no-base-to-string`](./no-base-to-string.mdx)
|
167
|
-
- [`restrict-plus-operands`](./restrict-plus-operands.mdx)
|