Skip to content

docs: rewrite some examples with var using let and const #19404

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
Feb 4, 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
docs: rewrite some examples with var using let and const
Refs #19240
  • Loading branch information
MueezJavaidHashmi committed Feb 4, 2025
commit 4dae463ab11b0dfc9f88963824b126a12d3b6508
16 changes: 8 additions & 8 deletions docs/src/rules/no-plusplus.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ rule_type: suggestion
Because the unary `++` and `--` operators are subject to automatic semicolon insertion, differences in whitespace can change semantics of source code.

```js
var i = 10;
var j = 20;
let i = 10;
let j = 20;

i ++
j
// i = 11, j = 20
```

```js
var i = 10;
var j = 20;
let i = 10;
let j = 20;

i
++
Expand All @@ -36,10 +36,10 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-plusplus: "error"*/

var foo = 0;
let foo = 0;
foo++;

var bar = 42;
let bar = 42;
bar--;

for (i = 0; i < l; i++) {
Expand All @@ -56,10 +56,10 @@ Examples of **correct** code for this rule:
```js
/*eslint no-plusplus: "error"*/

var foo = 0;
let foo = 0;
foo += 1;

var bar = 42;
let bar = 42;
bar -= 1;

for (i = 0; i < l; i += 1) {
Expand Down
8 changes: 4 additions & 4 deletions docs/src/rules/no-proto.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-proto: "error"*/

var a = obj.__proto__;
const a = obj.__proto__;

var a = obj["__proto__"];
const a1 = obj["__proto__"];

obj.__proto__ = b;

Expand All @@ -37,11 +37,11 @@ Examples of **correct** code for this rule:
```js
/*eslint no-proto: "error"*/

var a = Object.getPrototypeOf(obj);
const a = Object.getPrototypeOf(obj);

Object.setPrototypeOf(obj, b);

var c = { __proto__: a };
const c = { __proto__: a };
```

:::
Expand Down
12 changes: 6 additions & 6 deletions docs/src/rules/no-regex-spaces.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ related_rules:
Regular expressions can be very complex and difficult to understand, which is why it's important to keep them as simple as possible in order to avoid mistakes. One of the more error-prone things you can do with a regular expression is to use more than one space, such as:

```js
var re = /foo bar/;
const re = /foo bar/;
```

In this regular expression, it's very hard to tell how many spaces are intended to be matched. It's better to use only one space and then specify how many spaces are expected, such as:

```js
var re = /foo {3}bar/;
const re = /foo {3}bar/;
```

Now it is very clear that three spaces are expected to be matched.
Expand All @@ -35,8 +35,8 @@ Examples of **incorrect** code for this rule:
```js
/*eslint no-regex-spaces: "error"*/

var re = /foo bar/;
var re = new RegExp("foo bar");
const re = /foo bar/;
const re1 = new RegExp("foo bar");
```

:::
Expand All @@ -48,8 +48,8 @@ Examples of **correct** code for this rule:
```js
/*eslint no-regex-spaces: "error"*/

var re = /foo {3}bar/;
var re = new RegExp("foo {3}bar");
const re = /foo {3}bar/;
const re1 = new RegExp("foo {3}bar");
```

:::
Expand Down
2 changes: 1 addition & 1 deletion docs/src/rules/no-restricted-globals.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ import event from "event-module";
/*global event*/
/*eslint no-restricted-globals: ["error", "event"]*/

var event = 1;
const event = 1;
```

:::
Expand Down
14 changes: 7 additions & 7 deletions docs/src/rules/no-restricted-modules.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ Examples of **incorrect** code for this rule with sample `"fs", "cluster", "lod
```js
/*eslint no-restricted-modules: ["error", "fs", "cluster"]*/

var fs = require('fs');
var cluster = require('cluster');
const fs = require('fs');
const cluster = require('cluster');
```

:::
Expand All @@ -91,7 +91,7 @@ var cluster = require('cluster');
```js
/*eslint no-restricted-modules: ["error", {"paths": ["cluster"] }]*/

var cluster = require('cluster');
const cluster = require('cluster');
```

:::
Expand All @@ -101,7 +101,7 @@ var cluster = require('cluster');
```js
/*eslint no-restricted-modules: ["error", { "patterns": ["lodash/*"] }]*/

var pick = require('lodash/pick');
const pick = require('lodash/pick');
```

:::
Expand All @@ -113,7 +113,7 @@ Examples of **correct** code for this rule with sample `"fs", "cluster", "lodash
```js
/*eslint no-restricted-modules: ["error", "fs", "cluster"]*/

var crypto = require('crypto');
const crypto = require('crypto');
```

:::
Expand All @@ -126,8 +126,8 @@ var crypto = require('crypto');
"patterns": ["lodash/*", "!lodash/pick"]
}]*/

var crypto = require('crypto');
var pick = require('lodash/pick');
const crypto = require('crypto');
const pick = require('lodash/pick');
```

:::
2 changes: 1 addition & 1 deletion docs/src/rules/no-restricted-syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ with (me) {
dontMess();
}

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

foo in bar;
```
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