prefer-single-world-query
Combines consecutive world.get() calls, and some world.has() calls, that query the same entity from the same world.
Rule details Suggestion
Section titled “Rule details ”SuggestionThis rule looks for consecutive const declarations that call world.get(entity, Component) or
world.has(entity, Component). It only groups calls when the world expression text matches, the entity expression text
matches, and there is nothing between the declarations except whitespace or semicolons.
For world.get(), any matching run of two or more declarations is reported.
For world.has(), the rule is narrower. It only reports when every declared boolean is later used directly inside an
&& expression, such as an if, while, or ternary condition.
Examples
Section titled “Examples” Incorrect
const position = world.get(entity, Position);const velocity = world.get(entity, Velocity);
const hasHealth = world.has(entity, Health);const hasMana = world.has(entity, Mana);if (hasHealth && hasMana) { doSomething();} Correct
const [position, velocity] = world.get(entity, Position, Velocity);
const hasAll = world.has(entity, Health, Mana);if (hasAll) { doSomething();}
const health = world.get(player, Health);logHealth(health);const mana = world.get(player, Mana);What gets skipped
Section titled “What gets skipped”letandvardeclarations- destructuring declarations like
const [value] = world.get(...) - computed access like
world["get"](...) - calls with extra arguments
world.has()values that are used separately or with||
Related rules
Section titled “Related rules” prefer-pattern-replacements Handles configurable constructor and method rewrites
no-identity-map Removes work that does not change the result