0.0.5 • Published 9 months ago

eslint-plugin-optional-params v0.0.5

Weekly downloads
-
License
ISC
Repository
github
Last release
9 months ago

eslint-plugin-optional-params

A ESLint plugin that allows you to limit the number of optional params a function may have. Works with:

  • function declarations
  • function expressions
  • arrow functions
  • class methods
  • class properties (class methods declared as arrow functions)
  • function type declarations
  • function declarations within interfaces
  • arrow function declarations within interfaces
  • abstract methods
  • abstract properties (abstract methods declared as arrow functions)

Installation

npm i -D eslint-plugin-optional-params

Rules

  • max-optional-params: controls the count of optional params a function may have.

    • Example:

      // 'optional-params/max-optional-params': ['error', 1]
      
      // ❌
      // Only 1 optional param(s) are allowed (eslint)
      function buildMech(head: Head, core: Core, arms?: Arm[], legs?: Leg[]): Mech
      
      // ✅
      // A fix
      function buildMech(params: { head: Head, core: Core, arms?: Arm[], legs?: Leg[] }): Mech
    • When to use it:
      The rule must be used if multiple optional params are dissatisfactory.
      To pass a succeeding optional param a redundant undefined value should be passed as an argument for the preceding param.

Usage

  • The plugin must be added to the plugins array in a .eslintrc.* config.
  • the eslint-plugin part of the name can be omitted.
// .eslintrc.js
module.exports = {
  // ...
  plugins: [/* other plugins */, 'optional-params']
  rules: {
    // ...
    'optional-params/max-optional-params': ['error', 2],
  }
  // ...
}
0.0.5

9 months ago

0.0.4

9 months ago

0.0.3

9 months ago

0.0.2

9 months ago

0.0.1

9 months ago