I'm starting a new GraphQL project, following the code-first approach, but I'm getting a bunch of linting warning for rule @typescript-eslint/no-unused-vars
whenever @Field
is used.
I see the same is happening with the following sample project: https://github.com/nestjs/nest/tree/master/sample/23-graphql-code-first
I don't want to disable the rule altogether, other than disabling the rule for each line, would there be a way to address this in the code?
git clone [email protected]:nestjs/nest.git
cd nest/sample/23-graphql-code-first
yarn
yarn run lint
nest/sample/23-graphql-code-first on î‚ master [?] is 📦 v1.0.0 via ⬢ v12.16.2 took 26s
➜ yarn run lint
yarn run v1.22.4
$ eslint '{src,apps,libs,test}/**/*.ts' --fix
/Users/user/GitHub/nestjs/nest/sample/23-graphql-code-first/src/common/scalars/date.scalar.ts
4:17 warning 'type' is defined but never used @typescript-eslint/no-unused-vars
/Users/user/GitHub/nestjs/nest/sample/23-graphql-code-first/src/recipes/dto/new-recipe.input.ts
15:10 warning 'type' is defined but never used @typescript-eslint/no-unused-vars
/Users/user/GitHub/nestjs/nest/sample/23-graphql-code-first/src/recipes/dto/recipes.args.ts
6:10 warning 'type' is defined but never used @typescript-eslint/no-unused-vars
10:10 warning 'type' is defined but never used @typescript-eslint/no-unused-vars
/Users/user/GitHub/nestjs/nest/sample/23-graphql-code-first/src/recipes/models/recipe.model.ts
5:10 warning 'type' is defined but never used @typescript-eslint/no-unused-vars
17:10 warning 'type' is defined but never used @typescript-eslint/no-unused-vars
/Users/user/GitHub/nestjs/nest/sample/23-graphql-code-first/src/recipes/recipes.resolver.ts
11:11 warning 'of' is defined but never used @typescript-eslint/no-unused-vars
15:10 warning 'returns' is defined but never used @typescript-eslint/no-unused-vars
24:10 warning 'returns' is defined but never used @typescript-eslint/no-unused-vars
29:13 warning 'returns' is defined but never used @typescript-eslint/no-unused-vars
38:13 warning 'returns' is defined but never used @typescript-eslint/no-unused-vars
43:17 warning 'returns' is defined but never used @typescript-eslint/no-unused-vars
/Users/user/GitHub/nestjs/nest/sample/23-graphql-code-first/src/recipes/recipes.service.ts
14:16 warning 'data' is defined but never used @typescript-eslint/no-unused-vars
18:21 warning 'id' is defined but never used @typescript-eslint/no-unused-vars
22:17 warning 'recipesArgs' is defined but never used @typescript-eslint/no-unused-vars
26:16 warning 'id' is defined but never used @typescript-eslint/no-unused-vars
✖ 16 problems (0 errors, 16 warnings)
✨ Done in 4.27s.
No warnings
Nest version: 7.0.9
For Tooling issues:
You can use a function that looks like this instead and then not have those errors. This is an issue of an aggressive linter, not a problem with the framework.
@Field(() => ID)
And now there's no linting error.
Awesome, thanks for the quick response.
You can also modify your .eslintrc.js file to include the following:
module.exports = {
rules: {
'@typescript-eslint/no-unused-vars': ['error', { args: 'none' }],
},
};
This disables the no-unused-vars
rule but only for function arguments, making this issue go away while keeping the rule in other contexts.
Most helpful comment
You can use a function that looks like this instead and then not have those errors. This is an issue of an aggressive linter, not a problem with the framework.
And now there's no linting error.