[英]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.