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

    enhancement: plugin rule optionNew rule option for an existing eslint-plugin rulepackage: eslint-pluginIssues related to @typescript-eslint/eslint-plugintriageWaiting for team members to take a look

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      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