Skip to content
This repository has been archived by the owner on Aug 31, 2023. It is now read-only.

useLiteralKeys #3889

Closed
Tracked by #3953 ...
ematipico opened this issue Nov 28, 2022 · 8 comments · Fixed by #4358
Closed
Tracked by #3953 ...

useLiteralKeys #3889

ematipico opened this issue Nov 28, 2022 · 8 comments · Fixed by #4358
Assignees
Labels
A-Linter Area: linter I-Normal Implementation: normal understanding of the tool and awareness

Comments

@ematipico
Copy link
Contributor

ematipico commented Nov 28, 2022

  1. no-literal-computed-keys (autofix e.g. ["a"] to a, safe)

cc @jeysal

@ematipico ematipico mentioned this issue Nov 28, 2022
29 tasks
@notmd
Copy link
Contributor

notmd commented Nov 29, 2022

@ematipico I would like to take this one.

@notmd
Copy link
Contributor

notmd commented Nov 29, 2022

I don't really understand the rule. The issue title seems like https://eslint.org/docs/latest/rules/no-useless-computed-key. But the fix suggestion is like https://eslint.org/docs/latest/rules/dot-notation. We didn't have both of these rules yet.

@ematipico
Copy link
Contributor Author

Sorry for the lack of context. In this issue #3731 there's more information about why we decided to split the ESLint rule into three rules.

They are more specialised, allowing us to give more control and put them in different groups.

@MichaReiser
Copy link
Contributor

Naming. How about noComputedLiteralKeys (or MemberNames) or useLiteralKeys?

@ematipico
Copy link
Contributor Author

Naming. How about noComputedLiteralKeys (or MemberNames) or useLiteralKeys?

I like these names.

I wonder if we should narrow down the name to include "string", I don't think the rule will be applied to numerical literals, for example.

@jeysal
Copy link
Contributor

jeysal commented Nov 29, 2022

I wonder if we should narrow down the name to include "string", I don't think the rule will be applied to numerical literals, for example.

I think it should actually! Any numeric literal should be valid directly as a literal property name (even weird stuff like { .1: 42 } works), so we should also unwrap those out of a computed property name.

image

Boolean and null literals too (trivial)

@ematipico ematipico added the I-Normal Implementation: normal understanding of the tool and awareness label Dec 6, 2022
@ematipico ematipico changed the title noLiteralComputedKeys noComputedLiteralKeys Dec 6, 2022
@ematipico ematipico changed the title noComputedLiteralKeys useLiteralKeys Dec 6, 2022
@github-actions
Copy link

👋 @rome/staff please triage this issue by adding one of the following labels: S-Bug: confirmed, S-Planned , S-Wishlist or umbrella

@jpike88
Copy link

jpike88 commented Jan 24, 2023

this is a super important one, I'd even suggest putting it in the recommended set. It's super dangerous to allow people to accidentally reference a non-literal key due to it sidestepping type checks.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
A-Linter Area: linter I-Normal Implementation: normal understanding of the tool and awareness
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

6 participants