eslint rule suggestion: report an Index that the system's own query already covers

オープン
#235 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
45/100
issue の種類
機能追加
明瞭さ
おおむね明確
活発さ
活発
技術スタック
eslint, typescript
領域
tooling

調査の方向性

Start by reading the existing ESLint plugin and rule entry points; the issue notes that the plugin already sees system declarations and lookups. Check related issues #233 and #234 for context, then add tests for the listed report and non-report cases. Done means the rule reports only qualifying indexes at Index.create and leaves the specified legitimate indexes alone.

索引モデルが issue の本文から書いたものです。

説明

Summary

Suggestion for the planned ESLint rule: report an Index that a plain query already covers. An index is kept up to date on every structural change and costs memory, so defining one for something a system can read with components: { with, not } is waste, and it is easy to write by habit.

Case

A system that despawns every entity carrying a tag was written with an index:

const transients = Index.create({ key: [], components: { with: [frameTransient] } });

export const endFrame = System.create({ lookup: { transients: { index: transients } } }, ({ commands, lookup }) => {
    const all = lookup.transients();
    for (let i = 0; i < all.length; i++) commands.despawn(all.at(i).entity);
});

A row system reads the same entities with nothing to maintain:

export const endFrame = System.create({ components: { with: [frameTransient] } }, (row, { commands }) => {
    commands.despawn(row.entity);
});

Rule

Report an index when all of these hold:

  • it has key: [] and is not unique,
  • exactly one system uses it, through a lookup,
  • the index's with (and not) is covered by that system's own components declaration, so the system already matches those entities,
  • the body only iterates the lookup's rows (for (i < rows.length) rows.at(i)), with no keyed access.

Message: "this index is replaceable by the system's own components query; make it a row system" (or the equivalent for per-run systems), pointing at the Index.create.

What it must not report

An all-rows index (key: []) is legitimate when:

  • several systems read it,
  • a per-run system needs the whole set before it acts (for example, "is there any request for X?" across all rows), which a row system, called once per row, can't express,
  • it is read from a system whose own declaration doesn't match those entities (a different archetype).

An index with a key (a keyed or unique lookup) is never reported.

Notes

  • It could also be a compiler warning, since the plugin already sees every system's declaration and lookups, but a lint rule fits better: the first check is a style judgment and the fix depends on the body.
  • Related: https://github.com/adobe/data/issues/234 (the widened-access fallback) and https://github.com/adobe/data/issues/233 (describing inferred access), both about making what the build infers visible.
主要言語
TypeScript
スター
12
フォーク
8
平均マージ
11時間 2分
マージ済み PR(30日)
23

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

adobe/data のほかの issue

adobe/data の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。