Skip to content

Commit

Permalink
Follow-up #186: Actually merge no-undelegate into no-delegate
Browse files Browse the repository at this point in the history
Part of #163
  • Loading branch information
edg2s committed Mar 16, 2020
1 parent 1d899ad commit 973bf5b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/no-delegate.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# no-delegate

Disallows the `.delegate` method. Prefer `$.on`/`EventTarget#addEventListener` to `$.delegate`.
Disallows the `.delegate`/`.undelegate` methods. Prefer `$.on`/`$.off` or `EventTarget#addEventListener`/`removeEventListener`.

This rule is enabled in `plugin:no-jquery/deprecated-3.0`.

Expand Down
9 changes: 7 additions & 2 deletions rules/no-delegate.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@
const utils = require( './utils.js' );

module.exports = utils.createCollectionMethodRule(
'delegate',
'Prefer `$.on`/`EventTarget#addEventListener` to `$.delegate`'
[ 'delegate', 'undelegate' ],
( node ) => node === true ?
'Prefer `$.on`/`$.off` or `EventTarget#addEventListener`/`removeEventListener`' : (
node.callee.property.name === 'delegate' ?
'Prefer $.on/EventTarget#addEventListener to $.delegate' :
'Prefer $.off/EventTarget#removeEventListener to $.undelegate'
)
);
2 changes: 1 addition & 1 deletion test-all/methods.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ $x.toggleClass();
$x.trigger();
// eslint-disable-next-line rulesdir/no-bind, rulesdir/no-unbind
$x.unbind();
// eslint-disable-next-line rulesdir/no-undelegate
// eslint-disable-next-line rulesdir/no-delegate, rulesdir/no-undelegate
$x.undelegate();
// eslint-disable-next-line rulesdir/no-wrap
$x.unwrap();
Expand Down

0 comments on commit 973bf5b

Please sign in to comment.