Skip to content

globetro/eslint-plugin-private-props

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

eslint-plugin-private-props

Assume all properties that begin with an underscore and the handle prefix (specific case for React components) are private and generate errors for unused or undeclared properties.

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-private-props:

$ npm install eslint-plugin-private-props --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-private-props globally.

Usage

Add private-props to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
  "plugins": [
    "private-props"
  ]
}

Then configure the rules you want to use under the rules section.

{
  "rules": {
    "private-props/no-unused-or-undeclared": 2
  }
}

Supported Rules

private-props/no-unused-or-undeclared

Disallow unused or undeclared private properties

Example:

class Foo {
  _init() { // Error: `_init` is unused
    console.log('init');
  }

  bar() {
    this._foo = 1; // Error: `_foo` is unused
    this._baz(); // Error: `_baz` is undefined
  }
}

private-props/no-use-outside

Disallow use of private properties outside of own object

this._bar(); // ok
foo._bar(); // Error: `_bar` is used outside of own object

Options

privateMatchers Change the default set of matchers for private properties

Default:

{
  "rules": {
    "private-props/no-unused-or-undeclared": [2, {
      "privateMatchers": [
        "^_", 
        "^handle[A-Z]"
      ]
    }]
  }
}

About

Eslint rules for private properties

Resources

Stars

Watchers

Forks

Packages

No packages published