vue/sfc-element-order
Enforce consistent order of SFC top-level elements.
| Default severity | Presets | Automatic fix | Options |
|---|---|---|---|
warning |
happy-path, nuxt, ecosystem, opinionated |
No | Rule options |
Applies to: Vue SFC templates and blocks, with script context where the rule requires it.
Bad
The style block precedes the script block, contrary to the configured SFC block order.
<style scoped>
.panel {
color: red;
}
</style>
<script setup lang="ts">
const label = "Save";
</script>
Good
The blocks follow script → template → style. Projects can choose a different order through this rule's typed option.
<script setup lang="ts">
const label = "Save";
</script>
<template>
<p>{{ label }}</p>
</template>
<style scoped>
p {
color: red;
}
</style>
Configuration (Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/sfc-element-order": "warn"
}
},
});
Then run vp run lint.