From ff1ee249b566dfedec43a05a7541449f0070a1bc Mon Sep 17 00:00:00 2001 From: Omer Ganim Date: Wed, 16 Sep 2015 15:29:46 +0300 Subject: [PATCH] fix unwrap to not fail when using _.prototype.commit() --- lib/rules/unwrap.js | 6 +----- tests/lib/rules/unwrap.js | 2 ++ 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/rules/unwrap.js b/lib/rules/unwrap.js index 48c550b..6763eae 100644 --- a/lib/rules/unwrap.js +++ b/lib/rules/unwrap.js @@ -13,13 +13,9 @@ module.exports = function (context) { return { CallExpression: function (node) { if (lodashUtil.isEndOfChain(node) && - (lodashUtil.isChainable(node) || (lodashUtil.isExplicitMethodChaining(node) && !lodashUtil.isChainBreaker(node)))) { + ((lodashUtil.isChainable(node) && !lodashUtil.isCallToMethod(node, 'commit')) || (lodashUtil.isExplicitMethodChaining(node) && !lodashUtil.isChainBreaker(node)))) { context.report(node, 'Missing unwrapping at end of chain'); } } }; }; - -module.exports.schema = [ - // JSON Schema for rule options goes here -]; diff --git a/tests/lib/rules/unwrap.js b/tests/lib/rules/unwrap.js index 971e10c..e043980 100644 --- a/tests/lib/rules/unwrap.js +++ b/tests/lib/rules/unwrap.js @@ -20,6 +20,8 @@ ruleTester.run('unwrap', rule, { code: 'var x = _(a).map(f).filter(g).value()' }, { code: 'var x = _.chain(a).map(f).value()' + }, { + code: 'var stillWrapped = _(a).forEach(f).commit();' }], invalid: [{ code: 'var x = _(a).map(f);',