Skip to content

Commit

Permalink
docs: replace var with let and const in rule example (#19302)
Browse files Browse the repository at this point in the history
* docs: replace var with let and const

* replace more var in no-func-assign
  • Loading branch information
Tanujkanti4441 authored Jan 2, 2025
1 parent 069af5e commit 6e7361b
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docs/src/rules/no-ex-assign.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ Examples of **correct** code for this rule:
try {
// code
} catch (e) {
var foo = 10;
const foo = 10;
}
```

Expand Down
8 changes: 4 additions & 4 deletions docs/src/rules/no-func-assign.md
Original file line number Diff line number Diff line change
Expand Up @@ -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() {}
Expand All @@ -31,7 +31,7 @@ function baz() {
baz = bar;
}

var a = function hello() {
let a = function hello() {
hello = 123;
};
```
Expand All @@ -58,15 +58,15 @@ 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.
baz = bar;
}

function qux() {
var qux = bar; // `qux` is shadowed.
const qux = bar; // `qux` is shadowed.
}
```

Expand Down
24 changes: 12 additions & 12 deletions docs/src/rules/no-irregular-whitespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,43 +81,43 @@ Examples of **incorrect** code for this rule with the default `{ "skipStrings":
```js
/*eslint no-irregular-whitespace: "error"*/

var thing = function() /*<NBSP>*/{
const thing = function() /*<NBSP>*/{
return 'test';
}

var thing = function/*<NBSP>*/){
const foo = function/*<NBSP>*/){
return 'test';
}

var thing = function /*<NBSP>*/(){
const bar = function /*<NBSP>*/(){
return 'test';
}

var thing = function/*<Ogham Space Mark>*/(){
const baz = function/*<Ogham Space Mark>*/(){
return 'test';
}

var thing = function() {
const qux = function() {
return 'test'; /*<ENSP>*/
}

var thing = function() {
const quux = function() {
return 'test'/*<NBSP>*/
}

var thing = function() {
const item = function() {
// Description <NBSP>: some descriptive text
}

/*
Description <NBSP>: some descriptive text
*/

var thing = function() {
const func = function() {
return / <NBSP>regexp/;
}

var thing = function() {
const myFunc = function() {
return `template <NBSP>string`;
}
```
Expand All @@ -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 ' <NBSP>thing';
}

var thing = function() {
const foo = function() {
return '​<ZWSP>thing';
}

var thing = function() {
const bar = function() {
return 'th <NBSP>ing';
}
```
Expand Down
12 changes: 6 additions & 6 deletions docs/src/rules/no-new-native-nonconstructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);
```

:::
Expand All @@ -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) {
Expand Down
28 changes: 14 additions & 14 deletions docs/src/rules/no-obj-calls.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
```

:::
Expand All @@ -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" });
```

:::

0 comments on commit 6e7361b

Please sign in to comment.