Skip to content
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

docs: rewrite examples with var using let and const #19398

Merged
merged 1 commit into from
Feb 3, 2025
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
12 changes: 6 additions & 6 deletions docs/src/rules/init-declarations.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ rule_type: suggestion
In JavaScript, variables can be assigned during declaration, or at any point afterwards using an assignment statement. For example, in the following code, `foo` is initialized during declaration, while `bar` is initialized later.

```js
var foo = 1;
var bar;
let foo = 1;
let bar;

if (foo) {
bar = 1;
Expand All @@ -22,8 +22,8 @@ if (foo) {
This rule is aimed at enforcing or eliminating variable initializations during declaration. For example, in the following code, `foo` is initialized during declaration, while `bar` is not.

```js
var foo = 1;
var bar;
let foo = 1;
let bar;

bar = 2;
```
Expand Down Expand Up @@ -109,7 +109,7 @@ function foo() {
var bar = 1;
let baz = 2;

for (var i = 0; i < 1; i++) {}
for (let i = 0; i < 1; i++) {}
}
```

Expand Down Expand Up @@ -141,7 +141,7 @@ Examples of **correct** code for the `"never", { "ignoreForLoopInit": true }` op

```js
/*eslint init-declarations: ["error", "never", { "ignoreForLoopInit": true }]*/
for (var i = 0; i < 1; i++) {}
for (let i = 0; i < 1; i++) {}
```

:::
Expand Down
36 changes: 18 additions & 18 deletions docs/src/rules/no-empty-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ Examples of **incorrect** code for this rule:

function foo() {}

var bar = function() {};
const bar = function() {};

var bar = () => {};
const bar1 = () => {};

function* baz() {}

var bar = function*() {};
const bar2 = function*() {};

var obj = {
const obj = {
foo: function() {},

foo: function*() {},
Expand Down Expand Up @@ -93,23 +93,23 @@ function foo() {
// do nothing.
}

var baz = function() {
const baz = function() {
// any clear comments.
};

var baz = () => {
const baz1 = () => {
bar();
};

function* foobar() {
// do nothing.
}

var baz = function*() {
const baz2 = function*() {
// do nothing.
};

var obj = {
const obj = {
foo: function() {
// do nothing.
},
Expand Down Expand Up @@ -203,9 +203,9 @@ Examples of **correct** code for the `{ "allow": ["functions"] }` option:

function foo() {}

var bar = function() {};
const bar = function() {};

var obj = {
const obj = {
foo: function() {}
};
```
Expand All @@ -221,7 +221,7 @@ Examples of **correct** code for the `{ "allow": ["arrowFunctions"] }` option:
```js
/*eslint no-empty-function: ["error", { "allow": ["arrowFunctions"] }]*/

var foo = () => {};
const foo = () => {};
```

:::
Expand All @@ -237,9 +237,9 @@ Examples of **correct** code for the `{ "allow": ["generatorFunctions"] }` optio

function* foo() {}

var bar = function*() {};
const bar = function*() {};

var obj = {
const obj = {
foo: function*() {}
};
```
Expand All @@ -255,7 +255,7 @@ Examples of **correct** code for the `{ "allow": ["methods"] }` option:
```js
/*eslint no-empty-function: ["error", { "allow": ["methods"] }]*/

var obj = {
const obj = {
foo() {}
};

Expand All @@ -276,7 +276,7 @@ Examples of **correct** code for the `{ "allow": ["generatorMethods"] }` option:
```js
/*eslint no-empty-function: ["error", { "allow": ["generatorMethods"] }]*/

var obj = {
const obj = {
*foo() {}
};

Expand All @@ -297,7 +297,7 @@ Examples of **correct** code for the `{ "allow": ["getters"] }` option:
```js
/*eslint no-empty-function: ["error", { "allow": ["getters"] }]*/

var obj = {
const obj = {
get foo() {}
};

Expand All @@ -318,7 +318,7 @@ Examples of **correct** code for the `{ "allow": ["setters"] }` option:
```js
/*eslint no-empty-function: ["error", { "allow": ["setters"] }]*/

var obj = {
const obj = {
set foo(value) {}
};

Expand Down Expand Up @@ -369,7 +369,7 @@ Examples of **correct** code for the `{ "allow": ["asyncMethods"] }` options:
```js
/*eslint no-empty-function: ["error", { "allow": ["asyncMethods"] }]*/

var obj = {
const obj = {
async foo() {}
};

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

var foo = !!!bar;
const foo = !!!bar;

var foo = !!bar ? baz : bat;
const foo1 = !!bar ? baz : bat;

var foo = Boolean(!!bar);
const foo2 = Boolean(!!bar);

var foo = new Boolean(!!bar);
const foo3 = new Boolean(!!bar);

if (!!foo) {
// ...
Expand Down Expand Up @@ -68,14 +68,14 @@ Examples of **correct** code for this rule:
```js
/*eslint no-extra-boolean-cast: "error"*/

var foo = !!bar;
var foo = Boolean(bar);
const foo = !!bar;
const foo1 = Boolean(bar);

function qux() {
return !!bar;
}

var foo = bar ? !!baz : !!bat;
foo = bar ? !!baz : !!bat;
```

:::
Expand Down Expand Up @@ -109,7 +109,7 @@ if ((!!foo || bar) && !!baz) {
//...
}

var foo = new Boolean(!!bar || baz);
const foo = new Boolean(!!bar || baz);

foo && Boolean(bar) ? baz : bat;

Expand All @@ -134,9 +134,9 @@ Examples of **correct** code for this rule with `"enforceForInnerExpressions"` o
```js
/*eslint no-extra-boolean-cast: ["error", {"enforceForInnerExpressions": true}]*/

// Note that `||` and `&&` alone aren't a boolean context for either operand
// Note that `||` and `&&` alone aren't a boolean context for either operand
// since the resultant value need not be a boolean without casting.
var foo = !!bar || baz;
const foo = !!bar || baz;

if (foo || bar) {
//...
Expand All @@ -150,7 +150,7 @@ if ((foo || bar) && baz) {
//...
}

var foo = new Boolean(bar || baz);
const foo1 = new Boolean(bar || baz);

foo && bar ? baz : bat;

Expand Down
4 changes: 2 additions & 2 deletions docs/src/rules/no-restricted-properties.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Examples of **incorrect** code for this rule:
"property": "disallowedPropertyName"
}] */

var example = disallowedObjectName.disallowedPropertyName; /*error Disallowed object property: disallowedObjectName.disallowedPropertyName.*/
const example = disallowedObjectName.disallowedPropertyName; /*error Disallowed object property: disallowedObjectName.disallowedPropertyName.*/

disallowedObjectName.disallowedPropertyName(); /*error Disallowed object property: disallowedObjectName.disallowedPropertyName.*/
```
Expand Down Expand Up @@ -126,7 +126,7 @@ Examples of **correct** code for this rule:
"property": "disallowedPropertyName"
}] */

var example = disallowedObjectName.somePropertyName;
const example = disallowedObjectName.somePropertyName;

allowedObjectName.disallowedPropertyName();
```
Expand Down
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