From 6e7361bb6ae93c87fccdf2219379c7793517f17a Mon Sep 17 00:00:00 2001 From: Tanuj Kanti <86398394+Tanujkanti4441@users.noreply.github.com> Date: Thu, 2 Jan 2025 22:12:31 +0530 Subject: [PATCH] docs: replace `var` with `let` and `const` in rule example (#19302) * docs: replace var with let and const * replace more var in no-func-assign --- docs/src/rules/no-ex-assign.md | 2 +- docs/src/rules/no-func-assign.md | 8 +++--- docs/src/rules/no-irregular-whitespace.md | 24 ++++++++-------- .../src/rules/no-new-native-nonconstructor.md | 12 ++++---- docs/src/rules/no-obj-calls.md | 28 +++++++++---------- 5 files changed, 37 insertions(+), 37 deletions(-) diff --git a/docs/src/rules/no-ex-assign.md b/docs/src/rules/no-ex-assign.md index 395164d204bc..79263089f009 100644 --- a/docs/src/rules/no-ex-assign.md +++ b/docs/src/rules/no-ex-assign.md @@ -40,7 +40,7 @@ Examples of **correct** code for this rule: try { // code } catch (e) { - var foo = 10; + const foo = 10; } ``` diff --git a/docs/src/rules/no-func-assign.md b/docs/src/rules/no-func-assign.md index 6346e2b8064f..160f9380a311 100644 --- a/docs/src/rules/no-func-assign.md +++ b/docs/src/rules/no-func-assign.md @@ -6,7 +6,7 @@ handled_by_typescript: true -JavaScript functions can be written as a FunctionDeclaration `function foo() { ... }` or as a FunctionExpression `var foo = function() { ... };`. While a JavaScript interpreter might tolerate it, overwriting/reassigning a function written as a FunctionDeclaration is often indicative of a mistake or issue. +JavaScript functions can be written as a FunctionDeclaration `function foo() { ... }` or as a FunctionExpression `const foo = function() { ... };`. While a JavaScript interpreter might tolerate it, overwriting/reassigning a function written as a FunctionDeclaration is often indicative of a mistake or issue. ```js function foo() {} @@ -31,7 +31,7 @@ function baz() { baz = bar; } -var a = function hello() { +let a = function hello() { hello = 123; }; ``` @@ -58,7 +58,7 @@ Examples of **correct** code for this rule: ```js /*eslint no-func-assign: "error"*/ -var foo = function () {} +let foo = function () {} foo = bar; function baz(baz) { // `baz` is shadowed. @@ -66,7 +66,7 @@ function baz(baz) { // `baz` is shadowed. } function qux() { - var qux = bar; // `qux` is shadowed. + const qux = bar; // `qux` is shadowed. } ``` diff --git a/docs/src/rules/no-irregular-whitespace.md b/docs/src/rules/no-irregular-whitespace.md index 8fb3f3fac49c..8b1972d1d61f 100644 --- a/docs/src/rules/no-irregular-whitespace.md +++ b/docs/src/rules/no-irregular-whitespace.md @@ -81,31 +81,31 @@ Examples of **incorrect** code for this rule with the default `{ "skipStrings": ```js /*eslint no-irregular-whitespace: "error"*/ -var thing = function() /**/{ +const thing = function() /**/{ return 'test'; } -var thing = function( /**/){ +const foo = function( /**/){ return 'test'; } -var thing = function /**/(){ +const bar = function /**/(){ return 'test'; } -var thing = function /**/(){ +const baz = function /**/(){ return 'test'; } -var thing = function() { +const qux = function() { return 'test'; /**/ } -var thing = function() { +const quux = function() { return 'test'; /**/ } -var thing = function() { +const item = function() { // Description : some descriptive text } @@ -113,11 +113,11 @@ var thing = function() { Description : some descriptive text */ -var thing = function() { +const func = function() { return / regexp/; } -var thing = function() { +const myFunc = function() { return `template string`; } ``` @@ -131,15 +131,15 @@ Examples of **correct** code for this rule with the default `{ "skipStrings": tr ```js /*eslint no-irregular-whitespace: "error"*/ -var thing = function() { +const thing = function() { return ' thing'; } -var thing = function() { +const foo = function() { return '​thing'; } -var thing = function() { +const bar = function() { return 'th ing'; } ``` diff --git a/docs/src/rules/no-new-native-nonconstructor.md b/docs/src/rules/no-new-native-nonconstructor.md index e605241abc0d..a8d35a108001 100644 --- a/docs/src/rules/no-new-native-nonconstructor.md +++ b/docs/src/rules/no-new-native-nonconstructor.md @@ -16,10 +16,10 @@ It is a convention in JavaScript that global variables beginning with an upperca ```js // throws a TypeError -let foo = new Symbol("foo"); +const foo = new Symbol("foo"); // throws a TypeError -let result = new BigInt(9007199254740991); +const result = new BigInt(9007199254740991); ``` Both `new Symbol` and `new BigInt` throw a type error because they are functions and not classes. It is easy to make this mistake by assuming the uppercase letters indicate classes. @@ -40,8 +40,8 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-new-native-nonconstructor: "error"*/ -var foo = new Symbol('foo'); -var bar = new BigInt(9007199254740991); +const foo = new Symbol('foo'); +const bar = new BigInt(9007199254740991); ``` ::: @@ -53,8 +53,8 @@ Examples of **correct** code for this rule: ```js /*eslint no-new-native-nonconstructor: "error"*/ -var foo = Symbol('foo'); -var bar = BigInt(9007199254740991); +const foo = Symbol('foo'); +const bar = BigInt(9007199254740991); // Ignores shadowed Symbol. function baz(Symbol) { diff --git a/docs/src/rules/no-obj-calls.md b/docs/src/rules/no-obj-calls.md index 2ab8d27f8b71..e7cadbd16778 100644 --- a/docs/src/rules/no-obj-calls.md +++ b/docs/src/rules/no-obj-calls.md @@ -39,25 +39,25 @@ Examples of **incorrect** code for this rule: ```js /*eslint no-obj-calls: "error"*/ -var math = Math(); +const math = Math(); -var newMath = new Math(); +const newMath = new Math(); -var json = JSON(); +const json = JSON(); -var newJSON = new JSON(); +const newJSON = new JSON(); -var reflect = Reflect(); +const reflect = Reflect(); -var newReflect = new Reflect(); +const newReflect = new Reflect(); -var atomics = Atomics(); +const atomics = Atomics(); -var newAtomics = new Atomics(); +const newAtomics = new Atomics(); -var intl = Intl(); +const intl = Intl(); -var newIntl = new Intl(); +const newIntl = new Intl(); ``` ::: @@ -73,13 +73,13 @@ function area(r) { return Math.PI * r * r; } -var object = JSON.parse("{}"); +const object = JSON.parse("{}"); -var value = Reflect.get({ x: 1, y: 2 }, "x"); +const value = Reflect.get({ x: 1, y: 2 }, "x"); -var first = Atomics.load(foo, 0); +const first = Atomics.load(foo, 0); -var segmenterFr = new Intl.Segmenter("fr", { granularity: "word" }); +const segmenterFr = new Intl.Segmenter("fr", { granularity: "word" }); ``` :::