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

Enhancement: [no-magic-numbers] Allow for readonly number[] #8102

Closed
4 tasks done
Samuel-Therrien-Beslogic opened this issue Dec 20, 2023 · 3 comments
Closed
4 tasks done
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin wontfix This will not be worked on

Comments

@Samuel-Therrien-Beslogic

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/no-magic-numbers/

Description

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
}

Additional Info

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]
@Samuel-Therrien-Beslogic Samuel-Therrien-Beslogic added enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin triage Waiting for maintainers to take a look labels Dec 20, 2023
@bradzacher
Copy link
Member

As this is a stylistic extension rule - we aren't looking to deviate from the base rules enforced style. Instead the goal is to augment the existing style with support for TS features that align with the style.

The base rule has no option to ignore arrays - so we shall not add one to ingore arrays - readonly or otherwise.

@bradzacher bradzacher closed this as not planned Won't fix, can't repro, duplicate, stale Dec 20, 2023
@bradzacher bradzacher added wontfix This will not be worked on and removed triage Waiting for maintainers to take a look labels Dec 20, 2023
@Samuel-Therrien-Beslogic
Copy link
Author

Did not realize it was considered a stylistic rule (which I know are "no longer developed"). Thanks for your answer.

@bradzacher
Copy link
Member

It's a stylistic rule - which you're right are considered feature complete and thus feature frozen by both us an eslint core.

But it's not considered a formatting rule - hence it has not been deprecated/removed from eslint core (and thus we retain our extension version).

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 28, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement: plugin rule option New rule option for an existing eslint-plugin rule package: eslint-plugin Issues related to @typescript-eslint/eslint-plugin wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants