Skip to content

[no-magic-numbers] False positive with array/tuple type index access #4780

@davecardwell

Description

@davecardwell
  • I have tried restarting my IDE and the issue persists.
  • I have updated to the latest version of the packages.
  • I have read the FAQ and my problem is not listed.

Repro

{
  "rules": {
    "@typescript-eslint/no-magic-numbers": [
      "error",
      { "ignoreArrayIndexes": true }
    ],
  }
}
type Foo = ["bar", "baz"];
function foo(bar: string, baz: number) {}

// No magic number: 1. eslint(@typescript-eslint/no-magic-numbers)
type Oof1 = Foo[1];

// No magic number: 1. eslint(@typescript-eslint/no-magic-numbers)
type Oof2 = Parameters<typeof foo>[1];

Expected Result

I expect the array index access to be ignored.

Actual Result

No magic number: 1. eslint(@typescript-eslint/no-magic-numbers)

Additional Info

An alternative would be to add an additional option for this if you don’t think it should be covered under “ignoreArrayIndexes”.

Versions

package version
@typescript-eslint/eslint-plugin 5.17.0
@typescript-eslint/parser 5.17.0
TypeScript 4.6.3
ESLint 8.12.0
node 17.8.0

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

      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