Skip to content

Trang này là bản dịch. Nếu khác với trang tiếng Anh, trang tiếng Anh là bản đúng. English

Bắt đầu ​

eslint-plugin-pug-vue lint và format <template lang="pug"> (và lang="jade") trong Vue single-file component:

  • Các rule vue/* của eslint-plugin-vue chạy trên template Pug, với tên quen thuộc và các option bạn vẫn dùng.
  • Các rule vue-pug/* format chính phần Pug: thụt lề, bố cục attribute, dấu nháy, dấu phẩy, shorthand. Một rule tùy chọn báo các construct compile-time của Pug.
  • Mọi bản fix đụng đến template Pug đều được kiểm tra trước khi ESLint áp dụng (fix guard), nên --fix và fix-on-save không làm hỏng template.
  • Không cần Prettier hay formatter riêng: các bản fix đến từ ESLint.

Yêu cầu ​

  • Node.js ^22.13.0 || >=24
  • ESLint ^9.15.0 || ^10.0.0, chỉ hỗ trợ flat config (eslint.config.js)
  • eslint-plugin-vue ^10.0.0 và vue-eslint-parser ^10.0.0

Cài đặt ​

sh
npm install --save-dev eslint eslint-plugin-vue vue-eslint-parser eslint-plugin-pug-vue
sh
pnpm add -D eslint eslint-plugin-vue vue-eslint-parser eslint-plugin-pug-vue
sh
yarn add -D eslint eslint-plugin-vue vue-eslint-parser eslint-plugin-pug-vue

Cấu hình ​

js
// 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,
]

Hãy đặt ...vuePug.configs.recommended sau các config của eslint-plugin-vue. Nó thiết lập parser option, processor và các rule phải tắt cho Pug. Một config đứng sau mà đặt processor riêng, hoặc bật lại một rule bị crash, sẽ làm hỏng việc lint file Pug.

Chạy ​

sh
npx eslint .          # report problems
npx eslint . --fix    # fix what can be fixed

Để fix khi lưu trong VS Code, xem Thiết lập editor.

Bước tiếp theo ​

Phát hành theo giấy phép MIT.