The ESLint custom parser for `.vue` files.
Installations
npm install vue-eslint-parser
Developer Guide
Typescript
Yes
Module System
CommonJS
Min. Node Version
^14.17.0 || >=16.0.0
Node Version
20.13.0
NPM Version
10.5.2
Score
93.9
Supply Chain
94.7
Quality
77.9
Maintenance
100
Vulnerability
98.6
License
Releases
Contributors
Languages
TypeScript (71.84%)
JavaScript (28.16%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
vuejs
Download Statistics
Total Downloads
785,228,027
Last Day
829,241
Last Week
4,372,365
Last Month
18,350,548
Last Year
199,867,347
GitHub Statistics
MIT License
458 Stars
392 Commits
75 Forks
12 Watchers
2 Branches
80 Contributors
Updated on Jan 29, 2025
Bundle Size
392.73 kB
Minified
114.10 kB
Minified + Gzipped
Sponsor this package
Package Meta Information
Latest Version
9.4.3
Package Id
vue-eslint-parser@9.4.3
Unpacked Size
1.08 MB
Size
193.58 kB
File Count
6
NPM Version
10.5.2
Node Version
20.13.0
Published on
Jun 01, 2024
Total Downloads
Cumulative downloads
Total Downloads
785,228,027
Last Day
-0.8%
829,241
Compared to previous day
Last Week
5.3%
4,372,365
Compared to previous week
Last Month
47.1%
18,350,548
Compared to previous month
Last Year
18.1%
199,867,347
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
Dev Dependencies
40
vue-eslint-parser
The ESLint custom parser for .vue
files.
⤴️ Motivation
This parser allows us to lint the <template>
of .vue
files. We can make mistakes easily on <template>
if we use complex directives and expressions in the template. This parser and the rules of eslint-plugin-vue would catch some of the mistakes.
💿 Installation
1npm install --save-dev eslint vue-eslint-parser
- Requires Node.js ^14.17.0, 16.0.0 or later.
- Requires ESLint 6.0.0 or later.
📖 Usage
- Write
parser
option into your.eslintrc.*
file. - Use glob patterns or
--ext .vue
CLI option.
1{ 2 "extends": "eslint:recommended", 3 "parser": "vue-eslint-parser" 4}
1$ eslint "src/**/*.{js,vue}" 2# or 3$ eslint src --ext .vue
🔧 Options
parserOptions
has the same properties as what espree, the default parser of ESLint, is supporting.
For example:
1{ 2 "parser": "vue-eslint-parser", 3 "parserOptions": { 4 "sourceType": "module", 5 "ecmaVersion": 2018, 6 "ecmaFeatures": { 7 "globalReturn": false, 8 "impliedStrict": false, 9 "jsx": false 10 } 11 } 12}
parserOptions.parser
You can use parserOptions.parser
property to specify a custom parser to parse <script>
tags.
Other properties than parser would be given to the specified parser.
For example:
1{ 2 "parser": "vue-eslint-parser", 3 "parserOptions": { 4 "parser": "@babel/eslint-parser", 5 "sourceType": "module" 6 } 7}
1{ 2 "parser": "vue-eslint-parser", 3 "parserOptions": { 4 "parser": "@typescript-eslint/parser", 5 "sourceType": "module" 6 } 7}
You can also specify an object and change the parser separately for <script lang="...">
.
1{ 2 "parser": "vue-eslint-parser", 3 "parserOptions": { 4 "parser": { 5 // Script parser for `<script>` 6 "js": "espree", 7 8 // Script parser for `<script lang="ts">` 9 "ts": "@typescript-eslint/parser", 10 11 // Script parser for vue directives (e.g. `v-if=` or `:attribute=`) 12 // and vue interpolations (e.g. `{{variable}}`). 13 // If not specified, the parser determined by `<script lang ="...">` is used. 14 "<template>": "espree", 15 } 16 } 17}
When using JavaScript configuration (.eslintrc.js
), you can also give the parser object directly.
1const tsParser = require("@typescript-eslint/parser") 2const espree = require("espree") 3 4module.exports = { 5 parser: "vue-eslint-parser", 6 parserOptions: { 7 // Single parser 8 parser: tsParser, 9 // Multiple parser 10 parser: { 11 js: espree, 12 ts: tsParser, 13 } 14 }, 15}
If the parserOptions.parser
is false
, the vue-eslint-parser
skips parsing <script>
tags completely.
This is useful for people who use the language ESLint community doesn't provide custom parser implementation.
parserOptions.vueFeatures
You can use parserOptions.vueFeatures
property to specify how to parse related to Vue features.
For example:
1{ 2 "parser": "vue-eslint-parser", 3 "parserOptions": { 4 "vueFeatures": { 5 "filter": true, 6 "interpolationAsNonHTML": true, 7 "styleCSSVariableInjection": true, 8 "customMacros": [] 9 } 10 } 11}
parserOptions.vueFeatures.filter
You can use parserOptions.vueFeatures.filter
property to specify whether to parse the Vue2 filter. If you specify false
, the parser does not parse |
as a filter.
For example:
1{ 2 "parser": "vue-eslint-parser", 3 "parserOptions": { 4 "vueFeatures": { 5 "filter": false 6 } 7 } 8}
If you specify false
, it can be parsed in the same way as Vue 3.
The following template parses as a bitwise operation.
1<template> 2 <div>{{ a | b }}</div> 3</template>
However, the following template that are valid in Vue 2 cannot be parsed.
1<template> 2 <div>{{ a | valid:filter }}</div> 3</template>
parserOptions.vueFeatures.interpolationAsNonHTML
You can use parserOptions.vueFeatures.interpolationAsNonHTML
property to specify whether to parse the interpolation as HTML. If you specify true
, the parser handles the interpolation as non-HTML (However, you can use HTML escaping in the interpolation). Default is true
.
For example:
1{ 2 "parser": "vue-eslint-parser", 3 "parserOptions": { 4 "vueFeatures": { 5 "interpolationAsNonHTML": true 6 } 7 } 8}
If you specify true
, it can be parsed in the same way as Vue 3.
The following template can be parsed well.
1<template> 2 <div>{{a<b}}</div> 3</template>
But, it cannot be parsed with Vue 2.
parserOptions.vueFeatures.styleCSSVariableInjection
If set to true
, to parse expressions in v-bind
CSS functions inside <style>
tags. v-bind()
is parsed into the VExpressionContainer
AST node and held in the VElement
of <style>
. Default is true
.
See also to here.
parserOptions.vueFeatures.customMacros
Specifies an array of names of custom macros other than Vue standard macros.
For example, if you have a custom macro defineFoo()
and you want it processed by the parser, specify ["defineFoo"]
.
Note that this option only works in <script setup>
.
parserOptions.templateTokenizer
This is an experimental feature. It may be changed or deleted without notice in the minor version.
You can use parserOptions.templateTokenizer
property to specify custom tokenizers to parse <template lang="...">
tags.
For example to enable parsing of pug templates:
1{ 2 "parser": "vue-eslint-parser", 3 "parserOptions": { 4 "templateTokenizer": { 5 // template tokenizer for `<template lang="pug">` 6 "pug": "vue-eslint-parser-template-tokenizer-pug", 7 } 8 } 9}
This option is only intended for plugin developers. Be careful when using this option directly, as it may change behaviour of rules you might have enabled.
If you just want pug support, use eslint-plugin-vue-pug instead, which uses this option internally.
See implementing-custom-template-tokenizers.md for information on creating your own template tokenizer.
🎇 Usage for custom rules / plugins
- This parser provides
parserServices
to traverse<template>
.defineTemplateBodyVisitor(templateVisitor, scriptVisitor, options)
... returns ESLint visitor to traverse<template>
.getTemplateBodyTokenStore()
... returns ESLintTokenStore
to get the tokens of<template>
.getDocumentFragment()
... returns the rootVDocumentFragment
.defineCustomBlocksVisitor(context, customParser, rule, scriptVisitor)
... returns ESLint visitor that parses and traverses the contents of the custom block.defineDocumentVisitor(documentVisitor, options)
... returns ESLint visitor to traverses the document.
- ast.md is
<template>
AST specification. - mustache-interpolation-spacing.js is an example.
defineTemplateBodyVisitor(templateBodyVisitor, scriptVisitor, options)
Arguments
templateBodyVisitor
... Event handlers for<template>
.scriptVisitor
... Event handlers for<script>
or scripts. (optional)options
... Options. (optional)templateBodyTriggerSelector
... Script AST node selector that triggers the templateBodyVisitor. Default is"Program:exit"
. (optional)
1import { AST } from "vue-eslint-parser" 2 3export function create(context) { 4 return context.parserServices.defineTemplateBodyVisitor( 5 // Event handlers for <template>. 6 { 7 VElement(node: AST.VElement): void { 8 //... 9 } 10 }, 11 // Event handlers for <script> or scripts. (optional) 12 { 13 Program(node: AST.ESLintProgram): void { 14 //... 15 } 16 }, 17 // Options. (optional) 18 { 19 templateBodyTriggerSelector: "Program:exit" 20 } 21 ) 22}
⚠️ Known Limitations
Some rules make warnings due to the outside of <script>
tags.
Please disable those rules for .vue
files as necessary.
- eol-last
- linebreak-style
- max-len
- max-lines
- no-trailing-spaces
- unicode-bom
- Other rules which are using the source code text instead of AST might be confused as well.
📰 Changelog
🍻 Contributing
Welcome contributing!
Please use GitHub's Issues/PRs.
If you want to write code, please execute npm install && npm run setup
after you cloned this repository.
The npm install
command installs dependencies.
The npm run setup
command initializes ESLint as git submodules for tests.
Development Tools
npm test
runs tests and measures coverage.npm run build
compiles TypeScript source code toindex.js
,index.js.map
, andindex.d.ts
.npm run coverage
shows the coverage result ofnpm test
command with the default browser.npm run clean
removes the temporary files which are created bynpm test
andnpm run build
.npm run lint
runs ESLint.npm run setup
setups submodules to develop.npm run update-fixtures
updates files intest/fixtures/ast
directory based ontest/fixtures/ast/*/source.vue
files.npm run watch
runsbuild
,update-fixtures
, and tests with--watch
option.

No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
6 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/CI.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:16: update your workflow using https://app.stepsecurity.io/secureworkflow/vuejs/vue-eslint-parser/CI.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/vuejs/vue-eslint-parser/CI.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/vuejs/vue-eslint-parser/CI.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:51: update your workflow using https://app.stepsecurity.io/secureworkflow/vuejs/vue-eslint-parser/CI.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:73: update your workflow using https://app.stepsecurity.io/secureworkflow/vuejs/vue-eslint-parser/CI.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:77: update your workflow using https://app.stepsecurity.io/secureworkflow/vuejs/vue-eslint-parser/CI.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:92: update your workflow using https://app.stepsecurity.io/secureworkflow/vuejs/vue-eslint-parser/CI.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:96: update your workflow using https://app.stepsecurity.io/secureworkflow/vuejs/vue-eslint-parser/CI.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/CI.yml:25
- Warn: npmCommand not pinned by hash: .github/workflows/CI.yml:56
- Warn: npmCommand not pinned by hash: .github/workflows/CI.yml:82
- Warn: npmCommand not pinned by hash: .github/workflows/CI.yml:101
- Info: 0 out of 8 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 4 npmCommand dependencies pinned
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 20 are checked with a SAST tool
Score
3.9
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to vue-eslint-parser
vue-eslint-parser-template-tokenizer-pug
This is an internal library. If you just want to lint your pug templates, use [eslint-plugin-vue-pug](https://github.com/rashfael/eslint-plugin-vue-pug).
@vue-vine/eslint-parser
ESLint parser for Vue Vine
eslint-plugin-tsvue-parser
Used for the JS/TS hybrid project, make vue+ts become another extension
typescript-eslint-parser-for-extra-files
An experimental ESLint custom parser for Vue, Svelte, and Astro for use with TypeScript. It provides type information in combination with each framework's ESLint custom parser.