Nitpicky ESLint rules.
npm install -D eslint typescript-eslint eslint-plugin-nestjs-pedantic
See more: Configuring Plugins.
To use the recommended configuration:
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:
import nestjsPedantic from "eslint-plugin-nestjs-pedantic";
export default [
// ...
...nestjsPedantic.configs.recommendedSwc,
];Make sure to
To turn on every rule:
import nestjsPedantic from "eslint-plugin-nestjs-pedantic";
export default [
// ...
...nestjsPedantic.configs.all,
];💼 Configurations enabled in.
🌐 Set in the all configuration.
✅ Set in the recommended configuration.
⚡ Set in the recommendedSwc configuration.
🔧 Automatically fixable by the --fix 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 |
🌐 ✅ ⚡ | 💡 | |
| no-unused-route-params | Disallow unused route parameters | 🌐 ✅ ⚡ | 💡 | |
| route-convention | Keep a convention when decorating routes | 🌐 ✅ ⚡ | 🔧 | 💡 |
| safe-route-params | Ensure safe usage of the @Param 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:
Alternatively, you can define the type helper yourself in any .d.ts file which is included in your TypeScript project:
declare type Circular<T> = T;
{ // ... "compilerOptions": { // ... "types": [/* ... */ "eslint-plugin-nestjs-pedantic/circular"], }, }