From 4e5d0467a16f896fd62d469a223bbb36731e4072 Mon Sep 17 00:00:00 2001 From: MueezJavaidHashmi Date: Mon, 3 Feb 2025 20:43:48 +0500 Subject: [PATCH] docs: rewrite examples with var using let and const Refs #19240 --- docs/src/rules/init-declarations.md | 12 ++++---- docs/src/rules/no-empty-function.md | 36 +++++++++++----------- docs/src/rules/no-extra-boolean-cast.md | 22 ++++++------- docs/src/rules/no-restricted-properties.md | 4 +-- 4 files changed, 37 insertions(+), 37 deletions(-) diff --git a/docs/src/rules/init-declarations.md b/docs/src/rules/init-declarations.md index 32760b96cb3f..9ec9473936b9 100644 --- a/docs/src/rules/init-declarations.md +++ b/docs/src/rules/init-declarations.md @@ -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; @@ -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; ``` @@ -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++) {} } ``` @@ -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++) {} ``` ::: diff --git a/docs/src/rules/no-empty-function.md b/docs/src/rules/no-empty-function.md index 2810175e3eeb..9956476fe721 100644 --- a/docs/src/rules/no-empty-function.md +++ b/docs/src/rules/no-empty-function.md @@ -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*() {}, @@ -93,11 +93,11 @@ function foo() { // do nothing. } -var baz = function() { +const baz = function() { // any clear comments. }; -var baz = () => { +const baz1 = () => { bar(); }; @@ -105,11 +105,11 @@ function* foobar() { // do nothing. } -var baz = function*() { +const baz2 = function*() { // do nothing. }; -var obj = { +const obj = { foo: function() { // do nothing. }, @@ -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() {} }; ``` @@ -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 = () => {}; ``` ::: @@ -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*() {} }; ``` @@ -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() {} }; @@ -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() {} }; @@ -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() {} }; @@ -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) {} }; @@ -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() {} }; diff --git a/docs/src/rules/no-extra-boolean-cast.md b/docs/src/rules/no-extra-boolean-cast.md index e11394b20854..dea7354a86e9 100644 --- a/docs/src/rules/no-extra-boolean-cast.md +++ b/docs/src/rules/no-extra-boolean-cast.md @@ -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) { // ... @@ -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; ``` ::: @@ -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; @@ -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) { //... @@ -150,7 +150,7 @@ if ((foo || bar) && baz) { //... } -var foo = new Boolean(bar || baz); +const foo1 = new Boolean(bar || baz); foo && bar ? baz : bat; diff --git a/docs/src/rules/no-restricted-properties.md b/docs/src/rules/no-restricted-properties.md index 2e681733fc23..7fa7e3d0ddb1 100644 --- a/docs/src/rules/no-restricted-properties.md +++ b/docs/src/rules/no-restricted-properties.md @@ -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.*/ ``` @@ -126,7 +126,7 @@ Examples of **correct** code for this rule: "property": "disallowedPropertyName" }] */ -var example = disallowedObjectName.somePropertyName; +const example = disallowedObjectName.somePropertyName; allowedObjectName.disallowedPropertyName(); ``` 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