darraghoriordan / eslint-plugin-nestjs-typed

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

plugin doesn't work with NX #142

Open kosiakMD opened 8 months ago

kosiakMD commented 8 months ago

"@darraghor/eslint-plugin-nestjs-typed": "^4.4.0",

either files not found or are ignored - blocks other rules to go forward even with warn

Screenshot 2024-01-10 at 15 31 33 Screenshot 2024-01-10 at 15 31 49

ALSO:

I have next rule:

'@darraghor/nestjs-typed/injectable-should-be-provided': [
  'error',
  {
    src: ['src/**/*.ts'],
    filterFromPaths: ['node_modules', '.test.', '.spec.', 'jest.config.ts', 'tsconfig.spec.json', 'tsconfig.scripts.json'],
  },
],

and got next error

> nx run api:lint

Linting "api"...

 >  NX   Error while loading rule '@darraghor/nestjs-typed/injectable-should-be-provided': No files matching 'src/**/*.ts' were found.

   Occurred while linting /..****../..[projectRootfolder]../apps/api/jest.config.ts
   Pass --verbose to see the stacktrace.

--verbose add stacktrace, here is first lines:

Error: Error while loading rule '@darraghor/nestjs-typed/injectable-should-be-provided': All files matched by '**/*.ts' are ignored.
Occurred while linting /..****../..[projectRootfolder]../apps/api/jest.config.ts
    at FileEnumerator.iterateFiles (/..****../..[projectRootfolder]../node_modules/eslint/lib/cli-engine/file-enumerator.js:326:27)
roderik commented 8 months ago

I struggled too, but if you define a full path for src in the local folder, it works fine. I manage our monorepo libs folder with a script to update everything everywhere https://gist.github.com/roderik/c83efef5412b7bbd7d76329c02a28338 (specific to us, do not just copy it, but the logic to get the path and update the files is usable

darraghoriordan commented 8 months ago

i don't use NX sorry. I imagine it does all sorts of things with caching and file locations. If you get a chance to investigate and fix with a PR, it would help all nx users.

otherwise you should able to turn off this rule with '@darraghor/nestjs-typed/injectable-should-be-provided': "off"

ivan-shaban commented 1 month ago

Big thanks to @roderik, so as i understand we can add next:

{
  "extends": ["../../.eslintrc.json"],
  "ignorePatterns": ["!**/*"],
  "overrides": [
    {
      "files": ["**/*.ts"],
      "extends": ["plugin:@darraghor/nestjs-typed/recommended"],
      "plugins": ["@darraghor/nestjs-typed"],
      "rules": {
        "@darraghor/nestjs-typed/injectable-should-be-provided": [
          "error",
          {
            "src": ["apps/server/src/**/*.ts"],
            "filterFromPaths": ["node_modules"]
          }
        ]
      },
      "parserOptions": {
        "project": ["apps/server/tsconfig.*?.json"]
      }
    },
    {
      "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
      "rules": {}
    },
    {
      "files": ["*.ts", "*.tsx"],
      "rules": {}
    },
    {
      "files": ["*.js", "*.jsx"],
      "rules": {}
    }
  ]
}

Where apps/server path to your module.

Also i think it could be added to basic docs, because it is not obvious.

darraghoriordan commented 1 month ago

Big thanks to @roderik, so as i understand we can add next:

{
  "extends": ["../../.eslintrc.json"],
  "ignorePatterns": ["!**/*"],
  "overrides": [
    {
      "files": ["**/*.ts"],
      "extends": ["plugin:@darraghor/nestjs-typed/recommended"],
      "plugins": ["@darraghor/nestjs-typed"],
      "rules": {
        "@darraghor/nestjs-typed/injectable-should-be-provided": [
          "error",
          {
            "src": ["apps/server/src/**/*.ts"],
            "filterFromPaths": ["node_modules"]
          }
        ]
      },
      "parserOptions": {
        "project": ["apps/server/tsconfig.*?.json"]
      }
    },
    {
      "files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
      "rules": {}
    },
    {
      "files": ["*.ts", "*.tsx"],
      "rules": {}
    },
    {
      "files": ["*.js", "*.jsx"],
      "rules": {}
    }
  ]
}

Where apps/server path to your module.

Also i think it could be added to basic docs, because it is not obvious.

Do you use this in a commercial settings? If so can you get some of your paid time to submit a PR to update docs? šŸ™