简体   繁体   English

如何禁用@typescript-eslint/no-non-null-assertion 规则

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

I want to allow data!.id我想允许data!.id

Error:错误:

warning Forbidden non-null assertion @typescript-eslint/no-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'
  }
}

Please add '@typescript-eslint/no-non-null-assertion': 'off' to your config file like below.请将'@typescript-eslint/no-non-null-assertion': 'off'到您的配置文件中,如下所示。

module.exports = {
  ...
  rules: {
    ...
    '@typescript-eslint/no-non-null-assertion': 'off'
  },
  ...
}

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何禁用来自@typescript-eslint 的警告? - How to disable warnings from @typescript-eslint? 如何禁用@typescript-eslint/semi? - how disable @typescript-eslint/semi? 如何使用反应开发服务器禁用 @typescript-eslint/no-unused-vars 规则 - How can I disable @typescript-eslint/no-unused-vars rule with react dev server 如何将 typescript-eslint 规则添加到 eslint - How to add typescript-eslint rules to eslint 如何修复“未找到规则‘@typescript-eslint/no-use-before-declare’的定义。eslint(@typescript-eslint/no-use-before-declare)” - How to fix 'Definition for rule '@typescript-eslint/no-use-before-declare' was not found.eslint(@typescript-eslint/no-use-before-declare)' 如何解决“未找到规则‘@typescript-eslint/rule-name’的定义” - How to resolve "Definition for rule '@typescript-eslint/rule-name' was not found" 如何处理 catch(err) 块上的 @typescript-eslint/no-unsafe-member-access 规则? - How to handle the @typescript-eslint/no-unsafe-member-access rule on catch(err) blocks? 是否有关于可选属性的属性访问的 Typescript-Eslint 规则? - Is there a Typescript-Eslint rule on property access on optional property? 如何解决:“找不到规则'@typescript-eslint/consistent-type-assertions'的定义” - How to resolve: "Definition for rule '@typescript-eslint/consistent-type-assertions' was not found" 如何配置@typescript-eslint 规则 - How to configure @typescript-eslint rules
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM