Skip to content

Commit

Permalink
docs: replace var with const in rule examples (#19325)
Browse files Browse the repository at this point in the history
  • Loading branch information
Tanujkanti4441 authored Jan 9, 2025
1 parent 8e1a898 commit d9c23c5
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions docs/src/rules/no-prototype-builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-prototype-builtins: "error"*/

var hasBarProperty = foo.hasOwnProperty("bar");
const hasBarProperty = foo.hasOwnProperty("bar");

var isPrototypeOfBar = foo.isPrototypeOf(bar);
const isPrototypeOfBar = foo.isPrototypeOf(bar);

var barIsEnumerable = foo.propertyIsEnumerable("bar");
const barIsEnumerable = foo.propertyIsEnumerable("bar");
```

:::
Expand All @@ -38,11 +38,11 @@ Examples of **correct** code for this rule:
```js
/*eslint no-prototype-builtins: "error"*/

var hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar");
const hasBarProperty = Object.prototype.hasOwnProperty.call(foo, "bar");

var isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar);
const isPrototypeOfBar = Object.prototype.isPrototypeOf.call(foo, bar);

var barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar");
const barIsEnumerable = {}.propertyIsEnumerable.call(foo, "bar");
```

:::
Expand Down
4 changes: 2 additions & 2 deletions docs/src/rules/no-setter-return.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-setter-return: "error"*/

var foo = {
const foo = {
set a(value) {
this.val = value;
return value;
Expand Down Expand Up @@ -76,7 +76,7 @@ Examples of **correct** code for this rule:
```js
/*eslint no-setter-return: "error"*/

var foo = {
const foo = {
set a(value) {
this.val = value;
}
Expand Down
14 changes: 7 additions & 7 deletions docs/src/rules/no-sparse-arrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ further_reading:
Sparse arrays contain empty slots, most frequently due to multiple commas being used in an array literal, such as:

```js
var items = [,,];
const items = [,,];
```

While the `items` array in this example has a `length` of 2, there are actually no values in `items[0]` or `items[1]`. The fact that the array literal is valid with only commas inside, coupled with the `length` being set and actual item values not being set, make sparse arrays confusing for many developers. Consider the following:

```js
var colors = [ "red",, "blue" ];
const colors = [ "red",, "blue" ];
```

In this example, the `colors` array has a `length` of 3. But did the developer intend for there to be an empty spot in the middle of the array? Or is it a typo?
Expand All @@ -34,8 +34,8 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-sparse-arrays: "error"*/

var items = [,];
var colors = [ "red",, "blue" ];
const items = [,];
const colors = [ "red",, "blue" ];
```

:::
Expand All @@ -47,11 +47,11 @@ Examples of **correct** code for this rule:
```js
/*eslint no-sparse-arrays: "error"*/

var items = [];
var items = new Array(23);
const items = [];
const arr = new Array(23);

// trailing comma (after the last element) is not a problem
var colors = [ "red", "blue", ];
const colors = [ "red", "blue", ];
```

:::
Expand Down
8 changes: 4 additions & 4 deletions docs/src/rules/no-undef.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-undef: "error"*/

var foo = someFunction();
var bar = a + 1;
const foo = someFunction();
const bar = a + 1;
```

:::
Expand All @@ -36,8 +36,8 @@ Examples of **correct** code for this rule with `global` declaration:
/*global someFunction, a*/
/*eslint no-undef: "error"*/

var foo = someFunction();
var bar = a + 1;
const foo = someFunction();
const bar = a + 1;
```

:::
Expand Down
22 changes: 11 additions & 11 deletions docs/src/rules/no-unexpected-multiline.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-unexpected-multiline: "error"*/

var foo = bar
const foo = bar
(1 || 2).baz();

var hello = 'world'
const hello = 'world'
[1, 2, 3].forEach(addNumber);

let x = function() {}
const x = function() {}
`hello`

let y = function() {}
const y = function() {}
y
`hello`

let z = foo
const z = foo
/regex/g.test(bar)
```

Expand All @@ -57,22 +57,22 @@ Examples of **correct** code for this rule:
```js
/*eslint no-unexpected-multiline: "error"*/

var foo = bar;
const foo = bar;
(1 || 2).baz();

var foo = bar
const baz = bar
;(1 || 2).baz()

var hello = 'world';
const hello = 'world';
[1, 2, 3].forEach(addNumber);

var hello = 'world'
const hi = 'world'
void [1, 2, 3].forEach(addNumber);

let x = function() {};
const x = function() {};
`hello`

let tag = function() {}
const tag = function() {}
tag `hello`
```

Expand Down

0 comments on commit d9c23c5

Please sign in to comment.