<template lang="pug">에서 vue/* 규칙을 실행하고, eslint --fix로 Pug를 포맷하세요. 모든 fix는 적용되기 전에 검사를 거치므로 템플릿이 온전하게 유지됩니다.
npm i -D eslint-plugin-pug-vue<template lang="pug">div.card(·class="shadow"·,·:title·=·"title"·)····h2(·v-if='title'·)·{{·title·}}····input(v-model="name"·,·type='text'·disabled)/</template>vue/* 규칙 eslint-plugin-vue 규칙이 Pug 템플릿에서 기존과 같은 이름과 옵션으로 동작합니다. 누락된 key, 사용하지 않는 변수, 속성 순서, deprecated 구문 등을 잡아냅니다. Pug에서 동작할 수 없는 소수의 규칙은 꺼지거나 Pug 템플릿 안에서만 무시되므로, HTML 템플릿은 계속 검사됩니다.
<template lang="pug">
ul
li(v-for="todo in todos") {{ todo.title }}
</template>3:3 error Elements in iteration expect to have 'v-bind:key' directives vue/require-v-for-keyeslint --fix로 포맷하기 작은 vue-pug/* 규칙 열두 개가 Pug 자체를 포맷합니다. 들여쓰기, 속성 블록의 공백, 쉼표, 따옴표, 줄바꿈, 그리고 .class / #id 축약 표기를 다룹니다. 각 규칙에는 옵션이 있고 원하는 규칙은 언제든 끌 수 있습니다. Prettier도, 저장할 때 ESLint와 충돌하는 두 번째 포매터도 필요 없습니다.
// eslint.config.js
import pluginVue from 'eslint-plugin-vue'
import vuePug from 'eslint-plugin-pug-vue'
export default [
...pluginVue.configs['flat/recommended'],
...vuePug.configs.recommended,
]Pug에서는 들여쓰기가 곧 구조입니다. 한 줄만 옮겨도 트리가 바뀝니다. 그래서 ESLint가 Pug 템플릿에 fix를 쓰기 전에, 어떤 규칙에서 나온 fix든 플러그인이 먼저 검사합니다.
//- the same template to the guard
p(class="intro lead") Hello
p.intro.lead Hello
//- a different one: a class is gone
p.intro Hello그래서 vue-pug/prefer-shorthand는 첫 번째 줄을 두 번째 줄로 바꿀 수 있지만, class를 잃거나 줄을 다른 부모로 옮기는 fix는 적용되지 않습니다.
플랫 설정(flat config)을 쓰는 ESLint 9.15 또는 10, eslint-plugin-vue 10, vue-eslint-parser 10이 필요합니다. 시작하기에서 설치, 설정, VS Code의 저장 시 자동 fix까지 안내합니다. eslint-plugin-vue-pug에서 오셨나요? 마이그레이션 가이드를 읽어 보세요.