darraghoriordan / eslint-plugin-nestjs-typed

Some eslint rules for working with NestJs projects
http://www.darraghoriordan.com
171 stars 34 forks source link

injectable-should-be-provided doesn't work with not callable decorators #30

Closed WiseBird closed 2 years ago

WiseBird commented 2 years ago

Description

injectable-should-be-provided fails if a class has a not callable decorator:

@boundClass
@Injectable()
export class AppService {

The error:

TypeError: Cannot read properties of undefined (reading 'name')

happens when we try to get the name of the decorator:

        const decorators = n.decorators?.filter((d) =>
            decoratorNames.includes(
                (
                    (d.expression as TSESTree.CallExpression)
                        .callee as TSESTree.Identifier
                ).name <--
            )
        );

Reproduction

https://github.com/WiseBird/eslint-plugin-nestjs-issue-decorator (commit)

darraghoriordan commented 2 years ago

Hey thanks for reporting this. I fixed the rule so it won't crash for you now 👍