Nest: Linting warnings in a new project

Created on 26 Apr 2020  Â·  3Comments  Â·  Source: nestjs/nest

Bug Report

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?

Steps to reproduce

git clone [email protected]:nestjs/nest.git
cd nest/sample/23-graphql-code-first
yarn
yarn run lint

Current behavior

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.

Expected behavior

No warnings

Environment

Nest version: 7.0.9

For Tooling issues:

  • Node version: v12.16.2
  • Platform: Mac
needs triage

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.

@Field(() => ID)

And now there's no linting error.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

marshall007 picture marshall007  Â·  3Comments

menme95 picture menme95  Â·  3Comments

rlesniak picture rlesniak  Â·  3Comments

janckerchen picture janckerchen  Â·  3Comments

hackboy picture hackboy  Â·  3Comments