nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: xjamundx/eslint-plugin-promise
Pull request #27 (2016-10-10 00:12:31)

fix always-return error with shortcircuit syntax
Fix issue #26


Patch:
diff --git a/rules/always-return.js b/rules/always-return.js
index cfc4164..b95f796 100644
--- a/rules/always-return.js
+++ b/rules/always-return.js
@@ -104,10 +104,17 @@ module.exports = {
           return
         }
 
-        var finalBranchIDs = path.finalSegments.map(x => x.id)
-        finalBranchIDs.forEach((id) => {
+        path.finalSegments.forEach((segment) => {
+          var id = segment.id
           var branch = funcInfo.branchInfoMap[id]
           if (!branch.good) {
+            // check shortcircuit syntax like `x && x()` and `y || x()``
+            var prevSegments = segment.prevSegments
+            for (var ii = prevSegments.length - 1; ii >= 0; --ii) {
+              var prevSegment = prevSegments[ii]
+              if (funcInfo.branchInfoMap[prevSegment.id].good) return
+            }
+
             context.report({
               message: 'Each then() should return a value or throw',
               loc: branch.loc


Test patch:
diff --git a/test/always-return.test.js b/test/always-return.test.js
index e89b281..a26f820 100644
--- a/test/always-return.test.js
+++ b/test/always-return.test.js
@@ -24,7 +24,9 @@ ruleTester.run('always-return', rule, {
     { code: 'hey.then(x => { var f = function() { }; return f; })', parserOptions: parserOptions },
     { code: 'hey.then(x => { if (x) { return x; } else { return x; } })', parserOptions: parserOptions },
     { code: 'hey.then(x => { return x; var y = "unreachable"; })', parserOptions: parserOptions },
-    { code: 'hey.then(x => { return; }, err=>{ log(err); })', parserOptions: parserOptions }
+    { code: 'hey.then(x => { return; }, err=>{ log(err); })', parserOptions: parserOptions },
+    { code: 'hey.then(x => { return x && x(); }, err=>{ log(err); })', parserOptions: parserOptions },
+    { code: 'hey.then(x => { return x.y || x(); }, err=>{ log(err); })', parserOptions: parserOptions }
   ],
 
   invalid: [
Repository: xjamundx/eslint-plugin-promise
Pull request #32 (2016-10-18 16:05:09)

Add option for multiple terminationMethods
An array can now be passed for the terminationMethod option.
Allows use of multiple valid terminators.

Bluebird has the `asCallback` method which is also a valid terminator in addition to `catch`.


Patch:
diff --git a/README.md b/README.md
index 1e01167..7fbd508 100644
--- a/README.md
+++ b/README.md
@@ -44,6 +44,16 @@ You can pass an `{ allowThen: true }` as an option to this rule
 You can pass a `{ terminationMethod: 'done' }` as an option to this rule
  to require `done()` instead of `catch()` at the end of the promise chain.
  This is useful for many non-standard Promise implementations.
+ 
+You can also pass an array of methods such as
+ `{ terminationMethod: ['catch',  'asCallback', 'finally'] }`.
+ 
+ This will allow any of
+```js
+Promise.resolve(1).then(() => { throw new Error('oops') }).catch(logerror)
+Promise.resolve(1).then(() => { throw new Error('oops') }).asCallback(cb)
+Promise.resolve(1).then(() => { throw new Error('oops') }).finally(cleanUp)
+```
 
 ### `always-return`
 
diff --git a/rules/catch-or-return.js b/rules/catch-or-return.js
index f76d086..de9bfdd 100644
--- a/rules/catch-or-return.js
+++ b/rules/catch-or-return.js
@@ -33,6 +33,10 @@ module.exports = {
     var allowThen = options.allowThen
     var terminationMethod = options.terminationMethod || 'catch'
 
+    if (typeof terminationMethod === 'string') {
+      terminationMethod = [terminationMethod]
+    }
+
     return {
       ExpressionStatement: function (node) {
         if (!isPromise(node.expression)) {
@@ -52,7 +56,7 @@ module.exports = {
         // somePromise.catch()
         if (node.expression.type === 'CallExpression' &&
           node.expression.callee.type === 'MemberExpression' &&
-          node.expression.callee.property.name === terminationMethod
+          terminationMethod.indexOf(node.expression.callee.property.name) !== -1
         ) {
           return
         }


Test patch:
diff --git a/test/catch-or-return.test.js b/test/catch-or-return.test.js
index fa925ac..06bc395 100644
--- a/test/catch-or-return.test.js
+++ b/test/catch-or-return.test.js
@@ -45,8 +45,12 @@ ruleTester.run('catch-or-return', rule, {
     { code: 'frank.then(go).then(to).then(pewPew, jail)', options: [{ 'allowThen': true }] },
 
     // terminationMethod=done - .done(null, fn)
-    { code: 'frank().then(go).done()', options: [{ 'terminationMethod': 'done' }] }
+    { code: 'frank().then(go).done()', options: [{ 'terminationMethod': 'done' }] },
 
+    // terminationMethod=[catch, done] - .done(null, fn)
+    { code: 'frank().then(go).catch()', options: [{ 'terminationMethod': ['catch', 'done'] }] },
+    { code: 'frank().then(go).done()', options: [{ 'terminationMethod': ['catch', 'done'] }] },
+    { code: 'frank().then(go).finally()', options: [{ 'terminationMethod': ['catch', 'finally'] }] }
   ],
 
   invalid: [
Repository: xjamundx/eslint-plugin-promise
Pull request #68 (2017-10-01 05:46:22)

adding exceptions to no-callback-in-promise
see https://github.com/xjamundx/eslint-plugin-promise/issues/43 for more details


Patch:
diff --git a/rules/lib/is-callback.js b/rules/lib/is-callback.js
index 609fde9..0060e26 100644
--- a/rules/lib/is-callback.js
+++ b/rules/lib/is-callback.js
@@ -1,9 +1,9 @@
 var isNamedCallback = require('./is-named-callback')
 
-function isCallingBack (node) {
+function isCallingBack (node, exceptions) {
   var isCallExpression = node.type === 'CallExpression'
   var callee = node.callee || {}
-  var nameIsCallback = isNamedCallback(callee.name)
+  var nameIsCallback = isNamedCallback(callee.name, exceptions)
   var isCB = isCallExpression && nameIsCallback
   return isCB
 }
diff --git a/rules/lib/is-named-callback.js b/rules/lib/is-named-callback.js
index 98ee04c..bbe40a2 100644
--- a/rules/lib/is-named-callback.js
+++ b/rules/lib/is-named-callback.js
@@ -1,6 +1,9 @@
 var callbacks = ['done', 'cb', 'callback', 'next']
 
-module.exports = function isNamedCallback (potentialCallbackName) {
+module.exports = function isNamedCallback (potentialCallbackName, exceptions) {
+  for (var i = 0; i < exceptions.length; i++) {
+    callbacks = callbacks.filter(function (item) { return item !== exceptions[i] })
+  }
   return callbacks.some(function (trueCallbackName) {
     return potentialCallbackName === trueCallbackName
   })
diff --git a/rules/no-callback-in-promise.js b/rules/no-callback-in-promise.js
index 939f834..c1e3f6c 100644
--- a/rules/no-callback-in-promise.js
+++ b/rules/no-callback-in-promise.js
@@ -10,7 +10,9 @@ var isCallback = require('./lib/is-callback')
 module.exports = function (context) {
   return {
     CallExpression: function (node) {
-      if (!isCallback(node)) {
+      var options = context.options[0] || {}
+      var exceptions = options.exceptions || []
+      if (!isCallback(node, exceptions)) {
         // in general we send you packing if you're not a callback
         // but we also need to watch out for whatever.then(cb)
         if (hasPromiseCallback(node)) {


Test patch:
diff --git a/test/no-callback-in-promise.js b/test/no-callback-in-promise.js
index df85f47..5ab80bb 100644
--- a/test/no-callback-in-promise.js
+++ b/test/no-callback-in-promise.js
@@ -16,7 +16,10 @@ ruleTester.run('no-callback-in-promise', rule, {
 
     // arrow functions and other things
     {code: 'let thing = (cb) => cb()', parserOptions: {ecmaVersion: 6}},
-    {code: 'doSomething(err => cb(err))', parserOptions: {ecmaVersion: 6}}
+    {code: 'doSomething(err => cb(err))', parserOptions: {ecmaVersion: 6}},
+
+    // exceptions test
+    {code: 'a.then(() => next())', parserOptions: {ecmaVersion: 6}, options: [{ 'exceptions': ['next'] }]}
   ],
 
   invalid: [