# eslint-plugin-no-constructor-bind

> Prefer class arrow methods to binding in the constructor

Latest version **2.0.4** (published 2020-10-27) · ISC license · 0 weekly downloads

## Install

```sh
npm install eslint-plugin-no-constructor-bind
pnpm add eslint-plugin-no-constructor-bind
yarn add eslint-plugin-no-constructor-bind
bun add eslint-plugin-no-constructor-bind
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.4 |
| Published | 2020-10-27 |
| First published | 2018-04-26 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | separate (@types/eslint-plugin-no-constructor-bind) |
| Module format | CommonJS |
| Node | >=8.0.0 |
| Dependencies | 1 |
| Unpacked size | 49.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 12 |
| Author | Mark Battersby |
| Maintainers | markalfred |
| Keywords | eslint, eslintplugin, eslint-plugin |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-no-constructor-bind
- Repository: https://github.com/markalfred/eslint-plugin-no-constructor-bind
- Homepage: https://github.com/markalfred/eslint-plugin-no-constructor-bind#readme
- Issues: https://github.com/markalfred/eslint-plugin-no-constructor-bind/issues
- npm.io page: https://npm.io/package/eslint-plugin-no-constructor-bind

## Dependencies (1)

- [requireindex](https://npm.io/package/requireindex.md) ~1.2.0

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 2.0.4 (latest) — 2020-10-27
- 2.0.3 — 2020-08-09
- 2.0.2 — 2020-06-25
- 2.0.1 — 2020-06-17
- 2.0.0 — 2020-05-07
- 1.2.8 — 2020-03-16
- 1.2.7 — 2019-10-04
- 1.2.6 — 2019-08-26
- 1.2.4 — 2019-04-19
- 1.2.3 — 2019-03-13
- 1.2.2 — 2019-03-11
- 1.2.1 — 2018-08-02
- 1.2.0 — 2018-08-02
- 1.1.0 — 2018-08-02
- 1.0.1 — 2018-08-01
- … 1 more at https://npm.io/package/eslint-plugin-no-constructor-bind/versions

## README

# eslint-plugin-no-constructor-bind

[![Build Status](https://travis-ci.org/markalfred/eslint-plugin-no-constructor-bind.svg?branch=master)](https://travis-ci.org/markalfred/eslint-plugin-no-constructor-bind)
[![Coverage Status](https://coveralls.io/repos/github/markalfred/eslint-plugin-no-constructor-bind/badge.svg?branch=master)](https://coveralls.io/github/markalfred/eslint-plugin-no-constructor-bind?branch=master)
[![Known Vulnerabilities](https://snyk.io/test/github/markalfred/eslint-plugin-no-constructor-bind/badge.svg?targetFile=package.json)](https://snyk.io/test/github/markalfred/eslint-plugin-no-constructor-bind?targetFile=package.json)

Prefer class properties to equivalent setup steps taken in a class' constructor method.

```js
// Bad:
class User {
  constructor() {
    this.greet = this.greet.bind(this)
  }
  greet() { return 'Hello' }
}

// Good:
class User {
  greet = () => 'hello'
}
```

Use `no-constructor-bind` to eliminate bound functions in your constructor.
Use `no-constructor-state` to eliminate initial state setting in your constructor.
Doing this, most likely you'll be able to use ESLint's builtin `no-useless-constructor` to remove many constructors in your app.

## Installation

You'll first need to install [ESLint](http://eslint.org):

```
$ npm i eslint --save-dev
```

Next, install `eslint-plugin-no-constructor-bind`:

```
$ npm install eslint-plugin-no-constructor-bind --save-dev
```

**Note:** If you installed ESLint globally (using the `-g` flag) then you must also install `eslint-plugin-no-constructor-bind` globally.

## Usage

Add `no-constructor-bind` to the plugins section of your `.eslintrc` configuration file. You can omit the `eslint-plugin-` prefix:

```json
{
  "plugins": ["no-constructor-bind"]
}
```

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

```json
{
  "rules": {
    "no-constructor-bind/no-constructor-bind": "error",
    "no-constructor-bind/no-constructor-state": "error"
  }
}
```

## Supported Rules

* no-constructor-bind (:wrench:) — Use class arrow functions instead of binding in the constructor
* no-constructor-state (:wrench:) — Use class property instead of setting initial state in the constructor

---
_Source: https://npm.io/package/eslint-plugin-no-constructor-bind · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
