An ESLint plugin for NestJS, with pedantic rules
npm install eslint-plugin-nestjs-pedanticNitpicky ESLint rules.
```
npm install -D eslint typescript-eslint eslint-plugin-nestjs-pedantic
See more: Configuring Plugins.
To use the recommended configuration:
`js
import nestjsPedantic from "eslint-plugin-nestjs-pedantic";
export default [
// ...
...nestjsPedantic.configs.recommended,
];
`
If you use SWC to compile Nest (i.e. you use --builder swc or have "builder": "swc" in your nest-cli.json), use the recommended SWC configuration:
`js
import nestjsPedantic from "eslint-plugin-nestjs-pedantic";
export default [
// ...
...nestjsPedantic.configs.recommendedSwc,
];
`
Make sure to
To turn on every rule:
`js
import nestjsPedantic from "eslint-plugin-nestjs-pedantic";
export default [
// ...
...nestjsPedantic.configs.all,
];
`
πΌ Configurations enabled in.\
π Set in the all configuration.\recommended
β
Set in the configuration.\recommendedSwc
β‘ Set in the configuration.\--fix
π§ Automatically fixable by the CLI option.\
π‘ Manually fixable by editor suggestions.
| NameΒ Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β Β | Description | πΌ | π§ | π‘ |
| :------------------------------------------------------------------------------------------------------------------------ | :----------------------------------------------------------------------------------- | :------- | :-- | :-- |
| match-methods-to-routes | Match method names to the decorated API routes | π β
β‘ | π§ | |
| no-duplicate-route-params | Disallow duplicate route parameters | π β
β‘ | | |
| no-mismatched-forward-refs | Ensure the type of any injected forwardRefs matches the actual forwarded reference | π β
β‘ | | π‘ |@Param
| no-unused-route-params | Disallow unused route parameters | π β
β‘ | | π‘ |
| route-convention | Keep a convention when decorating routes | π β
β‘ | π§ | π‘ |
| safe-route-params | Ensure safe usage of the decorator | π β
β‘ | | π‘ |
| wrap-circular-dependencies | Wrap circular dependencies to prevent SWC compilation issues | π β‘ | π§ | π‘ |
If you turn on the wrap-circular-dependencies rule and want the auto-fix (which uses a Circular type helper) to work, you'll need to setup your tsconfig.json to recognize it as a global type:
`jsonc`
{
// ...
"compilerOptions": {
// ...
"types": [/ ... / "eslint-plugin-nestjs-pedantic/circular"],
},
}
Alternatively, you can define the type helper yourself in any .d.ts file which is included in your TypeScript project:
`ts``
declare type Circular