https://github.com/wentout/eslint-plugin-no-arrow-this
eslint plugin for warning "this" inside of arrow functions
https://github.com/wentout/eslint-plugin-no-arrow-this
es6 eslint-plugin eslint-rules eslintplugin
Last synced: 4 months ago
JSON representation
eslint plugin for warning "this" inside of arrow functions
- Host: GitHub
- URL: https://github.com/wentout/eslint-plugin-no-arrow-this
- Owner: wentout
- Created: 2018-08-07T18:17:50.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-01-30T22:58:38.000Z (over 7 years ago)
- Last Synced: 2025-10-06T09:10:54.101Z (9 months ago)
- Topics: es6, eslint-plugin, eslint-rules, eslintplugin
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/eslint-plugin-no-arrow-this
- Size: 15.6 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# eslint-plugin-no-arrow-this
## Proposal
This is a [eslint](https://eslint.org/) plugin for warning "this" keyword inside of arrow functions. The key is about to get rid of using `this` in sort of `global` context.
For example, you have a code with regular function:
```javascript
(function () {
var me = this;
console.log(me);
}.bind(123))();
```
And then, somehow, may be after re-factoring, you will change that [**regular function**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function) to [**arrow function**](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions):
```javascript
(() => {
var me = this;
console.log(me);
}).bind(123)();
```
So, starting from that pont __`me`__ no longer follows to the binded context, and receives **`global`** or **`window`** instead.
This plugin will help you to find this conditions.
## Example .eslintrc configuration
### installation
```bash
$ npm i eslint-plugin-no-arrow-this
```
### typical config *for everything*
```javascript
"plugins": [
// ... other plugins
"eslint-plugin-no-arrow-this"
],
// ... other stuff
"rules": {
// ... other rules
"no-arrow-this/no-arrow-this": "warn"
}
```
So far here you will receive warning on `eslint`.
### How to check ONLY global~window context mess
```javascript
"no-arrow-this/no-arrow-this": ["warn", {
onlyGlobals : true
}]
```
## to play with this rule
on [astexplorer.net](https://astexplorer.net/#/gist/1b0e7979d799635ae74f6bb15acf6c5a/a83c95146598f1ad828646ac71d556a8a5a8b839)