Skip to content

Guardrails to prevent bad practices or do some serious mistakes when using NestJS Moongose or ORMs.

Notifications You must be signed in to change notification settings

aashutoshrathi/eslint-plugin-nestjs-orm

Repository files navigation

eslint-plugin-nestjs-orm

npm-badge GitHub stars npm

Guardrails to prevent bad practices or do some serious mistakes when using NestJS Moongose or ORMs.

Motivation 💡

No one likes unused variables, and we remove them. But with Mongoose there is a catch, if you attach inject model to non-model variable accidentally, you will get no error, but you will get a bug. This plugin will help you to avoid this.

One such incident is shown below:

Before After
Before After

Installation 🛠️

You'll first need to install ESLint:

npm i eslint --save-dev

Next, install eslint-plugin-nestjs-orm:

npm install eslint-plugin-nestjs-orm --save-dev

Usage 🚀

Add nestjs-orm to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "nestjs-orm"
    ]
}

Then configure the rules you want to use under the rules section.

{
    "rules": {
        "nestjs-orm/mongoose-no-bad-model-injection": "error"
    }
}

Tools Used 💪🏻