Skip to content

Commit

Permalink
docs: replace var with let or const in rules docs (#19396)
Browse files Browse the repository at this point in the history
* docs: replace var with let or const in rules docs

* docs: update global variable
  • Loading branch information
dharbrueger authored Feb 3, 2025
1 parent 4053226 commit 56ff404
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 24 deletions.
4 changes: 2 additions & 2 deletions docs/src/rules/no-new.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ rule_type: suggestion
The goal of using `new` with a constructor is typically to create an object of a particular type and store that object in a variable, such as:

```js
var person = new Person();
const person = new Person();
```

It's less common to use `new` and not store the result, such as:
Expand Down Expand Up @@ -41,7 +41,7 @@ Examples of **correct** code for this rule:
```js
/*eslint no-new: "error"*/

var thing = new Thing();
const thing = new Thing();

Foo();
```
Expand Down
8 changes: 4 additions & 4 deletions docs/src/rules/no-unused-expressions.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ This rule aims to eliminate unused expressions which have no effect on the state
This rule does not apply to function calls or constructor calls with the `new` operator, because they could have *side effects* on the state of the program.

```js
var i = 0;
let i = 0;
function increment() { i += 1; }
increment(); // return value is unused, but i changed as a side effect

var nThings = 0;
let nThings = 0;
function Thing() { nThings += 1; }
new Thing(); // constructed object is unused, but nThings changed as a side effect
```
Expand Down Expand Up @@ -270,9 +270,9 @@ Examples of **correct** code for the `{ "enforceForJSX": true }` option:
```jsx
/*eslint no-unused-expressions: ["error", { "enforceForJSX": true }]*/

var myComponentPartial = <MyComponent />;
const myComponentPartial = <MyComponent />;

var myFragment = <></>;
const myFragment = <></>;
```

:::
28 changes: 14 additions & 14 deletions docs/src/rules/no-unused-vars.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ This rule is aimed at eliminating unused variables, functions, and function para
A variable `foo` is considered to be used if any of the following are true:

* It is called (`foo()`) or constructed (`new foo()`)
* It is read (`var bar = foo`)
* It is read (`let bar = foo`)
* It is passed into a function as an argument (`doSomething(foo)`)
* It is read inside of a function that is passed to another function (`doSomething(function() { foo(); })`)

A variable is *not* considered to be used if it is only ever declared (`var foo = 5`) or assigned to (`foo = 7`).
A variable is *not* considered to be used if it is only ever declared (`let foo = 5`) or assigned to (`foo = 7`).

Examples of **incorrect** code for this rule:

Expand All @@ -33,14 +33,14 @@ Examples of **incorrect** code for this rule:
// It checks variables you have defined as global
some_unused_var = 42;

var x;
let x;

// Write-only variables are not considered as used.
var y = 10;
let y = 10;
y = 5;

// A read for a modification of itself is not considered as used.
var z = 0;
let z = 0;
z = z + 1;

// By default, unused arguments cause warnings.
Expand Down Expand Up @@ -70,7 +70,7 @@ Examples of **correct** code for this rule:
```js
/*eslint no-unused-vars: "error"*/

var x = 10;
const x = 10;
alert(x);

// foo is considered used here
Expand Down Expand Up @@ -180,8 +180,8 @@ Examples of **correct** code for the `{ "varsIgnorePattern": "[iI]gnored" }` opt
```js
/*eslint no-unused-vars: ["error", { "varsIgnorePattern": "[iI]gnored" }]*/

var firstVarIgnored = 1;
var secondVar = 2;
const firstVarIgnored = 1;
const secondVar = 2;
console.log(secondVar);
```

Expand Down Expand Up @@ -404,12 +404,12 @@ Examples of **correct** code for the `{ "ignoreRestSiblings": true }` option:
/*eslint no-unused-vars: ["error", { "ignoreRestSiblings": true }]*/

// 'foo' and 'bar' were ignored because they have a rest property sibling.
var { foo, ...rest } = data;
const { foo, ...rest } = data;
console.log(rest);

// OR

var bar;
let bar;
({ bar, ...rest } = data);
```

Expand Down Expand Up @@ -474,8 +474,8 @@ Examples of **incorrect** code for the `{ "reportUsedIgnorePattern": true }` opt
```js
/*eslint no-unused-vars: ["error", { "reportUsedIgnorePattern": true, "varsIgnorePattern": "[iI]gnored" }]*/

var firstVarIgnored = 1;
var secondVar = 2;
const firstVarIgnored = 1;
const secondVar = 2;
console.log(firstVarIgnored, secondVar);
```

Expand All @@ -488,8 +488,8 @@ Examples of **correct** code for the `{ "reportUsedIgnorePattern": true }` optio
```js
/*eslint no-unused-vars: ["error", { "reportUsedIgnorePattern": true, "varsIgnorePattern": "[iI]gnored" }]*/

var firstVar = 1;
var secondVar = 2;
const firstVar = 1;
const secondVar = 2;
console.log(firstVar, secondVar);
```

Expand Down
6 changes: 3 additions & 3 deletions docs/src/rules/no-void.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ foo = undefined;
When used with IIFE (immediately-invoked function expression), `void` can be used to force the function keyword to be treated as an expression instead of a declaration:

```js
var foo = 1;
let foo = 1;
void function(){ foo = 1; }() // will assign foo a value of 1
+function(){ foo = 1; }() // same as above
```
Expand All @@ -68,7 +68,7 @@ Examples of **incorrect** code for this rule:
void foo
void someFunction();

var foo = void bar();
const foo = void bar();
function baz() {
return void 0;
}
Expand All @@ -93,7 +93,7 @@ Examples of **incorrect** code for `{ "allowAsStatement": true }`:
```js
/*eslint no-void: ["error", { "allowAsStatement": true }]*/

var foo = void bar();
const foo = void bar();
function baz() {
return void 0;
}
Expand Down
2 changes: 1 addition & 1 deletion docs/src/rules/prefer-arrow-callback.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ foo(a => a); // OK
foo(function*() { yield; }); // OK

// function expression not used as callback or function argument
var foo = function foo(a) { return a; }; // OK
const foo = function foo(a) { return a; }; // OK

// unbound function expression callback
foo(function() { return this.a; }); // OK
Expand Down

0 comments on commit 56ff404

Please sign in to comment.