sindresorhus/eslint-plugin-unicorn

`unicorn/prefer-at` incorrectly fixes object property key lookup

クローズ

#2,229 opened on 2023/12/12

 (0 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (468 件のフォーク)user submission
bughelp wantedtypes

Repository metrics

Stars
 (5,022 個のスター)
PR merge metrics
 (平均マージ 4h 30m) (30d で 26 merged PRs)

説明

for the following code:

const x = {
  1: 1,
  a: 2,
};

const y = x['a']; // can also be written as x.a 
const z = x[1];

the prefer-at rule will suggest and autofix const z = x[1]; to const z = x.at(1); - this is an object and therefore does not have the .at property available, while the x['a'] accessor remains unchanged.

While in TypeScript and Javascript, object property keys are supposed to always be strings, we cannot always assume that they are.

I believe that the rule should check whether you are accessing on an object and therefore not suggest the fix

コントリビューターガイド