ESLint plugins: pinia
Stores in Pinia are the foundation of any Vue application architecture. However, the larger the project, the more challenging it becomes to ensure that all defineStore
are implemented consistently, there are no duplicate ids, and properties are explicitly exported.
eslint-plugin-pinia helps automate these checks: once connected to ESLint, the plugin will find potential errors, inconsistent styles, and architectural inconsistencies in your stores
.
Installation
bash
npm install --save-dev eslint-plugin-pinia
js
// eslint.config.js
import piniaPlugin from "eslint-plugin-pinia";
export default [
// ...
piniaPlugin.configs["all-flat"]
];
What does it check?
The rules cover the most common errors:
never-export-initialized-store
— prohibits exporting the result ofdefineStore()
, only the function itself.no-duplicate-store-ids
— checks the uniqueness of the id for alldefineStore
.no-return-global-properties
— prohibits returninginject
,useRouter
,useRoute
directly from the store.no-store-to-refs-in-store
—storeToRefs()
should not be used insidedefineStore
.prefer-single-store-per-file
— one file should contain one store. Disabled by defaultprefer-use-store-naming-convention
— store names must begin withuse
:useCartStore
,useUserStore
, etc. Disabled by defaultrequire-setup-store-properties-export
— allstate
properties in the setup store must be exported.
Summary
If you use Pinia, this small plugin will help you avoid many architectural problems while writing code. It is especially useful for teamwork: stores will be formatted consistently, code will become predictable, and reviews will be faster and easier.