Skip to content

Conversation

snitin315
Copy link
Contributor

@snitin315 snitin315 commented Mar 22, 2025

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)

Refs #19173

It adds support for TypeScript types in no-loop-func.

/*eslint no-loop-func: "error"*/

type MyType = 1;
let someArray: MyType[] = [];
for (let i = 0; i < 10; i += 1) {
    someArray = someArray.filter((item: MyType) => !!item);
}

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

  • The rule didn't required any code changes 😄

@github-project-automation github-project-automation bot moved this to Needs Triage in Triage Mar 22, 2025
@eslint-github-bot eslint-github-bot bot added the feature This change adds a new feature to ESLint label Mar 22, 2025
Copy link

netlify bot commented Mar 22, 2025

Deploy Preview for docs-eslint ready!

Name Link
🔨 Latest commit 1e74207
🔍 Latest deploy log https://app.netlify.com/sites/docs-eslint/deploys/67ea3735e0e238000879191c
😎 Deploy Preview https://deploy-preview-19559--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.

@snitin315 snitin315 marked this pull request as ready for review March 22, 2025 18:05
@snitin315 snitin315 requested a review from a team as a code owner March 22, 2025 18:05
@github-actions github-actions bot added the rule Relates to ESLint's core rules label Mar 22, 2025
`,
],
invalid: [
// Invalid TS code
Copy link
Contributor

Choose a reason for hiding this comment

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

@snitin315 did you mean to push a commit with tests here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah added in 6337f87

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, I just noticed that in error message, we repeat the same variable name in few cases - Function declared in a loop contains unsafe references to variable(s) 'i', 'i'.

Is this expected, or should we print i just once?

@mdjermanovic @JoshuaKGoldberg ^

Copy link
Contributor

Choose a reason for hiding this comment

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

Ha, nice catch. I don't know if it's expected but my personal intuition is that it's a bug.

Copy link
Contributor

Choose a reason for hiding this comment

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

For tracking: #19586 -> #19595 ✔️

Copy link
Member

Choose a reason for hiding this comment

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

Are there really no changes needed in the code? Asking because @typescript-eslint/no-loop-func isn't marked as deprecated, and the implementation additionally checks isTypeReference attribute.

Copy link
Contributor Author

@snitin315 snitin315 Mar 27, 2025

Choose a reason for hiding this comment

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

Hmm, there might be some missing test cases in typescrip-eslint. Let me check on this.

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 removed this check and still all tests passed in typescript-eslint codebase, @JoshuaKGoldberg This might be dead code. Also I have tests all test cases from the typescript-eslint repo all are passing with this rule's current implementation in js.

Added few more test cases in d1c3bd5

Copy link
Contributor

Choose a reason for hiding this comment

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

Indeed, it does look like nothing is necessary. I filed typescript-eslint/typescript-eslint#11015 to double-check on the typescript-eslint side.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like the problem for which the extension rule was added (typescript-eslint/typescript-eslint#2448 - false positives on unresolved type references) has been fixed by 42faa17 in the core rule.

@nzakas nzakas moved this from Needs Triage to Implementing in Triage Mar 27, 2025
@snitin315 snitin315 added the accepted There is consensus among the team that this change meets the criteria for inclusion label Mar 27, 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.

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

Copy link
Contributor

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

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

Nice, glad this really didn't need any source logic changes! 👏

@mdjermanovic mdjermanovic merged commit 9535cff into main Apr 7, 2025
31 checks passed
@mdjermanovic mdjermanovic deleted the ts/no-loop-func branch April 7, 2025 20:00
@github-project-automation github-project-automation bot moved this from Implementing to Complete in Triage Apr 7, 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 feature This change adds a new feature to ESLint rule Relates to ESLint's core rules
Projects
Status: Complete
Development

Successfully merging this pull request may close these issues.

3 participants