[英]How to disable warn about some unused params, but keep "@typescript-eslint/no-unused-vars" rule
I want to disable no unused params warning but keep "unused vars" warning.我想禁用未使用的参数警告,但保留“未使用的变量”警告。
For this code:对于此代码:
const Query = objectType({
name: 'Query',
definition(t) {
t.field('test', {
type: 'Test',
resolve: (root, args, ctx) => {
const x = 1
return { id: 1, time: new Date().toString() }
},
})
},
})
I get warnings:我收到警告:
26:17 warning 'root' is defined but never used @typescript-eslint/no-unused-vars
26:23 warning 'args' is defined but never used @typescript-eslint/no-unused-vars
26:29 warning 'ctx' is defined but never used @typescript-eslint/no-unused-vars
27:15 warning 'x' is assigned a value but never used @typescript-eslint/no-unused-vars
eslint config: eslint 配置:
module.exports = {
root: true,
parser: '@typescript-eslint/parser',
parserOptions: { ecmaVersion: 2020, ecmaFeatures: { jsx: true } },
env: {
browser: true,
node: true,
},
extends: ['plugin:react-hooks/recommended', 'eslint:recommended', 'plugin:@typescript-eslint/recommended', 'plugin:react/recommended'],
settings: {
react: {
version: 'detect',
},
},
rules: {
'@typescript-eslint/no-empty-function': 'off',
'react/react-in-jsx-scope': 'off',
'@typescript-eslint/no-explicit-any': 'off',
'react/prop-types': 'off',
'@typescript-eslint/no-var-requires': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': ['off'],
},
ignorePatterns: ['**/generated/*'],
}
I was trying to disable it somehow, but found only this option that disables everything:我试图以某种方式禁用它,但发现只有这个选项可以禁用所有内容:
'no-unused-vars': 'off', '@typescript-eslint/no-unused-vars': ['off'], 'no-unused-vars': 'off', '@typescript-eslint/no-unused-vars': ['off'],
Only way that i found is to use ignore pattern argsIgnorePattern
in rule options.我发现的唯一方法是在规则选项中使用忽略模式
argsIgnorePattern
。 If your variable is unused, just add underscore _ctx
and eslint will ignore it, but no-unused-vars
rule will still work for other values.如果您的变量未使用,只需添加下划线
_ctx
并且 eslint 将忽略它,但no-unused-vars
规则仍然适用于其他值。
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', varsIgnorePattern: '^_' }],
You can change this pattern ^_
as you like using regexp.您可以使用正则表达式随意更改此模式
^_
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.