Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to disable @typescript-eslint/no-non-null-assertion rule

I want to allow data!.id

Error:

warning Forbidden non-null assertion @typescript-eslint/no-non-null-assertion

Current config:

module.exports = {
  parser: '@typescript-eslint/parser',
  extends: [
    'eslint:recommended',
    'plugin:jsx-a11y/recommended',
    'plugin:@typescript-eslint/eslint-recommended',
    'plugin:@typescript-eslint/recommended',
    'plugin:react/recommended',
    'prettier/@typescript-eslint',
    'plugin:prettier/recommended'
  ],
  plugins: ['react-hooks'],
  parserOptions: {
    ecmaVersion: 2020,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true
    }
  },
  rules: {
    '@typescript-eslint/ban-ts-ignore': 0,
    '@typescript-eslint/no-explicit-any': 0,
    '@typescript-eslint/consistent-type-assertions': ['warn', { assertionStyle: 'as' }],
    eqeqeq: 1,
    'react/prop-types': 0,
    '@typescript-eslint/camelcase': 0,
    'react-hooks/rules-of-hooks': 'error',
    'react-hooks/exhaustive-deps': 'warn'
  },
  globals: {
    React: 'writable'
  }
}
like image 679
ZiiMakc Avatar asked Feb 20 '20 13:02

ZiiMakc


People also ask

How do I turn off rule ESLint?

If you want to disable an ESLint rule in a file or on a specific line, you can add a comment. On a single line: const message = 'foo'; console. log(message); // eslint-disable-line no-console // eslint-disable-next-line no-console console.

What is TypeScript Eslint?

typescript-eslint enables ESLint to run on TypeScript code. typescript-eslint : allows ESLint to parse TypeScript syntax. creates a set of tools for ESLint rules to be able to use TypeScript's type information. provides a large list of lint rules that are specific to TypeScript and/or use that type information.


2 Answers

Please add '@typescript-eslint/no-non-null-assertion': 'off' to your config file like below.

module.exports = {
  ...
  rules: {
    ...
    '@typescript-eslint/no-non-null-assertion': 'off'
  },
  ...
}
like image 194
tatsuya kanemoto Avatar answered Oct 21 '22 05:10

tatsuya kanemoto


If you're attempting to disable a rule on the entire file, adding this comment in the file top to ignore will work:

/* eslint-disable  @typescript-eslint/no-non-null-assertion */

If you're attempting to disable a rule on the next line only (rather than for an entire file), adding this comment directly above the line to ignore will work:

// eslint-disable-next-line  @typescript-eslint/no-non-null-assertion
like image 23
Afaq Ahmed Khan Avatar answered Oct 21 '22 05:10

Afaq Ahmed Khan