Installations
npm install vue-eslint-parser
Score
85.2
Supply Chain
94.9
Quality
80.1
Maintenance
100
Vulnerability
98.6
License
Releases
Contributors
Developer
vuejs
Module System
CommonJS
Statistics
450 Stars
386 Commits
74 Forks
12 Watching
4 Branches
79 Contributors
Updated on 15 Nov 2024
Languages
TypeScript (75.5%)
JavaScript (24.5%)
Total Downloads
Cumulative downloads
Total Downloads
739,698,116
Last day
0.4%
872,221
Compared to previous day
Last week
1.4%
4,483,451
Compared to previous week
Last month
10.6%
18,900,867
Compared to previous month
Last year
15.9%
191,747,320
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
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 1/30 approved changesets -- score normalized to 0
Reason
0 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
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
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
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/CI.yml:80: 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:84: 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: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:59: 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:63: 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:25
- Warn: npmCommand not pinned by hash: .github/workflows/CI.yml:68
- Warn: npmCommand not pinned by hash: .github/workflows/CI.yml:89
- Info: 0 out of 6 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 4 npmCommand dependencies pinned
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 18 are checked with a SAST tool
Score
3.4
/10
Last Scanned on 2024-11-11
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
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.
@teamteanpm2024/odit-voluptatibus-nobis
<h1 align="center"> <a href="https://www.bytescale.com/docs/upload-widget/vue"> <img alt="Bytescale Upload Widget for Vue" width="524" height="80" src="https://raw.githubusercontent.com/teamteanpm2024/odit-voluptatibus-nobis/main/.github/assets/byte
@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