I want to disable no unused params warning in some cases but keep "unused vars" warning.
For example here I would want to leave arguments in place to see what is passed to resolver:
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:
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'],
To apply the ESLint no-unused-vars rule to a block of JavaScript code, we can wrap the code block that we want to apply the rule to with /* eslint-disable no-unused-vars */ and /* eslint-enable no-unused-vars */ respectively. to wrap the code that we want the rule to apply with the comments.
To automatically remove unused imports, we will need to add the eslint-plugin-unused-imports plugin. Now, when you run ESLint, you should see error lines saying error '<imported-var>' is defined but never used unused-imports/no-unused-imports for the files where you have unused imports.
If you are using ESLint and you need to disable the next line, use this code: eslint-disable-next-line.
Only way that I found is to use ignore pattern argsIgnorePattern
in rule options. 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. After you will need to use this value, just remove underscore ctx
.
// note you must disable the base rule as it can report incorrect errors
"no-unused-vars": "off",
'@typescript-eslint/no-unused-vars': [
'warn', // or error
{
argsIgnorePattern: '^_',
varsIgnorePattern: '^_',
caughtErrorsIgnorePattern: '^_',
},
],
You can change this pattern ^_
as you like using RegExp.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With