Skip to content

prefer-single-world-query

Combines consecutive world.get() calls, and some world.has() calls, that query the same entity from the same world.

This 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.

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);
  • let and var declarations
  • 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 ||