darraghoriordan / eslint-plugin-nestjs-typed

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

`provided-injected-should-match-factory-parameters` fails linting on unrelated code #63

Closed mcmxcdev closed 1 year ago

mcmxcdev commented 1 year ago

The lint rule mentioned above encounters this code and fails:

searchProvidersReturn = (providers: IdeonProvider[]) => {
    return providers.map((provider) => {
      const entity: Provider = { // THIS LINE
        id: provider.id,
        firstName: provider.first_name,
        middleName: provider.middle_name,
        lastName: provider.last_name,
        suffix: provider.suffix,
        title: provider.title,
        presentationName: provider.presentation_name,
        gender: provider.gender,
        npis: provider.npis,
        phone: provider.phone,
        email: provider.email,
        specialty: provider.specialty,
        addresses: provider.addresses,
      };
      return entity;
    });
  };

The stacktrace is as follows:

> nx run backend:lint

Linting "backend"...

 >  NX   Cannot read properties of undefined (reading 'params')

   Occurred while linting /home/user/Webdevelopment/Freelancing/Client/repository/apps/backend/src/insurance/insurance.service.ts:77
   Rule: "@darraghor/nestjs-typed/provided-injected-should-match-factory-parameters"

TypeError: Cannot read properties of undefined (reading 'params')
Occurred while linting /home/user/Webdevelopment/Freelancing/Client/repository/apps/backend/src/insurance/insurance.service.ts:77
Rule: "@darraghor/nestjs-typed/provided-injected-should-match-factory-parameters"
    at hasMismatchedInjected (/home/user/Webdevelopment/Freelancing/Client/repository/node_modules/.pnpm/@darraghor+eslint-plugin-nestjs-typed@3.21.2_@typescript-eslint+parser@5.59.2_class-validator_h7qfkjnhkslhix4uwhkjr3zqvq/node_modules/@darraghor/eslint-plugin-nestjs-typed/dist/rules/providerInjectedShouldMatchFactory/ProviderInjectedShouldMatchFactory.js:19:182)
    at VariableDeclarator (/home/user/Webdevelopment/Freelancing/Client/repository/node_modules/.pnpm/@darraghor+eslint-plugin-nestjs-typed@3.21.2_@typescript-eslint+parser@5.59.2_class-validator_h7qfkjnhkslhix4uwhkjr3zqvq/node_modules/@darraghor/eslint-plugin-nestjs-typed/dist/rules/providerInjectedShouldMatchFactory/ProviderInjectedShouldMatchFactory.js:48:55)
    at ruleErrorHandler (/home/user/Webdevelopment/Freelancing/Client/repository/node_modules/.pnpm/eslint@8.39.0/node_modules/eslint/lib/linter/linter.js:1045:28)
    at /home/user/Webdevelopment/Freelancing/Client/repository/node_modules/.pnpm/eslint@8.39.0/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/home/user/Webdevelopment/Freelancing/Client/repository/node_modules/.pnpm/eslint@8.39.0/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/home/user/Webdevelopment/Freelancing/Client/repository/node_modules/.pnpm/eslint@8.39.0/node_modules/eslint/lib/linter/node-event-generator.js:297:26)
    at NodeEventGenerator.applySelectors (/home/user/Webdevelopment/Freelancing/Client/repository/node_modules/.pnpm/eslint@8.39.0/node_modules/eslint/lib/linter/node-event-generator.js:326:22)
    at NodeEventGenerator.enterNode (/home/user/Webdevelopment/Freelancing/Client/repository/node_modules/.pnpm/eslint@8.39.0/node_modules/eslint/lib/linter/node-event-generator.js:340:14)
    at CodePathAnalyzer.enterNode (/home/user/Webdevelopment/Freelancing/Client/repository/node_modules/.pnpm/eslint@8.39.0/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:795:23)
darraghoriordan commented 1 year ago

fixed this one in 3.22.3

i added a check that the Provider declaration includes a useFactory property. close enough i reckon.