From 973bf5b99a7364a451d99896d5ca2ee89268d5d5 Mon Sep 17 00:00:00 2001 From: Ed Sanders Date: Mon, 16 Mar 2020 12:57:28 +0000 Subject: [PATCH] Follow-up #186: Actually merge `no-undelegate` into `no-delegate` Part of #163 --- docs/no-delegate.md | 2 +- rules/no-delegate.js | 9 +++++++-- test-all/methods.js | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/docs/no-delegate.md b/docs/no-delegate.md index 122af3b7..328ff426 100644 --- a/docs/no-delegate.md +++ b/docs/no-delegate.md @@ -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`. diff --git a/rules/no-delegate.js b/rules/no-delegate.js index c78e1dcd..c5049471 100644 --- a/rules/no-delegate.js +++ b/rules/no-delegate.js @@ -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' + ) ); diff --git a/test-all/methods.js b/test-all/methods.js index 12473e62..c68f29f0 100644 --- a/test-all/methods.js +++ b/test-all/methods.js @@ -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();