Skip to content

docs: replace var with const and let in rules #19389

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions docs/src/rules/prefer-destructuring.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ Examples of **incorrect** code for this rule:
/* eslint prefer-destructuring: "error" */

// With `array` enabled
var foo = array[0];
const foo = array[0];
bar.baz = array[0];

// With `object` enabled
var foo = object.foo;
var foo = object['foo'];
const obj1 = object.foo;
const obj2 = object['foo'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const obj1 = object.foo;
const obj2 = object['foo'];
const qux = object.qux;
const quux = object['quux'];

Variable and property should have the same name for this to be incorrect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done!

```

:::
Expand All @@ -65,15 +65,15 @@ Examples of **correct** code for this rule:
/* eslint prefer-destructuring: "error" */

// With `array` enabled
var [ foo ] = array;
var foo = array[someIndex];
const [ foo ] = array;
const arr = array[someIndex];
[bar.baz] = array;


// With `object` enabled
var { foo } = object;
const { baz } = object;

var foo = object.bar;
const obj = object.bar;

let bar;
({ bar } = object);
Expand Down Expand Up @@ -108,7 +108,7 @@ Examples of **correct** code when object destructuring in `VariableDeclarator` i

```javascript
/* eslint prefer-destructuring: ["error", {VariableDeclarator: {object: true}}] */
var {bar: foo} = object;
const {bar: foo} = object;
```

:::
Expand Down Expand Up @@ -148,7 +148,7 @@ Examples of **incorrect** code when `enforceForRenamedProperties` is enabled:

```javascript
/* eslint "prefer-destructuring": ["error", { "object": true }, { "enforceForRenamedProperties": true }] */
var foo = object.bar;
const foo = object.bar;
```

:::
Expand All @@ -159,7 +159,7 @@ Examples of **correct** code when `enforceForRenamedProperties` is enabled:

```javascript
/* eslint "prefer-destructuring": ["error", { "object": true }, { "enforceForRenamedProperties": true }] */
var { bar: foo } = object;
const { bar: foo } = object;
```

:::
Expand Down Expand Up @@ -194,15 +194,15 @@ If you want to be able to access array indices or object properties directly, yo
Additionally, if you intend to access large array indices directly, like:

```javascript
var foo = array[100];
const foo = array[100];
```

Then the `array` part of this rule is not recommended, as destructuring does not match this use case very well.

Or for non-iterable 'array-like' objects:

```javascript
var $ = require('jquery');
var foo = $('body')[0];
var [bar] = $('body'); // fails with a TypeError
const $ = require('jquery');
const foo = $('body')[0];
const [bar] = $('body'); // fails with a TypeError
```
32 changes: 16 additions & 16 deletions docs/src/rules/radix.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ When using the `parseInt()` function it is common to omit the second argument, t
This confusion led to the suggestion that you always use the radix parameter to `parseInt()` to eliminate unintended consequences. So instead of doing this:

```js
var num = parseInt("071"); // 57
const num = parseInt("071"); // 57
```

Do this:

```js
var num = parseInt("071", 10); // 71
const num = parseInt("071", 10); // 71
```

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.
Expand All @@ -45,15 +45,15 @@ Examples of **incorrect** code for the default `"always"` option:
```js
/*eslint radix: "error"*/

var num = parseInt("071");
const num = parseInt("071");

var num = parseInt(someValue);
const num1 = parseInt(someValue);

var num = parseInt("071", "abc");
const num2 = parseInt("071", "abc");

var num = parseInt("071", 37);
const num3 = parseInt("071", 37);

var num = parseInt();
const num4 = parseInt();
```

:::
Expand All @@ -65,11 +65,11 @@ Examples of **correct** code for the default `"always"` option:
```js
/*eslint radix: "error"*/

var num = parseInt("071", 10);
const num = parseInt("071", 10);

var num = parseInt("071", 8);
const num1 = parseInt("071", 8);

var num = parseFloat(someValue);
const num2 = parseFloat(someValue);
```

:::
Expand All @@ -83,11 +83,11 @@ Examples of **incorrect** code for the `"as-needed"` option:
```js
/*eslint radix: ["error", "as-needed"]*/

var num = parseInt("071", 10);
const num = parseInt("071", 10);

var num = parseInt("071", "abc");
const num1 = parseInt("071", "abc");

var num = parseInt();
const num2 = parseInt();
```

:::
Expand All @@ -99,11 +99,11 @@ Examples of **correct** code for the `"as-needed"` option:
```js
/*eslint radix: ["error", "as-needed"]*/

var num = parseInt("071");
const num = parseInt("071");

var num = parseInt("071", 8);
const num1 = parseInt("071", 8);

var num = parseFloat(someValue);
const num2 = parseFloat(someValue);
```

:::
Expand Down
Loading
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy