简体   繁体   English

ESLint 配置中的“parser”和“parserOptions.parser”有什么区别?

[英]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

Experimental data实验数据

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.

相关问题 为 ESLint 和 Airbnb typescript 设置配置 parserOptions 或解析器 package - Configure parserOptions or parser package for ESLint and Airbnb typescript setup “parserOptions.project” 已为 @typescript-eslint/parser 设置 - "parserOptions.project" has been set for @typescript-eslint/parser &#39;解析错误:已为@typescript-eslint/parser 设置了“parserOptions.project”是什么意思。 IntelliJ IDE 系列中的错误? - What means 'Parsing error: “parserOptions.project” has been set for @typescript-eslint/parser.' error in IntelliJ IDEs family? 解析错误:“parserOptions.project”已为@typescript-eslint/parser 设置。 该文件与您的项目配置不匹配:jest.config.js - Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: jest.config.js 如何修复“解析错误:“parserOptions.project”已为 @typescript-eslint/parser 设置。 在 gatsby-config 和 Gatsby-node.js 中 - How fix 'Parsing error: “parserOptions.project” has been set for @typescript-eslint/parser.' inside gatsby-config and Gatsby-node.js 解析错误:已为 @typescript-eslint/parser 设置“parserOptions.project”。 该文件与您的项目配置不匹配:.eslintrc.js - Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser. The file does not match your project config: .eslintrc.js 解析错误:“parserOptions.project”已为 @typescript-eslint/parser 设置为 gatsby/typescript - Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser for gatsby/typescript 为什么我已经为 @typescript-eslint/parser 设置了“parserOptions.project”,专门用于 .test.ts 文件? - Why am I getting "parserOptions.project" has been set for @typescript-eslint/parser specifically for .test.ts files? 我的“.eslintrc.js”文件出错 - “解析错误:已为@typescript-eslint/parser 设置了“parserOptions.project”。 - Error with my ".eslintrc.js" file - "Parsing error: "parserOptions.project" has been set for @typescript-eslint/parser." typescript 中的 eslint 解析错误,lint 没有得到 parserOptions 配置 - Parsing error with eslint in typescript, lint doesnt get the parserOptions config
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM