Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-use-decorator

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-use-decorator

This is a custom plugin for eslint which enforces the use of decorators on methods.

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

eslint-plugin-use-decorator

Version npm Dependencies peerDependencies Known Vulnerabilities License

This is a custom plugin for eslint which enforces the use of decorators on methods.

Note

This only works with the @typescript-eslint plugin

Installation

npm install --save-dev eslint-plugin-use-decorator

Usage

Add this to your .eslintrc

// .eslintrc
{
  "plugins": ["use-decorator"],
  "rules": {
    "use-decorator/use-decorator": [1, {
      "params": [
        {
          "name": "assertParameter",
          "public": true
        }
      ],
      "methods": [
        {
          "name": "assert",
          "public": true
        },
        {
          "name": "errorcatch",
          "async": true,
          "private": true
        }
      ],
      "class": [
        {
          "superClass": ["Vue", "Mixins"],
          "name": "Component"
        },
      ]
    }]
  }
}

Now methods and its parameters are checked for their decorators. Above rule would enforce following custom decorators:

class SomeClass {
  @assert
  someMethod(
    @assertParameter
      someParameter: number
  ): number {
    return someParameter;
  }
  
  @errorcatch
  private async somePrivateAsyncMethod(
      someParameter: number
  ): Promise<number> {
    return someParameter;
  }
  
  /**
   *  This one does not need a decorator, because its only async.
   *  It would need to be private as well for the linting to take effect.
   */
  async someAsyncMethod(
      someParameter: number
  ): Promise<number> {
    return someParameter;
  }
}

The options object looks like this:

Options

{
  "params": [
    {
      "name": "string",
      "private?": "boolean", // default: false
      "public?": "boolean", // default: false
      "async?": "boolean", // default: false, 
      "static?": "boolean" // default: false
    }
  ],
  "methods": [
    {
      "name": "assert",
      "private?": "boolean", // default: false
      "public?": "boolean", // default: false
      "async?": "boolean", // default: false
      "static?": "boolean" // default: false
    }
  ]
}

Keywords

FAQs

Package last updated on 07 Feb 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc