Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Linting warnings in a new project #4684

Closed
Fgerthoffert opened this issue Apr 26, 2020 · 7 comments
Closed

Linting warnings in a new project #4684

Fgerthoffert opened this issue Apr 26, 2020 · 7 comments
Labels
needs triage This issue has not been looked into

Comments

@Fgerthoffert
Copy link

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 git@github.com: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
@Fgerthoffert Fgerthoffert added the needs triage This issue has not been looked into label Apr 26, 2020
@jmcdo29
Copy link
Member

jmcdo29 commented Apr 26, 2020

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.

@Fgerthoffert
Copy link
Author

Awesome, thanks for the quick response.

@SkyLeite
Copy link

SkyLeite commented Oct 4, 2020

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.

@timecatalyst
Copy link

timecatalyst commented Jan 21, 2021

Sorry for bringing back this thread, but I'm experiencing a similar problem with the @Get() decorator in a fresh project created with @nestjs/cli. It seems to happen whenever I use an interface in a Promise generic response:

 1 import { Controller, Get } from '@nestjs/common';
 2
 3 interface Foo {
 4   foo: string;
 5 }
 6
 7 @Controller('foo') 
 8 export class FooController {
 9   @Get()
10   async doSomething(): Promise<Foo> {
11     return Promise.resolve({ foo: 'bar' });
12   }
13 }

The linter is throwing a no-unused-vars warning on line 3: interface Foo, despite it being used as the response type of doSomething() on line 10. If I remove the @Get decorator, the warning disappears. So far I haven't been able to find a workaround for it.

Screen Shot 2021-01-21 at 11 19 45 AM

@jmcdo29
Copy link
Member

jmcdo29 commented Jan 21, 2021

This looks like something that would be reported to the Typescript-eslint repository. It might be trusted to a new change dealing with decorators and exported types

@timecatalyst
Copy link

@jmcdo29 Sounds good, will do. Thanks for the quick response.

@timecatalyst
Copy link

In case anyone ends up here in the future, the problem I was experiencing was related to emitDecoratorMetadata in tsconfig.json. See: typescript-eslint/typescript-eslint#2972

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into
Projects
None yet
Development

No branches or pull requests

4 participants