https://github.com/boneskull/eslint-plugin-prototype-chain
https://github.com/boneskull/eslint-plugin-prototype-chain
Last synced: 11 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/boneskull/eslint-plugin-prototype-chain
- Owner: boneskull
- License: mit
- Archived: true
- Created: 2015-12-06T06:01:13.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-11-23T20:44:55.000Z (about 9 years ago)
- Last Synced: 2025-03-21T04:18:28.058Z (11 months ago)
- Language: JavaScript
- Size: 24.4 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 25
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# eslint-prototype-chain
> ESLint rule to optimize prototype chain lookups
## Summary
Repeatedly looking up values deep in the prototype chain can be less-than-performant--especially if [getters](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/defineProperty) are defined. Creating a variable to reference the value can speed things up.
This [ESLint](http://eslint.org) rule will tell you if you're doing this too much.
## Installation
```shell
$ npm install -D eslint eslint-plugin-prototype-chain
```
## Usage
Add this to your `.eslintrc`, assuming it's a JSON file:
```json
{
"plugins": [
"prototype-chain"
],
"prototype-chain/prototype-chain": [2, 1, 1]
}
```
The above configuration will cause an ESLint error when, *in the same scope*:
- You use the same object member expression (`foo.bar`) OR the same "this" expression (`this.bar`) more than one (1) time (that's the 2nd array item), AND
- You use one (1) member in the chain
A configuration such as this:
```json
{
"prototype-chain/prototype-chain": [2, 2, 3]
}
```
would cause an ESLint error when, *in the same scope*:
- You use the same object member expression (`foo.bar`) OR the same "this" expression (`this.bar`) more than one (2) times, AND
- You use one (2) members in the chain
That means repeating `foo.bar` will *not* throw an error. Repeating `foo.bar.baz` one time will not cause an error, but repeating it two times will.
Hope that makes sense!
## Fair Warning
There are tests, but I haven't tried this against much real-world code yet.
## License
© 2015 [Christopher Hiller](https://boneskull.com). Licensed MIT.