Skip to content

@rotki/composable-input-flexibility

Prefer MaybeRefOrGetter over Ref for composable parameters

  • ✒️️ The --fix option on the command line can automatically fix some of the problems reported by this rule.

📖 Rule Details

This rule reports Ref<T> type annotations on composable parameters and suggests using MaybeRefOrGetter<T> for greater input flexibility.

✅ Written-back parameters are exempt

A MaybeRefOrGetter<T> may be a plain getter, which is not writable. So a parameter that the composable writes back to must stay a Ref<T>, and the rule does not flag it. A parameter is considered written when it is reassigned via set(param, …), param.value = … (including compound assignments), or an update expression such as param.value++.

ts
/* eslint @rotki/composable-input-flexibility: "error" */

// ✓ GOOD — `state` is written back, so a Ref is required and it is not flagged
function useToggle(state: Ref<boolean>) {
  function toggle() {
    set(state, !get(state));
  }
  return { toggle };
}

This means no inline eslint-disable is needed for writable parameters: only genuinely read-only Ref<T> parameters — where a getter would work just as well — are reported.

🔧 Options

json
{
  "@rotki/composable-input-flexibility": ["error", { "autofix": false }]
}

autofix

  • Type: boolean
  • Default: false

When true, enables auto-fix via the --fix CLI flag. When false (default), the fix is available only as an editor suggestion.

🚀 Version

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

🔍 Implementation