eslint-plugin-vue-setup-order 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +38 -51
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
# eslint-plugin-vue-setup-order
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
ESLint plugin to enforce a consistent order of statements within the Vue 3 `<script setup>` block.
|
|
5
4
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
## 📦 Installation
|
|
5
|
+
## Installation
|
|
9
6
|
|
|
10
7
|
```bash
|
|
11
8
|
npm install -D eslint-plugin-vue-setup-order
|
|
@@ -15,7 +12,7 @@ pnpm add -D eslint-plugin-vue-setup-order
|
|
|
15
12
|
yarn add -D eslint-plugin-vue-setup-order
|
|
16
13
|
```
|
|
17
14
|
|
|
18
|
-
##
|
|
15
|
+
## Configuration
|
|
19
16
|
|
|
20
17
|
### ESLint Flat Config (ESLint 9+)
|
|
21
18
|
|
|
@@ -25,7 +22,7 @@ import vueSetupOrder from 'eslint-plugin-vue-setup-order';
|
|
|
25
22
|
|
|
26
23
|
export default [
|
|
27
24
|
vueSetupOrder.configs.flat.recommended,
|
|
28
|
-
//
|
|
25
|
+
// Or manual configuration:
|
|
29
26
|
{
|
|
30
27
|
plugins: {
|
|
31
28
|
'vue-setup-order': vueSetupOrder,
|
|
@@ -44,50 +41,50 @@ export default [
|
|
|
44
41
|
module.exports = {
|
|
45
42
|
plugins: ['vue-setup-order'],
|
|
46
43
|
extends: ['plugin:vue-setup-order/recommended'],
|
|
47
|
-
//
|
|
44
|
+
// Or manual configuration:
|
|
48
45
|
rules: {
|
|
49
46
|
'vue-setup-order/order': 'error',
|
|
50
47
|
},
|
|
51
48
|
};
|
|
52
49
|
```
|
|
53
50
|
|
|
54
|
-
##
|
|
51
|
+
## Default Order
|
|
55
52
|
|
|
56
|
-
The plugin enforces the following
|
|
53
|
+
The plugin enforces the following default sequence:
|
|
57
54
|
|
|
58
|
-
1.
|
|
59
|
-
2.
|
|
60
|
-
3.
|
|
61
|
-
4.
|
|
62
|
-
5.
|
|
63
|
-
6.
|
|
64
|
-
7.
|
|
65
|
-
8.
|
|
66
|
-
9.
|
|
67
|
-
10. Provide
|
|
55
|
+
1. **Imports**: All `import` statements.
|
|
56
|
+
2. **Type Declarations**: TypeScript `type`, `interface`, and `enum` declarations.
|
|
57
|
+
3. **Define Macros**: `defineProps`, `defineEmits`, `defineOptions`, `defineSlots`, `defineExpose`, `defineModel`, and `withDefaults`.
|
|
58
|
+
4. **Composables**: Function calls following the `useXxx` pattern (e.g., `useRouter`, `useStore`).
|
|
59
|
+
5. **Reactive State**: Vue reactivity APIs such as `ref`, `reactive`, and `shallowRef`.
|
|
60
|
+
6. **Computed Properties**: `computed` declarations.
|
|
61
|
+
7. **Watchers**: `watch` and `watchEffect` calls.
|
|
62
|
+
8. **Lifecycle Hooks**: `onMounted`, `onBeforeMount`, and other lifecycle functions.
|
|
63
|
+
9. **Functions**: Regular function declarations and arrow functions.
|
|
64
|
+
10. **Provide**: `provide` calls.
|
|
68
65
|
|
|
69
|
-
##
|
|
66
|
+
## Examples
|
|
70
67
|
|
|
71
|
-
###
|
|
68
|
+
### Incorrect
|
|
72
69
|
|
|
73
70
|
```vue
|
|
74
71
|
<script setup>
|
|
75
72
|
import { ref, computed } from 'vue';
|
|
76
73
|
|
|
77
74
|
function increment() {
|
|
78
|
-
//
|
|
75
|
+
// Error: function declared before reactive state
|
|
79
76
|
count.value++;
|
|
80
77
|
}
|
|
81
78
|
|
|
82
79
|
const count = ref(0);
|
|
83
80
|
|
|
84
|
-
onMounted(() => {}); //
|
|
81
|
+
onMounted(() => {}); // Error: lifecycle hook before computed property
|
|
85
82
|
|
|
86
83
|
const doubled = computed(() => count.value * 2);
|
|
87
84
|
</script>
|
|
88
85
|
```
|
|
89
86
|
|
|
90
|
-
###
|
|
87
|
+
### Correct
|
|
91
88
|
|
|
92
89
|
```vue
|
|
93
90
|
<script setup lang="ts">
|
|
@@ -121,11 +118,11 @@ The plugin enforces the following order in `<script setup>`:
|
|
|
121
118
|
</script>
|
|
122
119
|
```
|
|
123
120
|
|
|
124
|
-
##
|
|
121
|
+
## Options
|
|
125
122
|
|
|
126
|
-
###
|
|
123
|
+
### groupBlankLines
|
|
127
124
|
|
|
128
|
-
|
|
125
|
+
Ensures blank lines are present between different categories. Defaults to `true`.
|
|
129
126
|
|
|
130
127
|
```javascript
|
|
131
128
|
{
|
|
@@ -135,20 +132,20 @@ Add blank lines between different categories (default: `true`).
|
|
|
135
132
|
}
|
|
136
133
|
```
|
|
137
134
|
|
|
138
|
-
###
|
|
135
|
+
### order
|
|
139
136
|
|
|
140
|
-
|
|
137
|
+
Allows customization of the category sequence. Provide an array of category names to define your preferred order.
|
|
141
138
|
|
|
142
139
|
**Available categories:**
|
|
143
140
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
141
|
+
* `import`
|
|
142
|
+
* `types` (type, interface, enum)
|
|
143
|
+
* `defineProps`, `defineEmits`, `defineOptions`, `defineSlots`, `defineExpose`, `defineModel`, `withDefaults`
|
|
144
|
+
* `composable` (useXxx)
|
|
145
|
+
* `ref`, `reactive`, `computed`, `watch`, `watchEffect`
|
|
146
|
+
* `onMounted`, `onBeforeMount`, etc.
|
|
147
|
+
* `function`
|
|
148
|
+
* `provide`
|
|
152
149
|
|
|
153
150
|
**Example: Custom order**
|
|
154
151
|
|
|
@@ -173,24 +170,14 @@ Customize the order of categories. You can specify a custom array of category na
|
|
|
173
170
|
}
|
|
174
171
|
```
|
|
175
172
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
```javascript
|
|
179
|
-
{
|
|
180
|
-
'vue-setup-order/order': ['error', {
|
|
181
|
-
order: ['import', 'types', 'defineProps', 'function', 'ref', 'computed']
|
|
182
|
-
}]
|
|
183
|
-
}
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
## 🔧 Auto-fix
|
|
173
|
+
## Auto-fix
|
|
187
174
|
|
|
188
|
-
This rule supports
|
|
175
|
+
This rule supports automatic fixing. Run ESLint with the `--fix` flag to resolve ordering issues:
|
|
189
176
|
|
|
190
177
|
```bash
|
|
191
178
|
npx eslint --fix "src/**/*.vue"
|
|
192
179
|
```
|
|
193
180
|
|
|
194
|
-
##
|
|
181
|
+
## License
|
|
195
182
|
|
|
196
183
|
MIT
|