Skip to content
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

Feature Request: Extending @typescript-eslint/no-magic-numbers to allow for readonly number[] #238

Closed
3 of 4 tasks
Samuel-Therrien-Beslogic opened this issue Dec 20, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@Samuel-Therrien-Beslogic

Clear and concise description of the problem

There's a use case that comes up once in a while to define "magic" numbers in an array that itself is meant to be used as a constant.

Suggested solution

Copied from typescript-eslint/typescript-eslint#8102 . Thoughts on allowing (can be locked behind an option) the following?

Fail

const DEFAULT_PAGE_LENGTH = [5, 10, 25, 100]

class MyCLass {
  readonly DEFAULT_PAGE_LENGTH = [5, 10, 25, 100]
}

let DEFAULT_PAGE_LENGTH = [5, 10, 25, 100] as const

class MyCLass {
  DEFAULT_PAGE_LENGTH = [5, 10, 25, 100] as const
}

Pass

const DEFAULT_PAGE_LENGTH = [5, 10, 25, 100] as const

class MyCLass {
  readonly DEFAULT_PAGE_LENGTH = [5, 10, 25, 100] as const
}

Alternative

The alternative to a eslint-disable comment really isn't preferable and really verbose:

const STEP_1 = 5
const STEP_2 = 10
const STEP_3 = 25
const STEP_4 = 10
const DEFAULT_PAGE_LENGTH = [STEP_1 , STEP_2 , STEP_3 , STEP_4]

Additional context

No response

Validations

Contributes

  • If this feature request is accepted, I am willing to submit a PR to fix this issue
@Samuel-Therrien-Beslogic Samuel-Therrien-Beslogic added the enhancement New feature or request label Dec 20, 2023
@antfu
Copy link
Member

antfu commented Dec 27, 2023

Well, no-magic-number does not seem to be part of this project.

@antfu
Copy link
Member

antfu commented Dec 27, 2023

As stated in #26 (comment), we don't have a plan to migrate rules if eslint/ts-eslint teams are not deprecating them. Close if for now.

@Martinspire
Copy link

I've added the request to deprecate the issue since I also like to see this being a feature of this rule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants