【问题标题】:How to disable @typescript-eslint/no-non-null-assertion rule如何禁用@typescript-eslint/no-non-null-assertion 规则
【发布时间】:2020-06-04 19:38:54
【问题描述】:

我要允许data!.id

错误:

警告禁止非空断言 @typescript-eslint/no-non-null-assertion

当前配置:

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'
  }
}

【问题讨论】:

  • 在配置规则中添加'@typescript-eslint/no-non-null-assertion': 'off'不就行了吗?
  • 奇怪,我可以禁用任何规则,但不能禁用这个。

标签: typescript eslint


【解决方案1】:

请将'@typescript-eslint/no-non-null-assertion': 'off' 添加到您的配置文件中,如下所示。

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

【讨论】:

    【解决方案2】:

    如果您尝试禁用整个文件的规则,在文件顶部添加此注释以忽略将起作用:

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

    如果您尝试仅在下一行(而不是整个文件)禁用规则,则直接在该行上方添加此注释以忽略将起作用:

    // eslint-disable-next-line  @typescript-eslint/no-non-null-assertion
    

    【讨论】:

      猜你喜欢
      • 2020-03-23
      • 2020-10-21
      • 2020-10-01
      • 2020-03-27
      • 2020-01-25
      • 2020-11-10
      • 2021-02-20
      • 2021-05-08
      • 2021-09-05
      相关资源
      最近更新 更多