[英]What the difference between "parser" and "parserOptions.parser" in ESLint config?
I has used below preset for TypeScript and Vue for a long time.我已经为 TypeScript 和 Vue 使用了很长时间的以下预设。 It works, but I has not understood each option and now going to understand it.
它有效,但我还没有理解每个选项,现在要理解它。 First: what the difference between
parser
and @typescript-eslint/parser
?首先:
parser
和@typescript-eslint/parser
有什么区别?
parser: vue-eslint-parser
parserOptions:
parser: "@typescript-eslint/parser"
sourceType: module
project: tsconfig.json
tsconfigRootDir: ./
extraFileExtensions: [ ".vue" ]
env:
es6: true
browser: true
node: true
plugins:
- "@typescript-eslint"
- vue
Without parser: "vue-eslint-parser"
, we have [unknown]: Parsing error: Unexpected token:
in TypeScript file in line:没有
parser: "vue-eslint-parser"
,我们有[unknown]: Parsing error: Unexpected token:
in TypeScript file in line:
(async function executeApplication(): Promise<void> {})()
and Parsing error: Unexpected token <
in .vue
file in line:和
Parsing error: Unexpected token <
in .vue
file in line:
<template lang="pug">
If we delete or comment out parserOptions.parser: "@typescript-eslint/parser"
,如果我们删除或注释掉
parserOptions.parser: "@typescript-eslint/parser"
,
[unknown]: Parsing error: Unexpected token:
will remain. [unknown]: Parsing error: Unexpected token:
将保留。Parsing error: Unexpected token <
will disappear but Parsing error: Unexpected character '@'
will appear in @Component export default class extends Vue {
line. Parsing error: Unexpected token <
将消失,但Parsing error: Unexpected character '@'
将出现在@Component export default class extends Vue {
line. Both parser
and @typescript-eslint/parser
are required? parser
和@typescript-eslint/parser
都是必需的?
vue-eslint-parser
is the main parser to use instead of the default one ( espree
). vue-eslint-parser
是要使用的主要解析器,而不是默认的解析器( espree
)。 It will handle.vue SFC files, especially the <template>
tags.它将处理 .vue SFC 文件,尤其是
<template>
标签。
Within this parser, you have a custom option to specify which parser to use to lint the <script>
tag in the .vue
files.在这个解析器中,您有一个自定义选项来指定使用哪个解析器来对
.vue
文件中的<script>
标记进行 lint。
So basically, you're telling eslint to parse .vue
files with vue-eslint-parser
, and within this parser, to use @typescript-eslint/parser
for the <script>
tags.所以基本上,你告诉 eslint 用
vue-eslint-parser
解析.vue
文件,并在这个解析器中,使用@typescript-eslint/parser
来处理<script>
标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.