tools icon indicating copy to clipboard operation
tools copied to clipboard

`useLiteralKeys`

Open ematipico opened this issue 2 years ago • 6 comments

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

cc @jeysal

ematipico avatar Nov 28 '22 16:11 ematipico

@ematipico I would like to take this one.

notmd avatar Nov 29 '22 07:11 notmd

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.

notmd avatar Nov 29 '22 07:11 notmd

Sorry for the lack of context. In this issue https://github.com/rome/tools/issues/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.

ematipico avatar Nov 29 '22 10:11 ematipico

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

MichaReiser avatar Nov 29 '22 12:11 MichaReiser

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.

ematipico avatar Nov 29 '22 13:11 ematipico

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)

jeysal avatar Nov 29 '22 19:11 jeysal

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

github-actions[bot] avatar Dec 23 '22 12:12 github-actions[bot]

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.

jpike88 avatar Jan 24 '23 09:01 jpike88