vue/max-lines-per-block
限制每个 SFC 块的行数。
| 默认严重程度 | 预设 | 自动修复 | 选项 |
|---|---|---|---|
warning |
无 | 不支持 | 无 |
适用范围:Vue SFC 模板和代码块,包括规则所需的脚本上下文。
错误示例
template 块的行数超过配置的上限。
<script setup lang="ts">
const label = "a";
</script>
<template>
<ul>
<li>{{ label }}</li>
<li>{{ label }}</li>
<li>{{ label }}</li>
<li>{{ label }}</li>
<li>{{ label }}</li>
<li>{{ label }}</li>
<li>{{ label }}</li>
<li>{{ label }}</li>
<li>{{ label }}</li>
<li>{{ label }}</li>
</ul>
</template>
正确示例
template 块的行数保持在配置的上限以内。
<script setup lang="ts">
const label = "a";
</script>
<template>
<p>{{ label }}</p>
</template>
配置(Vite+)
import { defineConfig } from "@vizejs/vite-plugin/vite-plus";
export default defineConfig({}).withVue({
linter: {
"preset": "incremental",
"rules": {
"vue/max-lines-per-block": "warn"
},
"ruleOptions": {
"vue/max-lines-per-block": {
"template": 10
}
}
},
});
然后运行 vp run lint。