eslint-plugin-pug
raw JSON → 1.2.7 verified Sat Apr 25 auth: no javascript
ESLint plugin for linting inline JavaScript in Pug template files, currently at version 1.2.7. It extracts script tags without a type attribute or with type text/javascript and lints them using ESLint rules. The plugin processes .pug and .jade files, creating virtual files for linting. It has a simple setup with both processor and rules config. Alternative: eslint-plugin-html for HTML. Released under Unlicense with no dependencies.
Common errors
error Error: Failed to load plugin 'pug' declared in 'plugins': Cannot find module 'eslint-plugin-pug' ↓
cause Plugin not installed or missing in package.json.
fix
npm install --save-dev eslint-plugin-pug
error TypeError: Cannot read properties of undefined (reading 'pug') ↓
cause Using named import instead of default import in flat config.
fix
import pug from 'eslint-plugin-pug' not import { pug } from ...
error ESLint configuration for processor is invalid: "pug/pug" is not a valid processor. ↓
cause Processor string must be '<plugin>/<processorName>' with correct plugin name/alias.
fix
Set processor: 'pug/pug' after adding plugin with key 'pug'.
Warnings
breaking ESLint v9 flat config requires processor and rules config split, plugin must be imported default. ↓
fix Use flat config with processor and rules separate sections; import default export.
gotcha Only script tags without type or with type 'text/javascript' are linted; other scripts are ignored. ↓
fix Ensure your script tags have no type attribute or type='text/javascript'.
gotcha Virtual files are created with extensions .pug.js or .pug.mjs; rules must target these patterns. ↓
fix Set files in rules config to ['**/*.pug.js', '**/*.pug.mjs'] (or similar).
deprecated ESLint v8 .eslintrc style config is not supported with v9; plugin must be used in flat config. ↓
fix Migrate to flat config (eslint.config.js).
gotcha Processor only extracts inline scripts; does not lint Pug syntax itself. ↓
fix Use a separate tool like pug-lint for Pug syntax validation.
Install
npm install eslint-plugin-pug yarn add eslint-plugin-pug pnpm add eslint-plugin-pug Imports
- default wrong
const pug = require('eslint-plugin-pug')correctimport pug from 'eslint-plugin-pug' - pug wrong
import { pug } from 'eslint-plugin-pug'correctimport pug from 'eslint-plugin-pug' - plugins wrong
plugins: ['pug']correctplugins: { pug }
Quickstart
// eslint.config.js (ESLint v9+)
import { defineConfig } from 'eslint/config';
import pugPlugin from 'eslint-plugin-pug';
export default defineConfig([
{
name: 'pug-processor',
files: ['**/*.pug'],
plugins: { pug: pugPlugin },
processor: 'pug/pug',
},
{
name: 'pug-rules',
files: ['**/*.pug.mjs'],
rules: {
'@stylistic/eol-last': ['error', 'never'],
},
},
]);