Can you explain the distinction between "parser" and "parserOptions.parser" in an ESLint configuration?

For a considerable amount of time, I have been using the TypeScript and Vue presets provided below. While it has been functional, I realize that I do not fully comprehend each option and therefore seek to gain a better understanding. Firstly, what sets apart parser from @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

In the absence of

parser: "vue-eslint-parser"
, we encounter
[unknown]: Parsing error: Unexpected token :
in a TypeScript file at this line:

(async function executeApplication(): Promise<void> {})()

Additionally, we come across

Parsing error: Unexpected token <
in a .vue file on this line:

<template lang="pug">

If we remove or comment out

parserOptions.parser: "@typescript-eslint/parser"
,

  • [unknown]: Parsing error: Unexpected token :
    persists.
  • The occurrence of
    Parsing error: Unexpected token <
    is eliminated, but instead,
    Parsing error: Unexpected character '@'
    emerges at the
    @Component export default class extends Vue {
    line.

Is it necessary to have both parser and @typescript-eslint/parser?

Answer №1

vue-eslint-parser is the primary parser to use in place of the default one (espree). It is specifically designed to handle .vue Single File Component (SFC) files, with a focus on the <template> tags.

Within this parser, you have the ability to customize which parser should be used for linting the <script> tag inside .vue files.

In essence, you are instructing eslint to parse .vue files using vue-eslint-parser, and within this parser, to opt for @typescript-eslint/parser for handling the <script> tags.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Looking to create universal React component wrappers?

I am working with a set of functional components that share a common set of properties, for example: const A = ({ x, y, z }) = {...} const B = ({ x, y, z }) = {...} For these components, I have predefined configurations: const styles { A: { ty ...

Modify the background color of the disabled checkbox in Vuetify

Check out this example where I found a disabled checkbox. Is there a way to set a custom background color for the "on" and "off" states of a disabled checkbox? ...

Experiencing a problem with Typescript validation while integrating Storybook with Material-UI (

Encountering a Typescript validation issue while attempting to pass args as children to a Material-UI button in Storybook :-/ Any suggestions on how to resolve this and avoid the Typescript error? I suspect it is caused by not passing a ReactNode. Thanks ...

Guide on efficiently inserting values into an array of objects

I'm looking to extract specific values from the enum below enum p { XDR = 1, PT1M = 2, PT1M_ = 2, PT5M = 3, PT5M_ = 3, PT15M = 4, PT15M_ = 4, PT1H = 5, PT1H_ = 5, P1D = 6, P1D_ = 6, P7D = 7, P1W = 7, ...

What is the most efficient way to enable seamless communication between sibling components in Vue.js 2?

Just starting out with Vue.js 2 and I'm really enjoying it so far despite being new to it. Currently using the latest version. I've begun working on my first larger application and ran into a scenario right off the bat where I have a main app co ...

Can you explain the distinction between `any[]` and `{ [s: string]: any }`?

I was attempting to make this code snippet function properly: test(a: any[]) { let b: string[][] = []; b.push(Object.keys(a[0])); b.push(...a.map(e => Object.values(e))); } However, the compiler is throwing an error for the b.push(...a.ma ...

The art of transforming properties into boolean values (in-depth)

I need to convert all types to either boolean or object type CastDeep<T, K = boolean> = { [P in keyof T]: K extends K[] ? K[] : T[P] extends ReadonlyArray<K> ? ReadonlyArray<CastDeep<K>> : CastDeep<T[P]> ...

Creating a user-friendly interface for an array of objects, complete with an included array containing those same objects

I have an array that I want to iterate through. It contains a single object and an array of objects. How can I create an interface for this structure? What is the appropriate declaration to replace any[]? Here is the code: export const initialPhotoProps: ...

Incorporating an Angular 2 Directive within the body tag of an

My goal is to create a custom directive that can dynamically add or remove a class from the body element in HTML. The directive needs to be controlled by a service, as I want to manage the visibility of the class from various components. Question: How ca ...

Is there a way for me to determine whether the event is being caught in the parent component?

I'm working with a generic component that is used in multiple places, and it emits an event when an action is taken. For example: onClick(value) { this.$emit('on-click', value); // However, I only want to emit this event if there is a li ...

Creating a nested type using template literal syntax

Given a two-level nested type with specific properties: export type SomeNested = { someProp: { someChild: string someOtherChild: string } someOtherProp: { someMoreChildren: string whatever: string else: string } } I am looking ...

State in Angular stubbornly refuses to switch despite condition changes

Here is the Typescript code, followed by the HTML: public verifySelection() { let choice = false; if (typeof this.formUser.permissionsTemplateID === undefined) { choice = true; } return choice; } <div class="form-group" ...

Utilizing Vue's string-based class binding feature?

Can Vue class binding work with strings? For example: <div :class={open: target == 'myString'}></div> var app = new Vue({ target: null }) It works when I don't use quotes <div :class={open: target == myString}></div ...

Optimizing your Vue.js/webpack setup: Best practices for transpiling ES6/ES7

When setting up my project, I opted for the comprehensive webpack template available on GitHub. Now I'm looking to incorporate ES7 features like async functions. I've read about using babel plugins and attempted the following: { test: /&bsol ...

Component failing to refresh with each key modification

My understanding is that adding a key attribute to a component should make it reactive when the key changes. However, with a v-navigation-drawer from Vuetify, this doesn't seem to have any impact. I've tried making arbitrary changes to the logge ...

Is there a way to hide the borders between cells within these divs?

I am working on an application screen using Vue.js and facing an issue with the divisions between cells. I want to hide these divisions so that the lines of the items appear continuous. I attempted to modify the classes of the columns to "col-md" and "col ...

Dealing with Scoping Problems in a Typescript d3 Update Tutorial

I'm facing challenges trying to implement the provided bl.ocks example in Typescript (using Angular). This is my implementation in TypeScript: StackBlitz Could anyone offer insights on what might be causing the issues I'm encountering? My initi ...

What methods are available to restrict the values of properties to specific keys within the current type?

I am looking to declare an interface in typescript that is extensible through an indexer, allowing for the dynamic association of additional functions. However, I also want sub properties within this interface that can refer back to those indexed functio ...

What is the best way to output data to the console from an observable subscription?

I was working with a simple function that is part of a service and returns an observable containing an object: private someData; getDataStream(): Observable<any> { return Observable.of(this.someData); } I decided to subscribe to this funct ...

Can Vue instances be given custom names in Vue DevTools?

Currently, I am working on a website that involves several Vue instances. I have a quick question: Can these instances be labeled and displayed with their names using vue-devtools? At the moment, my console is showing instances in a way that makes it dif ...