Code Monkey home page Code Monkey logo

eslint-plugin-pinia's Introduction

eslint-plugin-pinia

npm test

Eslint plugin that enforces some best practices for writing pinia stores

Installation

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-pinia:

npm install eslint-plugin-pinia --save-dev

Usage

Add pinia to the plugins section of your .eslintrc or eslint.config.js configuration file. You can omit the eslint-plugin- prefix:

// .eslintrc [Legacy Config]
{
  "plugins": ["pinia"]
}
// eslint.config.js
import pinia from 'eslint-plugin-pinia'

export default [
  plugins: {
    pinia
  }
]

Rule Configuration

Then configure the rules you want to use under the rules section.

// .eslintrc [Legacy Config]
{
  "rules": {
    "pinia/require-export-define-store": [
      "warn"
    ]
  }
}
// eslint.config.js
import pinia from 'eslint-plugin-pinia'

export default [
  {
    plugin: {
      pinia
    },
    rules: {
      "pinia/require-export-define-store": ["warn"]
    }
  }
]

Recommended

To use the recommended configuration, extend it in your .eslintrc or eslint.config.js file:

// .eslintrc [Legacy Config]
{
  "extends": ["plugin:pinia/recommended"]
}
// eslint.config.js
import pinia from 'eslint-plugin-pinia'

export default [
  pinia.configs["recommended-flat"],
]

All recommend rules will be set to error by default. You can however disable some rules by setting turning them off in your configuration file or by setting them to warn in your configuration file.

all rules

To use the all configuration, extend it in your .eslintrc or eslint.config.js file:

// .eslintrc [Legacy Config]
{
  "extends": ["plugin:pinia/all"]
}
// eslint.config.js
import pinia from 'eslint-plugin-pinia'

export default [
  pinia.configs["all-flat"],
]

Rules

๐Ÿ’ผ Configurations enabled in.
โš ๏ธ Configurations set to warn in.
๐Ÿšซ Configurations disabled in.
๐ŸŒ Set in the all configuration.
๐ŸŒ Set in the all-flat configuration.
โœ… Set in the recommended configuration.
โœ… Set in the recommended-flat configuration.

Nameย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย ย  Description ๐Ÿ’ผ โš ๏ธ ๐Ÿšซ
never-export-initialized-store Never export an initialized named or default store. โœ… โœ… ๐ŸŒ ๐ŸŒ
no-duplicate-store-ids Disallow duplicate store ids. โœ… โœ… ๐ŸŒ ๐ŸŒ
no-return-global-properties Disallows returning globally provided properties from Pinia stores. โœ… โœ… ๐ŸŒ ๐ŸŒ
no-store-to-refs-in-store Disallow use of storeToRefs inside defineStore โœ… โœ… ๐ŸŒ ๐ŸŒ
prefer-single-store-per-file Encourages defining each store in a separate file. ๐ŸŒ ๐ŸŒ
prefer-use-store-naming-convention Enforces the convention of naming stores with the prefix use followed by the store name. ๐ŸŒ ๐ŸŒ โœ… โœ…
require-setup-store-properties-export In setup stores all state properties must be exported. โœ… โœ… ๐ŸŒ ๐ŸŒ

Credits

Licence

MIT Licence ยฉ 2024

Contributing

Please check the Contributing file.

This project exists thanks to all the people who contribute ๐Ÿ˜!

eslint-plugin-pinia's People

Contributors

dependabot[bot] avatar lisilinhart avatar 9romise avatar pjfontillas avatar

Stargazers

n0099 avatar Pavel Shakhov avatar Andrew Kazakov avatar Andrey Masiero avatar  avatar Akiho Nagao avatar Chantouch Sek avatar Seiya KONNO avatar kazuya kawaguchi avatar Matt avatar Muhammad Ubaid Raza avatar Marko ลฝuniฤ‡ avatar Wayne Zhang avatar Bryan Hyshka avatar Samuel Burkhard avatar  avatar Shhadi Masarwa avatar Guillaume Dumoulin avatar Alex Liu avatar  avatar Andrew Chou avatar Eduardo San Martin Morote avatar Jakob Miksch avatar

Watchers

 avatar  avatar

eslint-plugin-pinia's Issues

Have a rule to warn when creating a computed property that receives arguments

Would be awesome to have a linting rule to generate a warning when trying to use create a computed property with arguments , as you will take a performance hit by no catching the results and recalculating every time.

As per the documentation:

export const useStore = defineStore('main', {
  getters: {
    getActiveUserById(state) {
      const activeUsers = state.users.filter((user) => user.active)
      return (userId) => activeUsers.find((user) => user.id === userId)
    },
  },
})

When doing this, getters are no longer cached. They are simply functions you invoke.

Taken from: https://pinia.vuejs.org/core-concepts/getters.html#Passing-arguments-to-getters

support flat style configration

ESLint has provided flat config since v9.
https://eslint.org/docs/latest/use/configure/configuration-files

And in v10 the classical config style will be removed.

It would be nice if it could be easily set up as follows:

import vue from 'eslint-plugin-vue'
import pinia from 'eslint-plugin-pinia'

export default [
  ...vue.configs['flat/recommended'],
  ...pinia.configs.recommended,

  // Currently it can be configured as follows
  // {
  //   files: ['**/*.ts'],
  //   plugins: { pinia },
  //   rules: {
  //     ...pinia.configs.recommended.rules,
  //   },
  // },
]

Since eslint provides an API compatibility list, I think it would be possible to provide rules that work before v9.
https://eslint.org/blog/2023/09/preparing-custom-rules-eslint-v9/

if it were supported it would be great, because this plugin could be used for projects that have not yet been migrated that also support it.

The automated release is failing ๐Ÿšจ

๐Ÿšจ The automated release from the main branch failed. ๐Ÿšจ

I recommend you give this issue a high priority, so other packages depending on you can benefit from your bug fixes and new features again.

You can find below the list of errors reported by semantic-release. Each one of them has to be resolved in order to automatically publish your package. Iโ€™m sure you can fix this ๐Ÿ’ช.

Errors are usually caused by a misconfiguration or an authentication problem. With each error reported below you will find explanation and guidance to help you to resolve it.

Once all the errors are resolved, semantic-release will release your package the next time you push a commit to the main branch. You can also manually restart the failed CI job that runs semantic-release.

If you are not sure how to resolve this, here are some links that can help you:

If those donโ€™t help, or if this issue is reporting something you think isnโ€™t right, you can always ask the humans behind semantic-release.


Invalid npm token.

The npm token configured in the NPM_TOKEN environment variable must be a valid token allowing to publish to the registry https://registry.npmjs.org/.

If you are using Two Factor Authentication for your account, set its level to "Authorization only" in your account settings. semantic-release cannot publish with the default "
Authorization and writes" level.

Please make sure to set the NPM_TOKEN environment variable in your CI with the exact value of the npm token.


Good luck with your project โœจ

Your semantic-release bot ๐Ÿ“ฆ๐Ÿš€

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.