Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
vue-eslint-parser
Advanced tools
The vue-eslint-parser npm package is a parser that allows ESLint to lint .vue files' script and template sections. It is designed to parse Vue.js component files and extract the JavaScript expression inside them for ESLint to check.
Parsing .vue files
This feature allows the integration of ESLint with Vue.js single-file components. The code sample shows how to configure ESLint to use vue-eslint-parser in a project's .eslintrc.js file.
module.exports = { parser: 'vue-eslint-parser', parserOptions: { parser: 'babel-eslint', sourceType: 'module', ecmaVersion: 2020 } }
Extracting script content
vue-eslint-parser extracts the script content from a .vue file, enabling ESLint to lint the JavaScript code within. The code sample is a Vue component with a template and a script section.
/* eslint-disable */ <template><div>{{ message }}</div></template><script>export default { data() { return { message: 'Hello Vue!' }; } }</script>
Supporting custom blocks
The parser can handle custom blocks in .vue files, such as style and i18n blocks, although linting these blocks may require additional plugins or configurations. The code sample includes a style block along with the template and script.
/* eslint-disable */ <template><div>{{ message }}</div></template><script>export default { data() { return { message: 'Hello Vue!' }; } }</script><style scoped>.message { color: red; }</style>
This package is an ESLint plugin that provides linting rules for Vue.js templates. It is often used in conjunction with vue-eslint-parser to lint both the template and script parts of Vue components.
babel-eslint is a parser that allows ESLint to run on source code that is transpiled with Babel. While it does not specifically target Vue.js files, it is commonly used as the underlying JavaScript parser for vue-eslint-parser.
The ESLint custom parser for .vue
files.
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.
$ npm install --save-dev eslint vue-eslint-parser
parser
option into your .eslintrc.*
file.--ext .vue
CLI option.{
"extends": "eslint:recommended",
"parser": "vue-eslint-parser"
}
$ eslint "src/**/*.{js,vue}"
# or
$ eslint src --ext .vue
parserOptions
has the same properties as what espree, the default parser of ESLint, is supporting.
For example:
{
"parser": "vue-eslint-parser",
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2017,
"ecmaFeatures": {
"globalReturn": false,
"impliedStrict": false,
"jsx": false,
"experimentalObjectRestSpread": false
}
}
}
Also, you can use parser
property to specify a custom parser to parse <script>
tags.
Other properties than parser would be given to the specified parser.
For example:
{
"parser": "vue-eslint-parser",
"parserOptions": {
"parser": "babel-eslint",
"sourceType": "module",
"allowImportExportEverywhere": false
}
}
{
"parser": "vue-eslint-parser",
"parserOptions": {
"parser": "typescript-eslint-parser"
}
}
babel-eslint
, use babel-eslint@>=8.1.1
.typescript-eslint-parser
, the location of original nodes can be wrong. Waiting for typescript-eslint-parser
to support parseResult.visitorKeys.parserServices
to traverse <template>
.
defineTemplateBodyVisitor(templateVisitor, scriptVisitor)
... returns ESLint visitor to traverse <template>
.getTemplateBodyTokenStore()
... returns ESLint TokenStore
to get the tokens of <template>
.<template>
AST specification.Some rules make warnings due to the outside of <script>
tags.
Please disable those rules for .vue
files as necessary.
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.
npm test
runs tests and measures coverage.npm run build
compiles TypeScript source code to index.js
, index.js.map
, and index.d.ts
.npm run coverage
shows the coverage result of npm test
command with the default browser.npm run clean
removes the temporary files which are created by npm test
and npm run build
.npm run lint
runs ESLint.npm run setup
setups submodules to develop.npm run update-fixtures
updates files in test/fixtures/ast
directory based on test/fixtures/ast/*/source.vue
files.npm run watch
runs build
, update-fixtures
, and tests with --watch
option.FAQs
The ESLint custom parser for `.vue` files.
The npm package vue-eslint-parser receives a total of 827,008 weekly downloads. As such, vue-eslint-parser popularity was classified as popular.
We found that vue-eslint-parser demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 2 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.