Skip to content

docs: rewrite var using const in rule examples #19303

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 1 commit into from
Jan 2, 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/no-useless-computed-key.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ rule_type: suggestion
It's unnecessary to use computed properties with literals such as:

```js
var foo = {["a"]: "b"};
const foo = {["a"]: "b"};
```

The code can be rewritten as:

```js
var foo = {"a": "b"};
const foo = {"a": "b"};
```

## Rule Details
Expand All @@ -28,14 +28,14 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-useless-computed-key: "error"*/

var a = { ['0']: 0 };
var a = { ['0+1,234']: 0 };
var a = { [0]: 0 };
var a = { ['x']: 0 };
var a = { ['x']() {} };
const a = { ['0']: 0 };
const b = { ['0+1,234']: 0 };
const c = { [0]: 0 };
const d = { ['x']: 0 };
const e = { ['x']() {} };

var { [0]: a } = obj;
var { ['x']: a } = obj;
const { [0]: foo } = obj;
const { ['x']: bar } = obj;

class Foo {
["foo"] = "bar";
Expand All @@ -60,14 +60,14 @@ Examples of **correct** code for this rule:
```js
/*eslint no-useless-computed-key: "error"*/

var c = { 'a': 0 };
var c = { 0: 0 };
var a = { x() {} };
var c = { a: 0 };
var c = { '0+1,234': 0 };
const a = { 'a': 0 };
const b = { 0: 0 };
const c = { x() {} };
const d = { a: 0 };
const e = { '0+1,234': 0 };

var { 0: a } = obj;
var { 'x': a } = obj;
const { 0: foo } = obj;
const { 'x': bar } = obj;

class Foo {
"foo" = "bar";
Expand All @@ -92,7 +92,7 @@ Examples of additional **correct** code for this rule:
```js
/*eslint no-useless-computed-key: "error"*/

var c = {
const c = {
"__proto__": foo, // defines object's prototype

["__proto__"]: bar // defines a property named "__proto__"
Expand Down
24 changes: 12 additions & 12 deletions docs/src/rules/no-useless-concat.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ rule_type: suggestion
It's unnecessary to concatenate two strings together, such as:

```js
var foo = "a" + "b";
const foo = "a" + "b";
```

This code is likely the result of refactoring where a variable was removed from the concatenation (such as `"a" + b + "b"`). In such a case, the concatenation isn't important and the code can be rewritten as:

```js
var foo = "ab";
const foo = "ab";
```

## Rule Details
Expand All @@ -27,13 +27,13 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-useless-concat: "error"*/

var a = `some` + `string`;
const a = `some` + `string`;

// these are the same as "10"
var a = '1' + '0';
var a = '1' + `0`;
var a = `1` + '0';
var a = `1` + `0`;
const b = '1' + '0';
const c = '1' + `0`;
const d = `1` + '0';
const e = `1` + `0`;
```

:::
Expand All @@ -46,12 +46,12 @@ Examples of **correct** code for this rule:
/*eslint no-useless-concat: "error"*/

// when a non string is included
var c = a + b;
var c = '1' + a;
var a = 1 + '1';
var c = 1 - 2;
const a = a + b;
const b = '1' + a;
const c = 1 + '1';
const d = 1 - 2;
// when the string concatenation is multiline
var c = "foo" +
const e = "foo" +
"bar";
```

Expand Down
26 changes: 13 additions & 13 deletions docs/src/rules/no-useless-return.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ Examples of **incorrect** code for this rule:
```js
/* eslint no-useless-return: "error" */

var foo = function() { return; }
const foo = function() { return; }

var foo = function() {
const bar = function() {
doSomething();
return;
}

var foo = function() {
const baz = function() {
if (condition) {
bar();
qux();
return;
} else {
baz();
quux();
}
}

var foo = function() {
const item = function() {
switch (bar) {
case 1:
doSomething();
Expand All @@ -55,23 +55,23 @@ Examples of **correct** code for this rule:
```js
/* eslint no-useless-return: "error" */

var foo = function() { return 5; }
const foo = function() { return 5; }

var foo = function() {
const bar = function() {
return doSomething();
}

var foo = function() {
const baz = function() {
if (condition) {
bar();
qux();
return;
} else {
baz();
quux();
}
qux();
}

var foo = function() {
const item = function() {
switch (bar) {
case 1:
doSomething();
Expand All @@ -81,7 +81,7 @@ var foo = function() {
}
}

var foo = function() {
const func = function() {
for (const foo of bar) {
return;
}
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