10000 docs: replace `var` with `let` and `const` in rule examples by Tanujkanti4441 · Pull Request #19365 · eslint/eslint · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
53 changes: 32 additions & 21 deletions docs/src/rules/arrow-body-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ Examples of **incorrect** code for this rule with the `"always"` option:
```js
/*eslint arrow-body-style: ["error", "always"]*/

let foo = () => 0;
const foo = () => 0;
```

:::
Expand All @@ -44,10 +44,11 @@ Examples of **correct** code for this rule with the `"always"` option:
```js
/*eslint arrow-body-style: ["error", "always"]*/

let foo = () => {
const foo = () => {
return 0;
};
let bar = (retv, name) => {

const bar = (retv, name) => {
retv[name] = true;
return retv;
};
Expand All @@ -64,10 +65,11 @@ Examples of **incorrect** code for this rule with the default `"as-needed"` opti
```js
/*eslint arrow-body-style: ["error", "as-needed"]*/

let foo = () => {
const foo = () => {
return 0;
};
let bar = () => {

const bar = () => {
return {
bar: {
foo: 1,
Expand All @@ -86,24 +88,29 @@ Examples of **correct** code for this rule with the default `"as-needed"` option
```js
/*eslint arrow-body-style: ["error", "as-needed"]*/

let foo1 = () => 0;
let foo2 = (retv, name) => {
const foo1 = () => 0;

const foo2 = (retv, name) => {
retv[name] = true;
return retv;
};
let foo3 = () => ({

const foo3 = () => ({
bar: {
foo: 1,
bar: 2,
}
});
let foo4 = () => { bar(); };
let foo5 = () => {};
let foo6 = () => { /* do nothing */ };
let foo7 = () => {

const foo4 = () => { bar(); };
const foo5 = () => {};
const foo6 = () => { /* do nothing */ };

const foo7 = () => {
// do nothing.
};
let foo8 = () => ({ bar: 0 });

const foo8 = () => ({ bar: 0 });
```

:::
Expand All @@ -119,8 +126,9 @@ Examples of **incorrect** code for this rule with the `{ "requireReturnForObject
```js
/*eslint arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/

let foo = () => ({});
let bar = () => ({ bar: 0 });
const foo = () => ({});

const bar = () => ({ bar: 0 });
```

:::
Expand All @@ -132,8 +140,9 @@ Examples of **correct** code for this rule with the `{ "requireReturnForObjectLi
```js
/*eslint arrow-body-style: ["error", "as-needed", { "requireReturnForObjectLiteral": true }]*/

let foo = () => {};
let bar = () => { return { bar: 0 }; };
const foo = () => {};

const bar = () => { return { bar: 0 }; };
```

:::
Expand All @@ -147,10 +156,11 @@ Examples of **incorrect** code for this rule with the `"never"` option:
```js
/*eslint arrow-body-style: ["error", "never"]*/

let foo = () => {
const foo = () => {
return 0;
};
let bar = (retv, name) => {

const bar = (retv, name) => {
retv[name] = true;
return retv;
};
Expand All @@ -165,8 +175,9 @@ Examples of **correct** code for this rule with the `"never"` option:
```js
/*eslint arrow-body-style: ["error", "never"]*/

let foo = () => 0;
let bar = () => ({ foo: 0 });
const foo = () => 0;

const bar = () => ({ foo: 0 });
```

:::
6 changes: 3 additions & 3 deletions docs/src/rules/no-unmodified-loop-condition.md
10BC0
Original file line number Diff line numberDiff line change
Expand Up @@ -37,14 +37,14 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-unmodified-loop-condition: "error"*/

var node = something;
let node = something;

while (node) {
doSomething(node);
}
node = other;

for (var j = 0; j < 5;) {
for (let j = 0; j < 5;) {
doSomething(j);
}

Expand All @@ -67,7 +67,7 @@ while (node) {
node = node.parent;
}

for (var j = 0; j < items.length; ++j) {
for (let j = 0; j < items.length; ++j) {
doSomething(items[j]);
}

Expand Down
8 changes: 4 additions & 4 deletions docs/src/rules/no-unsafe-optional-chaining.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ rule_type: problem
The optional chaining (`?.`) expression can short-circuit with a return value of `undefined`. Therefore, treating an evaluated optional chaining expression as a function, object, number, etc., can cause TypeError or unexpected results. For example:

```js
var obj = undefined;
const obj = undefined;

1 in obj?.foo; // TypeError
with (obj?.foo); // TypeError
Expand All @@ -20,7 +20,7 @@ const { bar } = obj?.foo; // TypeError
Also, parentheses limit the scope of short-circuiting in chains. For example:

```js
var obj = undefined;
const obj = undefined;

(obj?.foo)(); // TypeError
(obj?.foo).bar; // TypeError
Expand Down Expand Up @@ -77,7 +77,7 @@ with (obj?.foo);

class A extends obj?.foo {}

var a = class A extends obj?.foo {};
const a = class A extends obj?.foo {};

async function foo () {
const { bar } = await obj?.foo;
Expand Down Expand Up @@ -111,7 +111,7 @@ foo?.()?.bar;

new (obj?.foo ?? bar)();

var baz = {...obj?.foo};
const baz = {...obj?.foo};

const { bar } = obj?.foo || baz;

Expand Down
4 changes: 2 additions & 2 deletions docs/src/rules/no-useless-backreference.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ In JavaScript regular expressions, it's syntactically valid to define a backrefe
Backreferences that always successfully match zero-length and cannot match anything else are useless. They are basically ignored and can be removed without changing the behavior of the regular expression.

```js
var regex = /^(?:(a)|\1b)$/;
const regex = /^(?:(a)|\1b)$/;

regex.test("a"); // true
regex.test("b"); // true!
regex.test("ab"); // false

var equivalentRegex = /^(?:(a)|b)$/;
const equivalentRegex = /^(?:(a)|b)$/;

equivalentRegex.test("a"); // true
equivalentRegex.test("b"); // true
Expand Down
30 changes: 15 additions & 15 deletions docs/src/rules/use-isnan.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,17 +219,17 @@ Examples of **incorrect** code for this rule with `"enforceForIndexOf"` option s
```js
/*eslint use-isnan: ["error", {"enforceForIndexOf": true}]*/

var hasNaN = myArray.indexOf(NaN) >= 0;
const hasNaN = myArray.indexOf(NaN) >= 0;

var firstIndex = myArray.indexOf(NaN);
const firstIndex = myArray.indexOf(NaN);

var lastIndex = myArray.lastIndexOf(NaN);
const lastIndex = myArray.lastIndexOf(NaN);

var indexWithSequenceExpression = myArray.indexOf((doStuff(), NaN));
const indexWithSequenceExpression = myArray.indexOf((doStuff(), NaN));

var firstIndexFromSecondElement = myArray.indexOf(NaN, 1);
const firstIndexFromSecondElement = myArray.indexOf(NaN, 1);

var lastIndexFromSecondElement = myArray.lastIndexOf(NaN, 1);
const lastIndexFromSecondElement = myArray.lastIndexOf(NaN, 1);
```

:::
Expand All @@ -246,7 +246,7 @@ function myIsNaN(val) {
}

function indexOfNaN(arr) {
for (var i = 0; i < arr.length; i++) {
for (let i = 0; i < arr.length; i++) {
if (myIsNaN(arr[i])) {
return i;
}
Expand All @@ -255,30 +255,30 @@ function indexOfNaN(arr) {
}

function lastIndexOfNaN(arr) {
for (var i = arr.length - 1; i >= 0; i--) {
for (let i = arr.length - 1; i >= 0; i--) {
if (myIsNaN(arr[i])) {
return i;
}
}
return -1;
}

var hasNaN = myArray.some(myIsNaN);
const hasNaN = myArray.some(myIsNaN);

var hasNaN = indexOfNaN(myArray) >= 0;
const hasNaN1 = indexOfNaN(myArray) >= 0;

var firstIndex = indexOfNaN(myArray);
const firstIndex = indexOfNaN(myArray);

var lastIndex = lastIndexOfNaN(myArray);
const lastIndex = lastIndexOfNaN(myArray);

// ES2015
var hasNaN = myArray.some(Number.isNaN);
const hasNaN2 = myArray.some(Number.isNaN);

// ES2015
var firstIndex = myArray.findIndex(Number.isNaN);
const firstIndex1 = myArray.findIndex(Number.isNaN);

// ES2016
var hasNaN = myArray.includes(NaN);
const hasNaN3 = myArray.includes(NaN);
```

:::
Expand Down
Loading
0