Skip to content

docs: update no-undef-init when not to use section #19624

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 4 commits into from
Apr 17, 2025

Conversation

Tanujkanti4441
Copy link
Contributor

Prerequisites checklist

What is the purpose of this pull request? (put an "X" next to an item)

[x] Documentation update
[ ] Bug fix (template)
[ ] New rule (template)
[ ] Changes an existing rule (template)
[ ] Add autofix to a rule
[ ] Add a CLI option
[ ] Add something to the core
[ ] Other, please explain:

What changes did you make? (Give an overview)

Updated when not to use section of no-undef-init rule docs by adding example of variable declaration with uninitialized and initialized with undefined.

Is there anything you'd like reviewers to focus on?

Fixes #19623

@Tanujkanti4441 Tanujkanti4441 requested a review from a team as a code owner April 15, 2025 15:17
@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Apr 15, 2025
@eslint-github-bot eslint-github-bot bot added the documentation Relates to ESLint's documentation label Apr 15, 2025
Copy link

netlify bot commented Apr 15, 2025

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit 9584ed6
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/68011743e83e7200086b0c6d
😎 Deploy Preview https://deploy-preview-19624--docs-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@mdjermanovic mdjermanovic moved this from Needs Triage to Implementing in Triage Apr 15, 2025
@mdjermanovic mdjermanovic added rule Relates to ESLint's core rules accepted There is consensus among the team that this change meets the criteria for inclusion labels Apr 15, 2025
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

Can you also update the first paragraph of this section, as there are two situations where initializing to undefined behaves differently than omitting the initialization (mentioned loop, and redeclaration).

There is one situation where initializing to `undefined` behaves differently than omitting the initialization, and that's when a `var` declaration occurs inside of a loop. For example:

@github-actions github-actions bot removed the rule Relates to ESLint's core rules label Apr 15, 2025
Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

Just a few small changes to the text.

Comment on lines 83 to 85
There are two situations where initializing to `undefined` behaves differently than omitting the initialization.

The first is when a `var` declaration occurs inside of a loop. For example:
Copy link
Contributor

Choose a reason for hiding this comment

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

Are we sure there are only two situations?

Suggested change
There are two situations where initializing to `undefined` behaves differently than omitting the initialization.
The first is when a `var` declaration occurs inside of a loop. For example:
There are situations where initializing to `undefined` behaves differently than omitting the initialization.
One such case is when a `var` declaration occurs inside a loop. For example:

@@ -150,3 +152,22 @@ for (i = 0; i < 10; i++) {
```

:::

The second is when a variable is redeclared using `var`. For example:
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
The second is when a variable is redeclared using `var`. For example:
Another such case is when a variable is redeclared using `var`. For example:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done!

Copy link
Member

@mdjermanovic mdjermanovic left a comment

Choose a reason for hiding this comment

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

LGTM, thanks! Leaving open for @snitin315 to verify.

@mdjermanovic mdjermanovic moved this from Implementing to Second Review Needed in Triage Apr 17, 2025
Copy link
Contributor

@snitin315 snitin315 left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@snitin315 snitin315 merged commit ca7a735 into eslint:main Apr 17, 2025
32 checks passed
@github-project-automation github-project-automation bot moved this from Second Review Needed to Complete in Triage Apr 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion documentation Relates to ESLint's documentation
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

Docs: no-undef-init rule
3 participants