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
* Accessing an object property whose key is an integer will fall under the category `array` destructuring.
186
186
* Accessing an array element through a computed index will fall under the category `object` destructuring.
187
187
188
-
The `--fix` option on the command line fixes only problems reported in variable declarations, and among them only those that fall under the category `object` destructuring. Furthermore, the name of the declared variable has to be the same as the name used for non-computed member access in the initializer. For example, `var foo = object.foo` can be automatically fixed by this rule. Problems that involve computed member access (e.g., `var foo = object[foo]`) or renamed properties (e.g., `var foo = object.bar`) are not automatically fixed.
188
+
The `--fix` option on the command line fixes only problems reported in variable declarations, and among them only those that fall under the category `object` destructuring. Furthermore, the name of the declared variable has to be the same as the name used for non-computed member access in the initializer. For example, `const foo = object.foo` can be automatically fixed by this rule. Problems that involve computed member access (e.g., `const foo = object[foo]`) or renamed properties (e.g., `const foo = object.bar`) are not automatically fixed.
189
189
190
190
## When Not To Use It
191
191
@@ -194,15 +194,15 @@ If you want to be able to access array indices or object properties directly, yo
194
194
Additionally, if you intend to access large array indices directly, like:
195
195
196
196
```javascript
197
-
var foo = array[100];
197
+
constfoo= array[100];
198
198
```
199
199
200
200
Then the `array` part of this rule is not recommended, as destructuring does not match this use case very well.
Copy file name to clipboardExpand all lines: docs/src/rules/radix.md
+16-16Lines changed: 16 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,13 +12,13 @@ When using the `parseInt()` function it is common to omit the second argument, t
12
12
This confusion led to the suggestion that you always use the radix parameter to `parseInt()` to eliminate unintended consequences. So instead of doing this:
13
13
14
14
```js
15
-
var num =parseInt("071"); // 57
15
+
constnum=parseInt("071"); // 57
16
16
```
17
17
18
18
Do this:
19
19
20
20
```js
21
-
var num =parseInt("071", 10); // 71
21
+
constnum=parseInt("071", 10); // 71
22
22
```
23
23
24
24
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.
@@ -45,15 +45,15 @@ Examples of **incorrect** code for the default `"always"` option:
45
45
```js
46
46
/*eslint radix: "error"*/
47
47
48
-
var num =parseInt("071");
48
+
constnum=parseInt("071");
49
49
50
-
var num=parseInt(someValue);
50
+
constnum1=parseInt(someValue);
51
51
52
-
var num=parseInt("071", "abc");
52
+
constnum2=parseInt("071", "abc");
53
53
54
-
var num=parseInt("071", 37);
54
+
constnum3=parseInt("071", 37);
55
55
56
-
var num=parseInt();
56
+
constnum4=parseInt();
57
57
```
58
58
59
59
:::
@@ -65,11 +65,11 @@ Examples of **correct** code for the default `"always"` option:
65
65
```js
66
66
/*eslint radix: "error"*/
67
67
68
-
var num =parseInt("071", 10);
68
+
constnum=parseInt("071", 10);
69
69
70
-
var num=parseInt("071", 8);
70
+
constnum1=parseInt("071", 8);
71
71
72
-
var num=parseFloat(someValue);
72
+
constnum2=parseFloat(someValue);
73
73
```
74
74
75
75
:::
@@ -83,11 +83,11 @@ Examples of **incorrect** code for the `"as-needed"` option:
83
83
```js
84
84
/*eslint radix: ["error", "as-needed"]*/
85
85
86
-
var num =parseInt("071", 10);
86
+
constnum=parseInt("071", 10);
87
87
88
-
var num=parseInt("071", "abc");
88
+
constnum1=parseInt("071", "abc");
89
89
90
-
var num=parseInt();
90
+
constnum2=parseInt();
91
91
```
92
92
93
93
:::
@@ -99,11 +99,11 @@ Examples of **correct** code for the `"as-needed"` option:
0 commit comments