Skip to content

Enhancement: [prefer-for-of] Add autofix / fix suggestions #11336

Open
@Samuel-Therrien-Beslogic

Description

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/prefer-for-of/

Description

https://typescript-eslint.io/rules/prefer-for-of/ and https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/no-for-loop.md seem to mostly overlap, but with some slight differences as noticed in #9628

I think I would prefer typescript-eslint/prefer-for-of's seemingly less aggressive approach, but unicorn/no-for-loop brings a lot of value by simply having it be autofixable.

Fail

// Caught by both
const values = [1, 2, 3]
let output = 0
for (let index = 0; index < values.length; index++) {
  output += values[index]
}

Pass

// unicorn/no-for-loop autofixes to this
const values = [1, 2, 3]
let output = 0
for (const value of values) {
  output += value
}

Additional Info

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions