Skip to content

@rotki/composable-return-readonly

Require returned refs from composables to be wrapped with readonly()

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

📖 Rule Details

This rule requires that writable reactive variables (ref, shallowRef) returned from composables are wrapped with readonly() to prevent consumers from mutating internal state.

computed() refs are excluded because they are already readonly by design — wrapping them with readonly() is unnecessary. The rule will flag unnecessary readonly() usage on computed refs.

Refs that are intentionally returned writable (for example, to bind with v-model) can be exempted by naming convention via the writablePrefixes option, instead of disabling the rule per line.

🔧 Options

json
{
  "@rotki/composable-return-readonly": [
    "error",
    { "autofix": false, "writablePrefixes": ["model"] }
  ]
}

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.

writablePrefixes

  • Type: string[]
  • Default: ["model"]

Returned variables whose name starts with one of these prefixes are exempt from the readonly() requirement. Use this for refs you intentionally expose as writable — for example, a ref meant to be bound with v-model — so you don't need a per-line eslint-disable.

Matching requires a strict camelCase boundary: the prefix must be the entire name or be followed by an uppercase letter. So model exempts model and modelValue, but not models.

Providing this option replaces the default, so include the default value if you want to keep it alongside additions, e.g. ["model", "writable"].

🚀 Version

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

🔍 Implementation