Skip to content

@rotki/no-conditional-empty-object-spread

Disallow object spreads that conditionally spread nothing to omit a property

📖 Rule Details

...(cursor ? { cursor } : {}) decides whether a property exists inside an expression. The reader has to evaluate the ternary to know the shape of the object, the empty branch carries no meaning of its own, and the pattern nests badly once two or three of them stack up in one literal.

Both shapes are reported, because both omit by spreading nothing:

  • the ternary, where one branch is an empty object literal
  • ...(cursor && { cursor }), where the false branch spreads false, a legal no-op

Only spreads in an object literal are reported. [...(enabled ? items : [])] is an array spread and is left alone, as is a ternary between two non-empty objects, where both branches carry properties and the shape is stated either way.

No autofix: the replacement depends on what the object is for. Usually it is a mutable base plus a guarded assignment, or a small builder function.

⚙️ Options

Nothing.

🚀 Version

This rule was introduced in @rotki/eslint-plugin v1.6.0

🔍 Implementation