Vue ESLint Parser Pug Template Tokenizer

1.0.0 · active · verified Sun Apr 19

This package, `vue-eslint-parser-template-tokenizer-pug`, serves as an internal tokenizer specifically designed for `vue-eslint-parser` to handle Pug (formerly Jade) templates within Vue Single File Components. Its primary function is to convert Pug syntax within `<template lang="pug">` blocks into a format that `vue-eslint-parser` can then process to generate an Abstract Syntax Tree (AST) for linting. It is currently at version 1.0.0. While actively maintained, it is *not* intended for direct end-user consumption. Users who wish to lint Pug templates in Vue applications should instead use `eslint-plugin-vue-pug`, which leverages this library internally. Its release cadence is tied to the needs of `eslint-plugin-vue-pug` and `vue-eslint-parser`, meaning updates are driven by functional requirements rather than a fixed schedule.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how `vue-eslint-parser-template-tokenizer-pug` is configured with `vue-eslint-parser` to lint a Vue SFC with Pug templates, emphasizing its internal role rather than direct end-user API usage.

import { ESLint } from 'eslint';
import vueParser from 'vue-eslint-parser';
import pugTokenizer from 'vue-eslint-parser-template-tokenizer-pug';

const cli = new ESLint({
  useEslintrc: false,
  overrideConfig: {
    parser: vueParser,
    parserOptions: {
      ecmaVersion: 2020,
      sourceType: 'module',
      templateTokenizer: {
        pug: pugTokenizer
      }
    },
    rules: {
      'vue/no-unused-vars': 'error'
    }
  }
});

async function lintPugVue() {
  const code = `<template lang="pug">\n  div.my-component\n    p Hello, Pug in Vue!\n    span {{ someVar }}\n</template>\n<script>\nexport default { data: () => ({ someVar: 'test' }) }\n</script>`;
  const results = await cli.lintText(code, { filePath: 'test.vue' });

  console.log('Linting Results:');
  results.forEach(result => {
    console.log(`File: ${result.filePath}`);
    result.messages.forEach(message => {
      console.log(`  Line ${message.line}, Col ${message.column}: ${message.message} (${message.ruleId})`);
    });
    if (result.errorCount > 0) {
      console.error(`  Errors: ${result.errorCount}`);
    }
  });
}

lintPugVue().catch(console.error);

view raw JSON →