This ESLint plugin provides a set of rules specifically designed to enforce best practices and prevent common pitfalls when working with Vue 3 composables and lifecycle hooks. It ensures that composable functions (prefixed with `use`) and lifecycle hook calls (like `onMounted`, `onBeforeUnmount`, etc.) are correctly placed within `setup()` functions, other composables, or Vue's `<script setup>` block. The plugin, currently at version 1.0.0, aims to help developers maintain proper reactivity contexts and avoid issues like calling hooks or composables after `await` expressions in incorrect scopes. It supports both modern ESLint flat configurations (`eslint.config.js`) and legacy `.eslintrc` formats, providing flexibility for different project setups. Its release cadence is likely tied to the evolving best practices for Vue composables, offering focused linting compared to general Vue ESLint plugins.
npm install eslint-plugin-vue-composableVerified import paths — ran on the pinned version, not inferred.
Demonstrates how to configure `eslint-plugin-vue-composable` using the modern ESLint flat configuration (`eslint.config.js`), including how to apply recommended rules and override specific rule severities.
Ensure composables and lifecycle hooks are called directly within `setup()`, another composable, or within `<script setup>` before any `await` expressions, unless specifically supported by `<script setup>` behavior.
Choose either the legacy `.eslintrc` or the modern `eslint.config.js` format and follow the corresponding installation instructions. Do not attempt to use both simultaneously or combine their configuration syntaxes.
Refactor your code to ensure that composables and lifecycle hooks are only invoked from `setup()`, within other composable functions, or directly in `<script setup>`.
Move the composable call before the `await` expression, or refactor the code to use `<script setup>` if suitable for async operations, or ensure the call is within a valid composable context.
Ensure all lifecycle hook calls are made before any `await` expressions within `setup()` or other composables, or leverage `<script setup>`'s async capabilities where appropriate.
Refactor the calling function to be a composable (start its name with `use`) or move the composable call into `setup()` or an existing composable.