Having trouble disabling an ESLint rule for ESLint, TypeScript, Vue, and WebPack Encore?

I've been delving into Webpack Encore and ESLint issues for quite some time now, but unfortunately, I haven't been able to find a solution to my problem.

Specifically, I've been trying to change or disable certain TypeScript-ESLint rules, but no matter what I do, I keep getting linter warnings. Here is how my configuration looks:

.eslintrc.json

{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "plugins": [
    "@typescript-eslint"
  ],
  "rules": {
    "@typescript-eslint/no-non-null-assertion": "off"
  }
}

tsconfig.json

{
  "compilerOptions": {
    "target": "es5",
    "module": "ES2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "removeComments": true,
    "preserveConstEnums": true,
    "allowSyntheticDefaultImports": true,
    "experimentalDecorators": true,
    "strict": true,
    "noImplicitAny": true,
    "esModuleInterop": true,
    "baseUrl": ".",
  },
  "include": [
    "assets/scripts/**/*"
  ],
  "exclude": [
    "node_modules"
  ]
}

Below are the relevant parts of my encore configuration:

Encore
  // ...
  .enableTypeScriptLoader()
  .enableForkedTypeScriptTypesChecking()
  .enableVueLoader()
  .enableEslintLoader((options) => {}, { lintVue: true })
  // ...
;

Despite disabling the rule, I still receive the following warning:

/some/path/my-file.ts
  97:82  warning  Forbidden non-null assertion  @typescript-eslint/no-non-null-assertion

It seems like this PR should resolve my issue, but unfortunately, it hasn't.

Do any of you have any suggestions? I would greatly appreciate any tips :)

Edit:

Thanks to the assistance of lotype and one of my colleagues, I finally managed to find a solution. A few things needed tweaking.

Firstly, ensure that the correct parser is being used:

.enableEslintLoader((options) => {
  options.parser = require('./.eslintrc.json').parser;
  // https://webpack.js.org/loaders/eslint-loader/#cache
  options.cache = false; // optional, but recommended
}, { lintVue: true })

Next, make sure to add TypeScript rules to the override section, while keeping "normal" rules in the rule section like so:

{
  "extends": [
    "eslint:recommended",
    "plugin:@typescript-eslint/eslint-recommended",
    "plugin:@typescript-eslint/recommended",
    "plugin:@typescript-eslint/recommended-requiring-type-checking"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": "./tsconfig.json"
  },
  "plugins": [
    "@typescript-eslint"
  ],
  "rules": {
    "no-console": "warn"
  },
  "overrides": [
    {
      "files": [
        "*.ts"
      ],
      "rules": {
        "@typescript-eslint/no-non-null-assertion": "off",
        "@typescript-eslint/no-explicit-any": "off"
      }
    }
  ]
}

Once again, a big thank you for assisting me with this!

Answer №1

Have you considered adding it to the overrides section of your .eslintrc.json file?

  "overrides": [
    {
      "files": ["*.ts"],
      "rules": {
        "@typescript-eslint/no-non-null-assertion": "off"
      }
    }
  ]

Update: The inclusion of "files" is now required as specified in this documentation.

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

Whenever I try to utilize async with React.FC in my React component, a TypeScript error is thrown

I am currently working on a React functional component called DashboardPage that utilizes async/await for fetching data, but I am running into a TypeScript error. The specific error message reads: 'Type '({ params }: DashboardPageProps) => Pro ...

What is the process for transforming binary code into a downloadable file format?

Upon receiving a binary response from the backend containing the filename and its corresponding download type, the following code snippet illustrates the data: 01 00 00 00 78 02 00 00 6c 02 00 00 91 16 a2 3d ....x...l....... 9d e3 a6 4d 8a 4b b4 38 77 bc b ...

"Encountered a problem with Next JS API while trying to fetch data from the app directory

import { NextResponse } from "next/server"; export async function POST(request: Request) { const data = await request.json(); console.log(data); return NextResponse.json({ foo: "boo" }); } next version = "next": &quo ...

Is it necessary to use both Vue Router and Express when incorporating Firebase into your project?

I am embarking on creating a simple application that will encompass various views, user authentication, data collection, database storage, and backend functionality to process and display the stored information. My chosen technology stack consists of Vue. ...

The stacking order of elements is not affected by the z-index property when using absolute positioning

I have developed a unique custom toggle switch component with the following structure: <template> <div> <label class="switch"> <input type="checkbox" :checked="value" @c ...

Dealing with Form Submission on Enter Keypress in VueJs

Transitioning from Angular to Vue was smooth until I encountered a frustrating issue that seems to have been ignored by VueJS developers. The challenge of allowing users to submit a form by pressing enter from an input field had me pulling my hair out. How ...

Is there a way to display all articles within an array while utilizing a computed property to sort through outcomes on VueJS?

I am currently utilizing VueJS to display a collection of articles. Additionally, I have integrated filters that utilize checkboxes and a computed property to refine the display of articles based on the selected tag. However, I am interested in incorporat ...

Vue.js - display additional items in an array with matching titles

I am working with an array of objects, examples include: [{ title: 'foo' id: 1, name: 'anne' }, { title: 'example', id: 2, name: 'anne' }, { title: 'ex', id: 3, name: &a ...

Encountering a problem while trying to execute npm run serve on a newly created Vue-CLI project

Struggling to execute npm run serve on a fresh vue Project made with the Vue CLI. I initiated the project using vue create app, navigated to the project directory cd app, and ran npm run serve, a routine I have followed in previous projects. However, start ...

Angular 2 feature that allows for a single list value to be toggled with the

Currently, my form is connected to a C# API that displays a list of entries. I am trying to implement a feature where two out of three fields can be edited for each line by clicking a button that toggles between Yes and No. When the button is clicked, it s ...

CSS not being applied to certain HTML elements due to an error in implementation

Utilizing Bootstrap's vue form-group has been instrumental in my creation of input fields. I am currently attempting to apply specific CSS styling to the 'legend' element within the following code: <fieldset id="__BVID__59" class="form-g ...

Encountering an error in TypeScript: Attempting to define type files for a third-party library triggers the TS2709 error when attempting to use the 'Optional' namespace as a type

Currently, I'm in the process of creating type files for a third-party library called optional-js. The structure is as follows: index.js var Optional = require('./lib/optional.js'); module.exports = { empty: function empty() { ...

Implementing Cors in Laravel 5.6 using Passport for authentication and Vue.js with Axios for making API calls

After extensive research on solving my CORS problem, I came across this package that promised to resolve everything. However, despite my attempts to implement it, I have yet to find a solution. The error I'm encountering is: Failed to load https://b ...

vue-spa breadcrumbs component

I am currently working on enhancing the navigation of my vue-spa project by implementing breadcrumbs. These breadcrumbs should be capable of displaying properties as breadcrumb-items, and each part of a route must be correctly identified as a breadcrumb-it ...

Hold off until the RxJS dispatch is resolved

I am working on integrating a "next step" feature into my Angular 6 webapp. When the user clicks the "next step" button, the frontend triggers an action to update the database with the data in the store, another action to retrieve processed data from a Spr ...

Is there a way to make Firebase Cloud Functions utilize ESLint?

Is there a specific command to activate ESLint for my cloud functions? Just to provide some context, I executed firebase init and completed the setup process, but it ended up using ESLint instead of TSLint which was unexpected. After that, I ran firebase ...

The SupabaseAuthClient type does not have a property named 'session' available

Here is the complete code snippet for page.tsx: "use client"; import React, { useState, useEffect } from "react"; import axios from "axios"; import { Session } from "@supabase/supabase-js"; import { Auth } from " ...

Vue 2: Avoid using Prop Object directly within template section

Query: Despite accurately passing the prop through Vue DevTools and ensuring that the router-view component has access to the necessary data in the correct format, I encounter a puzzling issue. When attempting to access any of the data properties within th ...

The type 'NextApiRequest' lacks the following attributes compared to type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any>>'

An error has been identified in the code for a Next.js project below. The error message reads: Argument of type 'NextApiRequest' is not assignable to parameter of type 'Request<ParamsDictionary, any, any, ParsedQs, Record<string, any ...

Encountering an issue while attempting to publish the extension: Part URI does not comply with the regulations outlined in the Open Packaging Conventions specification

My goal is to release an extension using vsce. I successfully logged in with the user access token and after building, a file named 'NadavShaked.my-first-extension v1.0.968.vsix' was created. However, when attempting to publish the extension to t ...