Skip to content

docs: replace var with const in rule examples #19352

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 2 commits into from
Jan 22, 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
34 changes: 17 additions & 17 deletions docs/src/rules/object-shorthand.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ Here are a few common examples using the ES5 syntax:

```js
// properties
var foo = {
const foo = {
x: x,
y: y,
z: z,
};

// methods
var foo = {
const bar = {
a: function() {},
b: function() {}
};
Expand All @@ -33,10 +33,10 @@ Now here are ES6 equivalents:

```js
// properties
var foo = {x, y, z};
const foo = {x, y, z};

// methods
var foo = {
const bar = {
a() {},
b() {}
};
Expand All @@ -53,7 +53,7 @@ Each of the following properties would warn:
```js
/*eslint object-shorthand: "error"*/

var foo = {
const foo = {
w: function() {},
x: function *() {},
[y]: function() {},
Expand All @@ -66,7 +66,7 @@ In that case the expected syntax would have been:
```js
/*eslint object-shorthand: "error"*/

var foo = {
const foo = {
w() {},
*x() {},
[y]() {},
Expand All @@ -80,7 +80,7 @@ The following will *not* warn:
```js
/*eslint object-shorthand: "error"*/

var foo = {
const foo = {
x: (y) => y
};
```
Expand Down Expand Up @@ -126,7 +126,7 @@ Example of **incorrect** code for this rule with the `"always", { "avoidQuotes":
```js
/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/

var foo = {
const foo = {
"bar-baz"() {}
};
```
Expand All @@ -140,7 +140,7 @@ Example of **correct** code for this rule with the `"always", { "avoidQuotes": t
```js
/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/

var foo = {
const foo = {
"bar-baz": function() {},
"qux": qux
};
Expand All @@ -163,7 +163,7 @@ Example of **correct** code for this rule with the `"always", { "ignoreConstruct
```js
/*eslint object-shorthand: ["error", "always", { "ignoreConstructors": true }]*/

var foo = {
const foo = {
ConstructorFunction: function() {}
};
```
Expand All @@ -179,7 +179,7 @@ Example of **correct** code for this rule with the `"always", { "methodsIgnorePa
```js
/*eslint object-shorthand: ["error", "always", { "methodsIgnorePattern": "^bar$" }]*/

var foo = {
const foo = {
bar: function() {}
};
```
Expand All @@ -201,7 +201,7 @@ Example of **incorrect** code for this rule with the `"always", { "avoidExplicit
```js
/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/

var foo = {
const foo = {
foo: (bar, baz) => {
return bar + baz;
},
Expand All @@ -221,7 +221,7 @@ Example of **correct** code for this rule with the `"always", { "avoidExplicitRe
```js
/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/

var foo = {
const foo = {
foo(bar, baz) {
return bar + baz;
},
Expand All @@ -239,7 +239,7 @@ Example of **incorrect** code for this rule with the `"consistent"` option:
```js
/*eslint object-shorthand: [2, "consistent"]*/

var foo = {
const foo = {
a,
b: "foo",
};
Expand All @@ -254,12 +254,12 @@ Examples of **correct** code for this rule with the `"consistent"` option:
```js
/*eslint object-shorthand: [2, "consistent"]*/

var foo = {
const foo = {
a: a,
b: "foo"
};

var bar = {
const bar = {
a,
b,
};
Expand All @@ -274,7 +274,7 @@ Example of **incorrect** code with the `"consistent-as-needed"` option, which is
```js
/*eslint object-shorthand: [2, "consistent-as-needed"]*/

var foo = {
const foo = {
a: a,
b: b,
};
Expand Down
2 changes: 1 addition & 1 deletion docs/src/rules/prefer-promise-reject-errors.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ new Promise(function(resolve, reject) {
reject(new Error("something bad happened"));
});

var foo = getUnknownValue();
const foo = getUnknownValue();
Promise.reject(foo);
```

Expand Down
6 changes: 3 additions & 3 deletions docs/src/rules/prefer-rest-params.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ function foo() {
}

function foo(action) {
var args = Array.prototype.slice.call(arguments, 1);
const args = Array.prototype.slice.call(arguments, 1);
action.apply(null, args);
}

function foo(action) {
var args = [].slice.call(arguments, 1);
const args = [].slice.call(arguments, 1);
action.apply(null, args);
}
```
Expand All @@ -61,7 +61,7 @@ function foo(arguments) {
console.log(arguments); // This is the first argument.
}
function foo() {
var arguments = 0;
const arguments = 0;
console.log(arguments); // This is a local variable.
}
```
Expand Down
4 changes: 2 additions & 2 deletions docs/src/rules/prefer-spread.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ related_rules:
Before ES2015, one must use `Function.prototype.apply()` to call variadic functions.

```js
var args = [1, 2, 3, 4];
const args = [1, 2, 3, 4];
Math.max.apply(Math, args);
```

In ES2015, one can use spread syntax to call variadic functions.

```js
var args = [1, 2, 3, 4];
const args = [1, 2, 3, 4];
Math.max(...args);
```

Expand Down
16 changes: 8 additions & 8 deletions docs/src/rules/prefer-template.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ related_rules:
In ES2015 (ES6), we can use template literals instead of string concatenation.

```js
var str = "Hello, " + name + "!";
const str = "Hello, " + name + "!";
```

```js
var str = `Hello, ${name}!`;
const str = `Hello, ${name}!`;
```

## Rule Details
Expand All @@ -31,8 +31,8 @@ Examples of **incorrect** code for this rule:
```js
/*eslint prefer-template: "error"*/

var str = "Hello, " + name + "!";
var str = "Time: " + (12 * 60 * 60 * 1000);
const str = "Hello, " + name + "!";
const str1 = "Time: " + (12 * 60 * 60 * 1000);
```

:::
Expand All @@ -44,12 +44,12 @@ Examples of **correct** code for this rule:
```js
/*eslint prefer-template: "error"*/

var str = "Hello World!";
var str = `Hello, ${name}!`;
var str = `Time: ${12 * 60 * 60 * 1000}`;
const str = "Hello World!";
const str1 = `Hello, ${name}!`;
const str2 = `Time: ${12 * 60 * 60 * 1000}`;

// This is reported by `no-useless-concat`.
var str = "Hello, " + "World!";
const str4 = "Hello, " + "World!";
```

:::
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