eslint-plugin-consistent-subscribe
ESLint rule, checking pairing subscriptions
Installation
You'll first need to install ESLint:
$ npm i eslint --save-dev
Next, install eslint-plugin-consistent-subscribe
:
$ npm install eslint-plugin-consistent-subscribe --save-dev
Note: If you installed ESLint globally (using the -g
flag) then you must also install eslint-plugin-consistent-subscribe
globally.
Usage
Add consistent-subscribe
to the plugins section of your .eslintrc
configuration file. You can omit the eslint-plugin-
prefix:
{
"plugins": [
"consistent-subscribe"
]
}
Then configure the rules you want to use under the rules section.
{
"rules": {
"consistent-subscribe/consistent-subscribe": 2
}
}
Supported Rules
consistent-subscribe
Rule Details
This rule aims to...
Examples of incorrect code for this rule:
$('body').on('click', onClick);
Examples of correct code for this rule:
$('body').on('click', onClick);
setTimeout(() => {
$('body').off('click', onClick);
}, 1000);
Options
This rule takes a list of objects, where each object describes a separate API subscription.
Default value is:
-
open name of subscribe method, i.e. on/subscribe/addEventListener
-
close name of unsubscribe method, i.e. off/unsubscribe/removeEventListener
-
contextEquality. default true - need check, that listened object strict equal
The following patterns are not warnings:
$('body').on('click', onClick);
$(document.body).off('click', onClick);
-
openArgumentsEquality/closeArgumentsEquality. default true - arguments should strict equal
If need check not all arguments, this is array of indexed arguments for check\
The following patterns are considered warnings:
$('body').on('click', onClick);
$('body').off('click');
The following patterns are not warnings:
$('body').on('click', onClick);
$('body').off('click');
Author
© 2016 Viktor Gvozdev gvozdev.viktor@gmail.com and contributors.
License
Released under the MIT license.