Skip to content

docs: rewrite examples with var using let and const #19407

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 6 commits into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
docs: rewrite examples with var using let and const
Refs #19240
  • Loading branch information
MueezJavaidHashmi committed Feb 5, 2025
commit f0d5b59a171fbd5bcdf5a466b460953148926654
16 changes: 8 additions & 8 deletions docs/src/rules/func-names.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ Examples of **correct** code for this rule with the `"as-needed"` option:
```js
/*eslint func-names: ["error", "as-needed"]*/

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

const cat = {
meow: function() {}
Expand Down Expand Up @@ -192,7 +192,7 @@ Examples of **correct** code for this rule with the `"always", { "generators": "
```js
/*eslint func-names: ["error", "always", { "generators": "as-needed" }]*/

var foo = function*() {};
const foo = function*() {};
```

:::
Expand All @@ -204,7 +204,7 @@ Examples of **incorrect** code for this rule with the `"always", { "generators":
```js
/*eslint func-names: ["error", "always", { "generators": "never" }]*/

var foo = bar(function *baz() {});
const foo = bar(function *baz() {});
```

:::
Expand All @@ -216,7 +216,7 @@ Examples of **correct** code for this rule with the `"always", { "generators": "
```js
/*eslint func-names: ["error", "always", { "generators": "never" }]*/

var foo = bar(function *() {});
const foo = bar(function *() {});
```

:::
Expand All @@ -228,7 +228,7 @@ Examples of **incorrect** code for this rule with the `"as-needed", { "generator
```js
/*eslint func-names: ["error", "as-needed", { "generators": "never" }]*/

var foo = bar(function *baz() {});
const foo = bar(function *baz() {});
```

:::
Expand All @@ -240,7 +240,7 @@ Examples of **correct** code for this rule with the `"as-needed", { "generators"
```js
/*eslint func-names: ["error", "as-needed", { "generators": "never" }]*/

var foo = bar(function *() {});
const foo = bar(function *() {});
```

:::
Expand All @@ -252,7 +252,7 @@ Examples of **incorrect** code for this rule with the `"never", { "generators":
```js
/*eslint func-names: ["error", "never", { "generators": "always" }]*/

var foo = bar(function *() {});
const foo = bar(function *() {});
```

:::
Expand All @@ -264,7 +264,7 @@ Examples of **correct** code for this rule with the `"never", { "generators": "a
```js
/*eslint func-names: ["error", "never", { "generators": "always" }]*/

var foo = bar(function *baz() {});
const foo = bar(function *baz() {});
```

:::
Expand Down
24 changes: 12 additions & 12 deletions docs/src/rules/func-style.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ For function expressions, you must define the function before it is used, otherw
```js
doSomething(); // error!

var doSomething = function() {
const doSomething = function() {
// ...
};
```
Expand Down Expand Up @@ -93,11 +93,11 @@ Examples of **correct** code for this rule with the default `"expression"` optio
```js
/*eslint func-style: ["error", "expression"]*/

var foo = function() {
const foo = function() {
// ...
};

var foo = () => {};
const foo1 = () => {};

// allowed as allowArrowFunctions : false is applied only for declaration
```
Expand All @@ -113,11 +113,11 @@ Examples of **incorrect** code for this rule with the `"declaration"` option:
```js
/*eslint func-style: ["error", "declaration"]*/

var foo = function() {
const foo = function() {
// ...
};

var foo = () => {};
const foo1 = () => {};
```

:::
Expand Down Expand Up @@ -150,7 +150,7 @@ Examples of additional **correct** code for this rule with the `"declaration", {
```js
/*eslint func-style: ["error", "declaration", { "allowArrowFunctions": true }]*/

var foo = () => {};
const foo = () => {};
```

:::
Expand Down Expand Up @@ -182,11 +182,11 @@ Examples of **correct** code for this rule with the `"declaration"` and `{"overr
```js
/*eslint func-style: ["error", "declaration", { "overrides": { "namedExports": "expression" } }]*/

export var foo = function() {
export const foo = function() {
// ...
};

export var bar = () => {};
export const bar = () => {};
```

:::
Expand All @@ -200,11 +200,11 @@ Examples of **incorrect** code for this rule with the `"expression"` and `{"over
```js
/*eslint func-style: ["error", "expression", { "overrides": { "namedExports": "declaration" } }]*/

export var foo = function() {
export const foo = function() {
// ...
};

export var bar = () => {};
export const bar = () => {};
```

:::
Expand Down Expand Up @@ -232,11 +232,11 @@ Examples of **correct** code for this rule with the `{"overrides": { "namedExpor
```js
/*eslint func-style: ["error", "expression", { "overrides": { "namedExports": "ignore" } }]*/

export var foo = function() {
export const foo = function() {
// ...
};

export var bar = () => {};
export const bar = () => {};

export function baz() {
// ...
Expand Down
26 changes: 13 additions & 13 deletions docs/src/rules/grouped-accessor-pairs.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ A getter and setter for the same property don't necessarily have to be defined a
For example, the following statements would create the same object:

```js
var o = {
const o = {
get a() {
return this.val;
},
Expand All @@ -27,7 +27,7 @@ var o = {
b: 1
};

var o = {
const o1 = {
get a() {
return this.val;
},
Expand Down Expand Up @@ -57,7 +57,7 @@ Examples of **incorrect** code for this rule:
```js
/*eslint grouped-accessor-pairs: "error"*/

var foo = {
const foo = {
get a() {
return this.val;
},
Expand All @@ -67,7 +67,7 @@ var foo = {
}
};

var bar = {
const bar = {
set b(value) {
this.val = value;
},
Expand Down Expand Up @@ -107,7 +107,7 @@ Examples of **correct** code for this rule:
```js
/*eslint grouped-accessor-pairs: "error"*/

var foo = {
const foo = {
get a() {
return this.val;
},
Expand All @@ -117,7 +117,7 @@ var foo = {
b: 1
};

var bar = {
const bar = {
set b(value) {
this.val = value;
},
Expand Down Expand Up @@ -167,7 +167,7 @@ Examples of **incorrect** code for this rule with the `"getBeforeSet"` option:
```js
/*eslint grouped-accessor-pairs: ["error", "getBeforeSet"]*/

var foo = {
const foo = {
set a(value) {
this.val = value;
},
Expand Down Expand Up @@ -204,7 +204,7 @@ Examples of **correct** code for this rule with the `"getBeforeSet"` option:
```js
/*eslint grouped-accessor-pairs: ["error", "getBeforeSet"]*/

var foo = {
const foo = {
get a() {
return this.val;
},
Expand Down Expand Up @@ -243,7 +243,7 @@ Examples of **incorrect** code for this rule with the `"setBeforeGet"` option:
```js
/*eslint grouped-accessor-pairs: ["error", "setBeforeGet"]*/

var foo = {
const foo = {
get a() {
return this.val;
},
Expand Down Expand Up @@ -280,7 +280,7 @@ Examples of **correct** code for this rule with the `"setBeforeGet"` option:
```js
/*eslint grouped-accessor-pairs: ["error", "setBeforeGet"]*/

var foo = {
const foo = {
set a(value) {
this.val = value;
},
Expand Down Expand Up @@ -318,10 +318,10 @@ might require or miss to require grouping or order for getters/setters that have
```js
/*eslint grouped-accessor-pairs: "error"*/

var a = 1;
const a = 1;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const a = 1;
let a = 1;

Since the code below is updating this variable.

Copy link
Contributor Author

@MueezJavaidHashmi MueezJavaidHashmi Feb 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am so sorry I missed that. I have updated the PR.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know if this is the right place for this, but if I wanted to learn more on how es-lint works and the core functionality so I can start fixing some bugs. What might be a good place to start?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can start with Ways to Extends ESLint section of docs and so on.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Source code, and documentation on https://eslint.org/docs/latest/.

For verifed bugs, you can check "Ready to Implement" column here:

Triage (view)


// false warning (false positive)
var foo = {
const foo = {
get [a++]() {
return this.val;
},
Expand All @@ -332,7 +332,7 @@ var foo = {
};

// missed warning (false negative)
var bar = {
const bar = {
get [++a]() {
return this.val;
},
Expand Down
28 changes: 14 additions & 14 deletions docs/src/rules/max-lines-per-function.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Examples of **incorrect** code for this rule with a particular max value:
```js
/*eslint max-lines-per-function: ["error", 2]*/
function foo() {
var x = 0;
const x = 0;
}
```

Expand All @@ -91,7 +91,7 @@ function foo() {
/*eslint max-lines-per-function: ["error", 3]*/
function foo() {
// a comment
var x = 0;
const x = 0;
}
```

Expand All @@ -104,7 +104,7 @@ function foo() {
function foo() {
// a comment followed by a blank line

var x = 0;
const x = 0;
}
```

Expand All @@ -117,7 +117,7 @@ Examples of **correct** code for this rule with a particular max value:
```js
/*eslint max-lines-per-function: ["error", 3]*/
function foo() {
var x = 0;
const x = 0;
}
```

Expand All @@ -129,7 +129,7 @@ function foo() {
/*eslint max-lines-per-function: ["error", 4]*/
function foo() {
// a comment
var x = 0;
const x = 0;
}
```

Expand All @@ -142,7 +142,7 @@ function foo() {
function foo() {
// a comment followed by a blank line

var x = 0;
const x = 0;
}
```

Expand All @@ -158,7 +158,7 @@ Examples of **incorrect** code for this rule with the `{ "skipBlankLines": true
/*eslint max-lines-per-function: ["error", {"max": 2, "skipBlankLines": true}]*/
function foo() {

var x = 0;
const x = 0;
}
```

Expand All @@ -172,7 +172,7 @@ Examples of **correct** code for this rule with the `{ "skipBlankLines": true }`
/*eslint max-lines-per-function: ["error", {"max": 3, "skipBlankLines": true}]*/
function foo() {

var x = 0;
const x = 0;
}
```

Expand All @@ -188,7 +188,7 @@ Examples of **incorrect** code for this rule with the `{ "skipComments": true }`
/*eslint max-lines-per-function: ["error", {"max": 2, "skipComments": true}]*/
function foo() {
// a comment
var x = 0;
const x = 0;
}
```

Expand All @@ -202,7 +202,7 @@ Examples of **correct** code for this rule with the `{ "skipComments": true }` o
/*eslint max-lines-per-function: ["error", {"max": 3, "skipComments": true}]*/
function foo() {
// a comment
var x = 0;
const x = 0;
}
```

Expand All @@ -217,11 +217,11 @@ Examples of **incorrect** code for this rule with the `{ "IIFEs": true }` option
```js
/*eslint max-lines-per-function: ["error", {"max": 2, "IIFEs": true}]*/
(function(){
var x = 0;
const x = 0;
}());

(() => {
var x = 0;
const x = 0;
})();
```

Expand All @@ -234,11 +234,11 @@ Examples of **correct** code for this rule with the `{ "IIFEs": true }` option:
```js
/*eslint max-lines-per-function: ["error", {"max": 3, "IIFEs": true}]*/
(function(){
var x = 0;
const x = 0;
}());

(() => {
var x = 0;
const x = 0;
})();
```

Expand Down
Loading
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