npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@darraghor/eslint-plugin-nestjs-typed

v5.0.30

Published

Eslint rules for nestjs projects

Downloads

210,838

Readme

commit npm npm-tag size types

A note on versions

Note: doesn't support eslint 9 yet!

  • Version 6.x supports Eslint version >=8.x and typescript eslint parser ^8
  • Version 5.x supports Eslint version >=8.x and typescript eslint parser ^7
  • Version 4.x supports Eslint version >=8.x and typescript eslint parser ^6
  • Version 3.x supports Eslint version >=8.x and typescript eslint parser ^5
  • Version 2.x supports Eslint version <=7.x and typescript eslint parser ^4

There are breaking changes between versions of ts-eslint.

typescript eslint parser supports a range of typescript versions but there can be a delay in supporting the latest versions.

This plugin only supports typescript up to the version typescript eslint parser supports. See https://github.com/typescript-eslint/typescript-eslint#supported-typescript-version for the versions.

Have an idea for a rule?

Awesome! Click here to submit a new issue!

Index of available rules

| Category | Rule | is on in recommended ruleset? | | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------- | | Nest Modules and Dependency Injection | provided-injected-should-match-factory-parameters | ✅ | | | injectable-should-be-provided | ✅ | | | | | | Nest Swagger | api-property-matches-property-optionality | ✅ | | | controllers-should-supply-api-tags | ✅ | | | api-method-should-specify-api-response | ✅ | | | api-method-should-specify-api-operation | ✅ | | | api-enum-property-best-practices | ✅ | | | api-property-returning-array-should-set-array | ✅ | | | | | | Preventing bugs | param-decorator-name-matches-route-param | ✅ | | | validate-nested-of-array-should-set-each | ✅ | | | validated-non-primitive-property-needs-type-decorator | ✅ | | | all-properties-are-whitelisted | ✅ | | | all-properties-have-explicit-defined | ✅ | | | no-duplicate-decorators | ✅ | | | should-specify-forbid-unknown-values | ✅ | | | | | | Security | api-methods-should-be-guarded | ❌ | | | | | | Code Consistency | sort-module-metadata-arrays | ❌ |

The "recommended" ruleset are the default rules that are turned on when you configure the plugin as described in this document.

The name "recommended" is an eslint convention, you can safely use the rules not in that list, they are just more opinionated.

Who is this package for?

If you use NestJs (https://nestjs.com/) these ESLint rules will help you to prevent common bugs and issues in NestJs applications.

They mostly check that you are using decorators correctly.

The primary groupings of rules in this plugin are...

1. Detect Nest Dependency Injection issues

The Nest DI is declarative and if you forget to provide an injectable you wont see an error until run time. Nest is good at telling you where these are but sometimes it's not.

In particular if you're using custom providers the errors can be really tricky to figure out because they won't explicitly error about mismatched injected items, you will just get unexpected operation.

These are described in the "Common Errors" section of the nest js docs.

2. Using Open Api / Swagger decorators and automatically generating a clients

When working with NestJS I generate my front end client and models using the swagger/Open API specification generated directly from the nest controllers and models.

I have a bunch of rules here that enforce strict Open API typing with decorators for NestJs controllers and models.

These rules are opinionated, but necessary for clean model generation if using an Open Api client generator later in your build.

3. Helping prevent bugs

There are some tightly coupled but untyped decorators and things like that in nest that will catch you out if your not careful. There are some rules to help prevent issues that have caught me out before.

4. Security

There is a CVE for class-transformer when using random javascript objects. You need to be careful about configuring the ValidationPipe in NestJs. See https://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2019-18413 https://github.com/typestack/class-validator/issues/438

To install

The plugin is on npm here: https://www.npmjs.com/package/@darraghor/eslint-plugin-nestjs-typed You can see how the rules are used in this NestJS project: https://github.com/darraghoriordan/use-miller

npm install --save-dev @darraghor/eslint-plugin-nestjs-typed

// or

yarn add -D @darraghor/eslint-plugin-nestjs-typed
// or

pnpm add -D @darraghor/eslint-plugin-nestjs-typed

If you don't already have class-validator you should install that

npm install class-validator

// or

yarn add class-validator

// or

pnpm add class-validator

To configure

Update your eslint with the plugin import and add the recommended rule set

module.exports = {
    env: {
        es6: true,
    },
    extends: ["plugin:@darraghor/nestjs-typed/recommended"],
    parser: "@typescript-eslint/parser",
    parserOptions: {
        project: ["./tsconfig.json"],
        sourceType: "module",
        ecmaVersion: "es2019",
    },
    plugins: ["@darraghor/nestjs-typed"],
};

Note: the injectables test scans your whole project. It's best to filter out ts things that don't matter - use filterFromPaths configuration setting for this. See the rule documentation for more info.

There are some defaults already applied.

Note: You can easily turn off all the swagger rules if you don't use swagger by adding the no-swagger rule set AFTER the recommended rule set.

// all the other config
    extends: ["plugin:@darraghor/nestjs-typed/recommended",
    "plugin:@darraghor/nestjs-typed/no-swagger"
    ],
 // more config

Disable a single rule with the full name e.g. in your eslint configuration...

   rules: {
   "@darraghor/nestjs-typed/api-property-returning-array-should-set-array":
            "off",
   }