|
1 |
| -# eslint-plugin-vue-sort-components |
2 |
| -A plugin for ESLint to keep order of component names |
| 1 | +# `eslint-plugin-vue-sort-components` |
| 2 | + |
| 3 | +A plugin for ESLint to keep order of component names. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
| 7 | +```shell |
| 8 | +$ npm install --save-dev eslint @jay-es/eslint-plugin-vue-sort-components |
| 9 | +``` |
| 10 | + |
| 11 | +or |
| 12 | + |
| 13 | +```shell |
| 14 | +$ yarn add -dev @jay-es/eslint-plugin-vue-sort-components |
| 15 | +``` |
| 16 | + |
| 17 | +## Usage |
| 18 | + |
| 19 | +Add `plugin:@jay-es/vue-sort-components/recommended` to the extends section of your `.eslintrc` configuration file. |
| 20 | + |
| 21 | +```js |
| 22 | +{ |
| 23 | + "extends": [ |
| 24 | + // ... |
| 25 | + "plugin:@jay-es/vue-sort-components/recommended" |
| 26 | + ] |
| 27 | +} |
| 28 | +``` |
| 29 | + |
| 30 | +### Custom Configuration |
| 31 | + |
| 32 | +Add `@jay-es/vue-sort-components` to the plugins section of your `.eslintrc` configuration file. |
| 33 | + |
| 34 | +```js |
| 35 | +{ |
| 36 | + "plugins": ["@jay-es/vue-sort-components"] |
| 37 | +} |
| 38 | +``` |
| 39 | + |
| 40 | +Then configure the rule under the rules section. |
| 41 | + |
| 42 | +```js |
| 43 | +{ |
| 44 | + "rules": { |
| 45 | + "@jay-es/vue-sort-components/vue-sort-components": "error" |
| 46 | + } |
| 47 | +} |
| 48 | +``` |
| 49 | + |
| 50 | +## Rule Details |
| 51 | + |
| 52 | +This rule checks property definitions of object expressions named `components` and verifies that all keys are sorted alphabetically. |
| 53 | + |
| 54 | +Examples of **incorrect** code for this rule: |
| 55 | + |
| 56 | +```js |
| 57 | +export default defineComponent({ |
| 58 | + components: { Foo, Bar, Baz }, |
| 59 | +}); |
| 60 | + |
| 61 | +// not only in Vue-specific context |
| 62 | +const myObject = { |
| 63 | + components: { Foo, Bar, Baz }, |
| 64 | +}; |
| 65 | +``` |
| 66 | + |
| 67 | +Examples of **correct** code for this rule: |
| 68 | + |
| 69 | +```js |
| 70 | +export default defineComponent({ |
| 71 | + components: { Bar, Baz, Foo }, |
| 72 | +}); |
| 73 | + |
| 74 | +// not only in Vue-specific context |
| 75 | +const myObject = { |
| 76 | + components: { Bar, Baz, Foo }, |
| 77 | +}; |
| 78 | +``` |
0 commit comments