You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"description": "The parseInt() function parses a string argument and returns an integer of the specified radix (the base in mathematical numeral systems)."
ECMAScript 5 changed the behavior of `parseInt()` so that it no longer autodetects octal literals and instead treats them as decimal literals. However, the differences between hexadecimal and decimal interpretation of the first parameter causes many developers to continue using the radix parameter to ensure the string is interpreted in the intended way.
25
26
26
-
On the other hand, if the code is targeting only ES5-compliant environments passing the radix `10` may be redundant. In such a case you might want to disallow using such a radix.
27
-
28
27
## Rule Details
29
28
30
-
This rule is aimed at preventing the unintended conversion of a string to a number of a different base than intended or at preventing the redundant `10` radix if targeting modern environments only.
31
-
32
-
## Options
33
-
34
-
There are two options for this rule:
29
+
This rule is aimed at preventing the unintended conversion of a string to a number of a different base than intended.
35
30
36
-
*`"always"` enforces providing a radix (default)
37
-
*`"as-needed"` disallows providing the `10` radix
38
-
39
-
### always
40
-
41
-
Examples of **incorrect** code for the default `"always"` option:
31
+
Examples of **incorrect** code for this rule:
42
32
43
33
::: incorrect
44
34
@@ -58,7 +48,7 @@ const num4 = parseInt();
58
48
59
49
:::
60
50
61
-
Examples of **correct** code for the default `"always"` option:
Examples of **incorrect** code for the `"as-needed"` option:
80
-
81
-
::: incorrect
82
-
83
-
```js
84
-
/*eslint radix: ["error", "as-needed"]*/
85
-
86
-
constnum=parseInt("071", 10);
87
-
88
-
constnum1=parseInt("071", "abc");
89
-
90
-
constnum2=parseInt();
91
-
```
92
-
93
-
:::
94
-
95
-
Examples of **correct** code for the `"as-needed"` option:
96
-
97
-
::: correct
98
-
99
-
```js
100
-
/*eslint radix: ["error", "as-needed"]*/
101
-
102
-
constnum=parseInt("071");
103
-
104
-
constnum1=parseInt("071", 8);
105
-
106
-
constnum2=parseFloat(someValue);
107
-
```
67
+
## Options
108
68
109
-
:::
69
+
**Deprecated:** String options `"always"` and `"as-needed"` are deprecated. Setting either of these options doesn't change the behavior of this rule, which now always enforces providing a radix, as it was the case when the `"always"` option was specified. Since the default radix depends on the first argument of `parseInt()`, this rule assumes that the second argument (the radix) is always needed.
110
70
111
71
## When Not To Use It
112
72
113
-
If you don't want to enforce either presence or omission of the `10`radix value you can turn this rule off.
73
+
If you want to use the default behavior of the `parseInt()` function when the radix argument is not specified, you can turn this rule off.
## <aname="radix"></a> Deprecated options of the `radix` rule
67
+
68
+
As of ESLint v10.0.0, string options `"always"` and `"as-needed"` of the [`radix`](../rules/radix) rule are deprecated. Setting either of these options doesn't change the behavior of this rule, which now always enforces providing a radix, as it was the case when the `"always"` option (default) was specified. Since the default radix depends on the first argument of `parseInt()`, this rule assumes that the second argument (the radix) is always needed.
69
+
70
+
The default behavior of this rule has not been changed.
71
+
72
+
**To address:**
73
+
74
+
- If you are using this rule without any options specified, there is no action required.
75
+
- If you are using this rule with the `"always"` option explicitly specified, remove the option. The behavior of this rule will remain the same.
76
+
- If you are using this rule with the `"as-needed"` option, remove the option and update your code to always provide the second argument to the `parseInt()` function. Alternatively, you can disable this rule.
## <aname="no-shadow-restricted-names"></a> `no-shadow-restricted-names` now reports `globalThis` by default
66
81
67
82
In ESLint v10, the [`no-shadow-restricted-names`](../rules/no-shadow-restricted-names) rule now treats `globalThis` as a restricted name by default. Consequently, the `reportGlobalThis` option now defaults to `true` (previously `false`). As a result, declarations such as `const globalThis = "foo";` or `function globalThis() {}` will now be reported by default.
0 commit comments