Vue Pug ESLint Plugin
eslint-plugin-vue-pug is an ESLint plugin designed to extend the linting capabilities of `eslint-plugin-vue` to support Pug templates within Vue Single File Components (SFCs). It enables developers to enforce coding standards and identify potential issues directly within their `<template lang="pug">` blocks. The current stable version is `0.6.2`, released in late 2022. Due to the lack of recent commits and releases since then, the package appears to be in a maintenance mode, with infrequent updates or new feature development. Its key differentiator is providing specific linting rules for Pug syntax within the Vue ecosystem, bridging a gap not covered by standard `eslint-plugin-vue` configurations alone. It relies heavily on `eslint-plugin-vue` for its core Vue-specific linting foundation.
Common errors
-
Error: Failed to load plugin 'vue-pug' declared in '...', It was not found.
cause The `eslint-plugin-vue-pug` package is not installed or incorrectly referenced in the ESLint configuration.fixEnsure `eslint-plugin-vue-pug` is installed: `npm install eslint-plugin-vue-pug eslint-plugin-vue --save-dev` or `yarn add -D eslint-plugin-vue-pug eslint-plugin-vue`. Verify the plugin name 'vue-pug' is correctly spelled in your `.eslintrc` plugins array. -
Error: Parsing error: The template requires a parser to be specified.
cause This error typically indicates that `@vue/eslint-parser` or another template-aware parser is not correctly configured for your `.vue` files, or that it cannot correctly interpret the Pug syntax.fixEnsure `eslint-plugin-vue` is correctly configured and its recommended configuration is extended, as it brings in `@vue/eslint-parser`. Also, verify that the Pug templates themselves are well-formed and valid Pug syntax. -
Error: Invalid configuration for rule 'vue-pug/some-rule-name'
cause The specified rule does not exist, is misspelled, or is not available in the currently loaded version of the plugin.fixDouble-check the rule name for typos. Refer to the `eslint-plugin-vue-pug` documentation or its `lib/rules` directory on GitHub to confirm available rule names and their options.
Warnings
- breaking Version `0.6.0` removed the `vca-style` configuration option and instead aligned with `vue3-recommended`. Users migrating from older versions that relied on `vca-style` for Vue Composition API linting will need to update their extends configuration.
- gotcha This plugin has a peer dependency on `eslint-plugin-vue`. Mismatched versions between the two plugins can lead to unexpected parsing errors, unapplied rules, or complete failure of the linting process.
- gotcha While `eslint-plugin-vue-pug` adds rules for Pug, it relies on `@vue/eslint-parser` (which is typically part of `eslint-plugin-vue`'s setup) to actually parse the Pug template syntax. Incorrect `parserOptions.parser` configuration for the `<script>` blocks (e.g., missing Babel or TypeScript parser) can prevent ESLint from properly processing Vue SFCs, even if Pug linting rules are defined.
Install
-
npm install eslint-plugin-vue-pug -
yarn add eslint-plugin-vue-pug -
pnpm add eslint-plugin-vue-pug
Imports
- Plugin registration
const vuePugPlugin = require('eslint-plugin-vue-pug'); // This is how ESLint internally loads the plugin, not for user configuration.{ "plugins": [ "vue-pug" ] } - Recommended configuration
{ "extends": [ "plugin:vue-pug" ] } // Missing '/recommended' suffix, will not load predefined rules.{ "extends": [ "plugin:vue/vue3-recommended", "plugin:vue-pug/recommended" ] } - Individual rule
{ "rules": { "no-bare-template-tag": "error" // Rules must be prefixed with the plugin name. } }{ "rules": { "vue-pug/no-bare-template-tag": "error" } }
Quickstart
module.exports = {
root: true,
env: {
node: true,
browser: true
},
extends: [
'eslint:recommended',
'plugin:vue/vue3-recommended', // Or vue2-recommended, essential, etc.
'plugin:vue-pug/recommended' // Integrates Pug-specific linting
],
parserOptions: {
ecmaVersion: 2020,
sourceType: 'module',
// The parser for <script> blocks in Vue SFCs
parser: '@babel/eslint-parser', // Or '@typescript-eslint/parser' if using TypeScript
requireConfigFile: false
},
rules: {
// Example of a specific vue-pug rule
'vue-pug/no-bare-template-tag': 'error',
'vue-pug/no-dupe-attributes': 'error',
'vue-pug/attribute-hyphenation': ['error', 'always'],
// General ESLint rules
'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off',
'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off'
}
};