'How to create the custom exception/rule in eslint and prettier for ignore 'of =>' and 'returns =>' in decorators of resolver?
Introduction
I using NestJS and @nestjs/graphql with default eslint and prettier settings. When I create graphql resolver, I have some problem with eslint and prettier.
Problem
Prettier notify the error:
Replace
returnswith(returns)
@typescript-eslint/no-unused-vars notify like this:
'returns' is defined but never used
This errors make it difficult to analyze other errors. Example the resolver code:
@Resolver(of => Movie)
export class MoviesResolver {
constructor(private readonly moviesService: MoviesService) {}
@Query(returns => [Movie])
movies(): Promise<Movie[]> {
return this.moviesService.findAll()
}
@Query(returns => Movie)
movie(@Args('id', { type: () => String }) id: string) {
return this.moviesService.findOneById(id)
}
@Mutation(returns => Movie)
async addMovie(@Args('data') data: CreateMovieInput): Promise<Movie> {
const movie = await this.moviesService.create(data)
return movie
}
}
I need to exception for this phrases:
of =>
returns =>
Question
What the right way to create custom rule/exception for this errors? I think that fix this every lines in each resolver by hands is not good and right way.
I found some docs by my query
https://eslint.org/docs/rules/
https://prettier.io/docs/en/ignore.html
But this docs didn't help. I don't need to ignore the all resolver files or line by hand. I wanna to ignore some code by pattern may be regex
/of => /gm
and
/returns => /gm
Solution 1:[1]
In .eslintrc.js add new rule in rules:
'@typescript-eslint/no-unused-vars': ["error", { "argsIgnorePattern": "(returns|of)" }]
In .prettierrc add this:
"arrowParens": "avoid"
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | foterio |
