🚫 This rule is disabled in the following configs: 🌐 all
, 🌐 all-flat
.
Here's the documentation for the prefer-single-store-per-file
rule:
This rule encourages defining each store in a separate file. Mixing multiple store definitions in a single file can lead to confusion and make the code harder to maintain.
❌ Examples of incorrect code for this rule:
// stores.js
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
return { count }
})
export const useTodoStore = defineStore('todo', () => {
const todos = ref([])
return { todos }
})
✅ Examples of correct code for this rule:
// counter.js
import { defineStore } from 'pinia'
export const useCounterStore = defineStore('counter', () => {
const count = ref(0)
return { count }
})
// todo.js
import { defineStore } from 'pinia'
export const useTodoStore = defineStore('todo', () => {
const todos = ref([])
return { todos }
})
Separating each store into its own file enhances code organization and readability, making it easier to understand and maintain.