nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: lo1tuma/eslint-plugin-mocha
Pull request #195 (2019-07-08 13:53:04)

Fix no-setup-in-describe to work with arrow functions
Fixes: #158


Patch:
diff --git a/lib/rules/no-setup-in-describe.js b/lib/rules/no-setup-in-describe.js
index d6aa739..3e80b98 100644
--- a/lib/rules/no-setup-in-describe.js
+++ b/lib/rules/no-setup-in-describe.js
@@ -49,6 +49,10 @@ module.exports = function noSetupInDescribe(context) {
         }
     }
 
+    function isParentDescribe(node) {
+        return astUtils.isDescribe(node.parent, additionalSuiteNames(settings));
+    }
+
     return {
         CallExpression(node) {
             const isDescribe = astUtils.isDescribe(node, additionalSuiteNames(settings));
@@ -86,13 +90,13 @@ module.exports = function noSetupInDescribe(context) {
             }
         },
 
-        ArrowFunctionExpression() {
-            if (nesting.length) {
+        ArrowFunctionExpression(node) {
+            if (nesting.length && !isParentDescribe(node)) {
                 nesting.push(FUNCTION);
             }
         },
-        'ArrowFunctionExpression:exit'() {
-            if (nesting.length) {
+        'ArrowFunctionExpression:exit'(node) {
+            if (nesting.length && !isParentDescribe(node)) {
                 nesting.pop();
             }
         }


Test patch:
diff --git a/test/rules/no-setup-in-describe.js b/test/rules/no-setup-in-describe.js
index 6fcb229..986b5af 100644
--- a/test/rules/no-setup-in-describe.js
+++ b/test/rules/no-setup-in-describe.js
@@ -63,6 +63,14 @@ ruleTester.run('no-setup-in-describe', rule, {
                 line: 1,
                 column: 28
             } ]
+        }, {
+            code: 'describe("", () => { a(); });',
+            parserOptions: { ecmaVersion: 2015 },
+            errors: [ {
+                message: 'Unexpected function call in describe block.',
+                line: 1,
+                column: 22
+            } ]
         }, {
             code: 'foo("", function () { a(); });',
             settings: {
Repository: lo1tuma/eslint-plugin-mocha
Pull request #196 (2019-07-08 14:04:10)

Fix no-setup-in-describe to correctly detect describe calls
There was one call of `astUtils.isDescribe` which has been called without the second parameter which caused the function to accept `undefined` as a valid alias for suite function names. Additionally there are cases where we don’t get a node name for `CallExpressions` (e.g. `foo()()`). So in such cases the extracted node name is `undefined` and `isDescribe` will return true due to the above mentioned
bug.

Fixes: #172


Patch:
diff --git a/lib/rules/no-setup-in-describe.js b/lib/rules/no-setup-in-describe.js
index 3e80b98..fcc1873 100644
--- a/lib/rules/no-setup-in-describe.js
+++ b/lib/rules/no-setup-in-describe.js
@@ -49,14 +49,17 @@ module.exports = function noSetupInDescribe(context) {
         }
     }
 
+    function isDescribe(node) {
+        return astUtils.isDescribe(node, additionalSuiteNames(settings));
+    }
+
     function isParentDescribe(node) {
-        return astUtils.isDescribe(node.parent, additionalSuiteNames(settings));
+        return isDescribe(node.parent);
     }
 
     return {
         CallExpression(node) {
-            const isDescribe = astUtils.isDescribe(node, additionalSuiteNames(settings));
-            if (isDescribe) {
+            if (isDescribe(node)) {
                 nesting.push(DESCRIBE);
                 return;
             }
@@ -68,7 +71,7 @@ module.exports = function noSetupInDescribe(context) {
         },
 
         'CallExpression:exit'(node) {
-            if (astUtils.isDescribe(node) || nesting.length && isPureNode(node)) {
+            if (isDescribe(node) || nesting.length && isPureNode(node)) {
                 nesting.pop();
             }
         },
diff --git a/lib/util/ast.js b/lib/util/ast.js
index 6f9a561..7e5845f 100644
--- a/lib/util/ast.js
+++ b/lib/util/ast.js
@@ -28,7 +28,7 @@ function getNodeName(node) {
     return node.name;
 }
 
-function isDescribe(node, additionalSuiteNames) {
+function isDescribe(node, additionalSuiteNames = []) {
     return isCallExpression(node) &&
       describeAliases.concat(additionalSuiteNames).indexOf(getNodeName(node.callee)) > -1;
 }


Test patch:
diff --git a/test/rules/no-setup-in-describe.js b/test/rules/no-setup-in-describe.js
index 986b5af..3109fb1 100644
--- a/test/rules/no-setup-in-describe.js
+++ b/test/rules/no-setup-in-describe.js
@@ -52,6 +52,16 @@ ruleTester.run('no-setup-in-describe', rule, {
                     additionalSuiteNames: [ 'foo' ]
                 }
             }
+        },
+        {
+            code: `describe('', () => {
+              it('', () =>{
+                  foo()();
+                  foo()();
+                  bar();
+              });
+            });`,
+            parserOptions: { ecmaVersion: 2015 }
         }
     ],
Repository: lo1tuma/eslint-plugin-mocha
Pull request #239 (2020-02-18 19:38:39)

Fix max-top-level-suites to ignore generated suites
Fixes: #224.


Patch:
diff --git a/lib/rules/max-top-level-suites.js b/lib/rules/max-top-level-suites.js
index 19fafa3..b88b804 100644
--- a/lib/rules/max-top-level-suites.js
+++ b/lib/rules/max-top-level-suites.js
@@ -26,7 +26,6 @@ module.exports = {
         ]
     },
     create(context) {
-        const stack = [];
         const topLevelDescribes = [];
         const options = context.options[0] || {};
         const settings = context.settings;
@@ -41,17 +40,11 @@ module.exports = {
         return {
             CallExpression(node) {
                 if (astUtil.isDescribe(node, additionalSuiteNames(settings))) {
-                    stack.push(node);
-                }
-            },
+                    const scope = context.getScope();
 
-            'CallExpression:exit'(node) {
-                if (astUtil.isDescribe(node, additionalSuiteNames(settings))) {
-                    if (stack.length === 1) {
+                    if (scope.upper === null) {
                         topLevelDescribes.push(node);
                     }
-
-                    stack.pop(node);
                 }
             },
 


Test patch:
diff --git a/test/rules/max-top-level-suites.js b/test/rules/max-top-level-suites.js
index 8fe9d7d..d38bdfd 100644
--- a/test/rules/max-top-level-suites.js
+++ b/test/rules/max-top-level-suites.js
@@ -53,7 +53,8 @@ ruleTester.run('max-top-level-suites', rules['max-top-level-suites'], {
                 }
             }
         },
-        'someOtherFunction();'
+        'someOtherFunction();',
+        'describe("top", function () {}); function foo() { describe("not necessarily top", function () {}); }'
     ],
 
     invalid: [
Repository: lo1tuma/eslint-plugin-mocha
Pull request #329 (2022-07-14 08:22:12)

Support this for additionalCustomNames
A `ThisExpression` doesn't have a name so effectively, `this.it` is parsed as `undefined.it` and that works but is obviously wrong since it would also catch literally `undefined.it` as well.


Patch:
diff --git a/lib/util/ast.js b/lib/util/ast.js
index a731a51..29b88ec 100644
--- a/lib/util/ast.js
+++ b/lib/util/ast.js
@@ -28,6 +28,9 @@ function getPropertyName(property) {
 }
 
 function getNodeName(node) {
+    if (node.type === 'ThisExpression') {
+        return 'this';
+    }
     if (node.type === 'MemberExpression') {
         return `${getNodeName(node.object)}.${getPropertyName(node.property)}`;
     }


Test patch:
diff --git a/test/rules/no-exclusive-tests.js b/test/rules/no-exclusive-tests.js
index eee1ab1..e36bb58 100644
--- a/test/rules/no-exclusive-tests.js
+++ b/test/rules/no-exclusive-tests.js
@@ -166,6 +166,15 @@ ruleTester.run('no-exclusive-tests', rules['no-exclusive-tests'], {
                 }
             },
             errors: [ { message: expectedErrorMessage, column: 7, line: 1 } ]
+        },
+        {
+            code: 'this.it.only()',
+            settings: {
+                mocha: {
+                    additionalCustomNames: [ { name: 'this.it', type: 'testCase', interfaces: [ 'BDD' ] } ]
+                }
+            },
+            errors: [ { message: expectedErrorMessage, column: 9, line: 1 } ]
         }
     ]
 });
Repository: pinojs/pino
Pull request #432 (2018-06-05 19:33:02)

Fixed asString
Hi!
I just added the same fix we did in [`fast-json-stringify`](https://github.com/fastify/fast-json-stringify) :)
Any suggestion on how to test this?

Reference: https://github.com/fastify/fast-json-stringify/pull/102

delvedor: I'm not super sure if this is the best place to run this test.

Patch:
diff --git a/pino.js b/pino.js
index dc3784e..011eefe 100644
--- a/pino.js
+++ b/pino.js
@@ -157,6 +157,7 @@ function _getLevel (level) {
 function asString (str) {
   var result = ''
   var last = 0
+  var found = false
   var l = str.length
   var point = 255
   if (l > 42) {
@@ -167,9 +168,10 @@ function asString (str) {
     if (point === 34 || point === 92) {
       result += str.slice(last, i) + '\\'
       last = i
+      found = true
     }
   }
-  if (last === 0) {
+  if (!found) {
     result = str
   } else {
     result += str.slice(last)


Test patch:
diff --git a/test/basic.test.js b/test/basic.test.js
index fed25f7..a570ec4 100644
--- a/test/basic.test.js
+++ b/test/basic.test.js
@@ -327,7 +327,7 @@ test('throw if creating child without bindings', function (t) {
   })
 })
 
-test('correctly escape msg strings', function (t) {
+test('correctly escape msg strings / 1', function (t) {
   t.plan(1)
 
   var instance = pino({
@@ -348,6 +348,27 @@ test('correctly escape msg strings', function (t) {
   instance.fatal('this contains "')
 })
 
+test('correctly escape msg strings / 2', function (t) {
+  t.plan(1)
+
+  var instance = pino({
+    name: 'hello'
+  }, sink(function (chunk, enc, cb) {
+    delete chunk.time
+    t.deepEqual(chunk, {
+      pid: pid,
+      hostname: hostname,
+      level: 60,
+      name: 'hello',
+      msg: '" this contains',
+      v: 1
+    })
+    cb()
+  }))
+
+  instance.fatal('" this contains')
+})
+
 // https://github.com/pinojs/pino/issues/139
 test('object and format string', function (t) {
   var instance = pino(sink(function (chunk, enc, cb) {
Repository: pinojs/pino
Pull request #443 (2018-07-03 15:05:16)

Default error serializer
docs will be updated as part of the docs rewrite 


Patch:
diff --git a/pino.js b/pino.js
index fae8e9c..b4e77cb 100644
--- a/pino.js
+++ b/pino.js
@@ -26,7 +26,7 @@ const { LOG_VERSION } = require('./lib/meta')
 const { epochTime, nullTime } = time
 const { pid, exit } = process
 const hostname = os.hostname()
-
+const defaultErrorSerializer = serializers.err
 const defaultOptions = {
   level: 'info',
   messageKey: 'msg',
@@ -34,7 +34,7 @@ const defaultOptions = {
   enabled: true,
   prettyPrint: false,
   base: { pid, hostname },
-  serializers: {},
+  serializers: {err: defaultErrorSerializer},
   timestamp: epochTime,
   onTerminated: (evt, err) => err ? exit(1) : exit(0),
   name: undefined,


Test patch:
diff --git a/test/serializers.test.js b/test/serializers.test.js
index 922c62d..424d262 100644
--- a/test/serializers.test.js
+++ b/test/serializers.test.js
@@ -11,6 +11,62 @@ const childSerializers = {
   test: () => 'child'
 }
 
+test('default err namespace error serializer', async ({is}) => {
+  const stream = sink()
+  const parent = pino(stream)
+
+  parent.info({err: ReferenceError('test')})
+  const o = await once(stream, 'data')
+  is(typeof o.err, 'object')
+  is(o.err.type, 'ReferenceError')
+  is(o.err.message, 'test')
+  is(typeof o.err.stack, 'string')
+})
+
+test('custom serializer overrides default err namespace error serializer', async ({is}) => {
+  const stream = sink()
+  const parent = pino({
+    serializers: {
+      err: (e) => ({
+        t: e.constructor.name,
+        m: e.message,
+        s: e.stack
+      })
+    }
+  }, stream)
+
+  parent.info({err: ReferenceError('test')})
+  const o = await once(stream, 'data')
+  is(typeof o.err, 'object')
+  is(o.err.t, 'ReferenceError')
+  is(o.err.m, 'test')
+  is(typeof o.err.s, 'string')
+})
+
+test('null overrides default err namespace error serializer', async ({is}) => {
+  const stream = sink()
+  const parent = pino({serializers: {err: null}}, stream)
+
+  parent.info({err: ReferenceError('test')})
+  const o = await once(stream, 'data')
+  is(typeof o.err, 'object')
+  is(typeof o.err.type, 'undefined')
+  is(typeof o.err.message, 'undefined')
+  is(typeof o.err.stack, 'undefined')
+})
+
+test('undefined overrides default err namespace error serializer', async ({is}) => {
+  const stream = sink()
+  const parent = pino({serializers: {err: undefined}}, stream)
+
+  parent.info({err: ReferenceError('test')})
+  const o = await once(stream, 'data')
+  is(typeof o.err, 'object')
+  is(typeof o.err.type, 'undefined')
+  is(typeof o.err.message, 'undefined')
+  is(typeof o.err.stack, 'undefined')
+})
+
 test('serializers override values', async ({is}) => {
   const stream = sink()
   const parent = pino({ serializers: parentSerializers }, stream)
Repository: pinojs/pino
Pull request #444 (2018-07-08 17:01:20)

Rename .pino to .version
Due to it's self referential nature `.pino` is difficult to talk about, because you have to explicitly signify that you're talking about the version property not pino itself. This leads to confusing documentation.

This PR suggests changing the property to `version` while we have the chance prior to v5 release, and also adding a `version` property to the exported function.


Patch:
diff --git a/lib/proto.js b/lib/proto.js
index 3e23e1e..7f12d84 100644
--- a/lib/proto.js
+++ b/lib/proto.js
@@ -45,8 +45,8 @@ const prototype = {
   flush,
   addLevel,
   isLevelEnabled,
+  version,
   silent: noop,
-  pino: version,
   get levelVal () { return this[getLevelValSym]() },
   set levelVal (num) { return this[setLevelValSym](num) },
   get level () { return this[getLevelSym]() },
diff --git a/pino.js b/pino.js
index 12a56b9..ef6997b 100644
--- a/pino.js
+++ b/pino.js
@@ -10,7 +10,7 @@ const proto = require('./lib/proto')
 const symbols = require('./lib/symbols')
 const { setLevelState, mappings } = require('./lib/levels')
 const { createArgsNormalizer, asChindings } = require('./lib/tools')
-const { LOG_VERSION } = require('./lib/meta')
+const { version, LOG_VERSION } = require('./lib/meta')
 const {
   chindingsSym,
   redactFmtSym,
@@ -106,6 +106,7 @@ pino.levels = mappings()
 pino.stdSerializers = Object.assign({}, serializers)
 pino.stdTimeFunctions = Object.assign({}, time)
 pino.symbols = symbols
+pino.version = version
 pino.LOG_VERSION = LOG_VERSION
 
 module.exports = pino


Test patch:
diff --git a/test/basic.test.js b/test/basic.test.js
index eb324de..2de09a2 100644
--- a/test/basic.test.js
+++ b/test/basic.test.js
@@ -8,14 +8,18 @@ const { version } = require('../package.json')
 const { pid } = process
 const hostname = os.hostname()
 
-test('pino version is exposed', async ({is}) => {
+test('pino version is exposed on export', async ({is}) => {
+  is(pino.version, version)
+})
+
+test('pino version is exposed on instance', async ({is}) => {
   const instance = pino()
-  is(instance.pino, version)
+  is(instance.version, version)
 })
 
-test('child exposes pino version', async ({is}) => {
+test('child instance exposes pino version', async ({is}) => {
   const child = pino().child({foo: 'bar'})
-  is(child.pino, version)
+  is(child.version, version)
 })
 
 function levelTest (name, level) {
Repository: pinojs/pino
Pull request #464 (2018-07-27 22:31:19)

Do not cast to string Error#stack.
Fixes https://github.com/pinojs/pino-pretty/issues/16.

@jsumners @davidmarkclements what do you think?

davidmarkclements: yes I agree - but this is now a breaking change, so should be in v5 but not v4
davidmarkclements: We also need to discuss one case:

If I  `delete err.stack` then "stack" should not show.

However if I assign: `err.stack = undefined`, then some make the argument that they'd like to see, in some way, that it's been set to `undefined`. Which is how we got here.

So, should we set stack to an empty string when the `stack` is present but the value is `undefined`?
mcollina: > yes I agree - but this is now a breaking change, so should be in v5 but not v4

I don't think so. We landed a botched commit that we shouldn't. Let's restore proper behavior.

> However if I assign: err.stack = undefined, then some make the argument that they'd like to see, in some way, that it's been set to undefined. Which is how we got here.

No, you do not want to see it. Mainly because:

```js
pino.info({ hello: undefined })
```

Will not show the `'hello'` property. `undefined` is invisible in JSON, and it is equal to `delete`.
mcollina: I do not know how to run that, and there are no instructions. However it does fix the pino-pretty test, so I think we are good to go.

Patch:
diff --git a/pino.js b/pino.js
index ff34c3b..43b68b6 100644
--- a/pino.js
+++ b/pino.js
@@ -147,7 +147,9 @@ function asJson (obj, msg, num, time) {
     var notHasOwnProperty = obj.hasOwnProperty === undefined
     if (objError) {
       data += ',"type":"Error"'
-      data += obj.stack ? ',"stack":' + this.stringify(obj.stack) : ''
+      if (obj.stack !== undefined) {
+        data += ',"stack":' + this.stringify(obj.stack)
+      }
     }
     // if global serializer is set, call it first
     if (this.serializers[Symbol.for('pino.*')]) {


Test patch:
diff --git a/test/error.test.js b/test/error.test.js
index dbdf1bc..5bdb73d 100644
--- a/test/error.test.js
+++ b/test/error.test.js
@@ -143,3 +143,19 @@ test('stack is omitted if it is not set on err', t => {
   instance.level = name
   instance[name](err)
 })
+
+test('stack is rendered as any other property if it\'s not a string', t => {
+  t.plan(3)
+  var err = new Error('myerror')
+  err.stack = null
+  var instance = pino(sink(function (chunk, enc, cb) {
+    t.ok(new Date(chunk.time) <= new Date(), 'time is greater than Date.now()')
+    delete chunk.time
+    t.equal(chunk.hasOwnProperty('stack'), true)
+    t.equal(chunk.stack, null)
+    cb()
+  }))
+
+  instance.level = name
+  instance[name](err)
+})
Repository: pinojs/pino
Pull request #472 (2018-08-06 14:34:45)

Support automatic destination with string.
This should simplify the integration with pino-http, fastify, etc..

mcollina: I think that's _advanced_, and possibly users should avoid doing that. We are already picking up the fd from stdout and stderr anyway.
mcollina: PTAL, I just added docs and fixed a bug.

Patch:
diff --git a/docs/api.md b/docs/api.md
index d2d0cda..2dfb67a 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -178,7 +178,7 @@ documented in the [Browser API ⇗](/docs/browser.md) documentation.
 * See [Browser API ⇗](/docs/browser.md)
 
 <a id="destination"></a>
-### `destination` (SonicBoom | WritableStream)
+### `destination` (SonicBoom | WritableStream | String)
 
 Default: `pino.destination(1)` (STDOUT)
 
@@ -198,6 +198,8 @@ const fileLogger = require('pino')( pino.destination('/log/path'))
 const opts = {name: 'my-logger'}
 const stderrLogger = require('pino')(opts, pino.destination(2))
 
+// automatic wrapping in pino.destination
+const fileLogger = require('pino')('/log/path')
 ```
 
 * See [`pino.destination`](#pino-destination) 
diff --git a/lib/tools.js b/lib/tools.js
index c31e913..967bc8d 100644
--- a/lib/tools.js
+++ b/lib/tools.js
@@ -193,6 +193,15 @@ function prettifierMetaWrapper (pretty, dest) {
 
 function createArgsNormalizer (defaultOptions) {
   return function normalizeArgs (opts = {}, stream) {
+    // support stream as a string
+    if (typeof opts === 'string') {
+      stream = new SonicBoom(opts)
+      opts = {}
+    }
+    if (typeof stream === 'string') {
+      stream = new SonicBoom(stream)
+      opts = {}
+    }
     if (opts instanceof SonicBoom || opts.writable || opts._writableState) {
       stream = opts
       opts = null


Test patch:
diff --git a/test/basic.test.js b/test/basic.test.js
index 1232634..1f96963 100644
--- a/test/basic.test.js
+++ b/test/basic.test.js
@@ -424,6 +424,44 @@ test('pino.destination', async ({same}) => {
   })
 })
 
+test('auto pino.destination with a string', async ({same}) => {
+  const tmp = join(
+    os.tmpdir(),
+    '_' + Math.random().toString(36).substr(2, 9)
+  )
+  const instance = pino(tmp)
+  instance.info('hello')
+  await sleep(250)
+  const result = JSON.parse(readFileSync(tmp).toString())
+  delete result.time
+  same(result, {
+    pid: pid,
+    hostname: hostname,
+    level: 30,
+    msg: 'hello',
+    v: 1
+  })
+})
+
+test('auto pino.destination with a string as second argument', async ({same}) => {
+  const tmp = join(
+    os.tmpdir(),
+    '_' + Math.random().toString(36).substr(2, 9)
+  )
+  const instance = pino({}, tmp)
+  instance.info('hello')
+  await sleep(250)
+  const result = JSON.parse(readFileSync(tmp).toString())
+  delete result.time
+  same(result, {
+    pid: pid,
+    hostname: hostname,
+    level: 30,
+    msg: 'hello',
+    v: 1
+  })
+})
+
 // https://github.com/pinojs/pino/issues/222
 test('children with same names render in correct order', async ({is}) => {
   const stream = sink()
Repository: pinojs/pino
Pull request #475 (2018-08-08 13:08:29)

More fixes to pino-pretty, now it applies serializers as expected

mcollina: No, it's matching a string `'object'`.

Patch:
diff --git a/lib/tools.js b/lib/tools.js
index bfc2132..5a90fa7 100644
--- a/lib/tools.js
+++ b/lib/tools.js
@@ -192,7 +192,7 @@ function prettifierMetaWrapper (pretty, dest) {
       for (var i = 0; i < keys.length; i++) {
         key = keys[i]
         if (obj[key] !== undefined) {
-          obj[key] = serializers[key](obj)
+          obj[key] = serializers[key](obj[key])
         }
       }
 
diff --git a/package.json b/package.json
index b11df93..be2d015 100644
--- a/package.json
+++ b/package.json
@@ -67,7 +67,7 @@
     "fresh-require": "^1.0.3",
     "log": "^1.4.0",
     "loglevel": "^1.6.1",
-    "pino-pretty": "^1.0.1",
+    "pino-pretty": "^2.0.0",
     "pre-commit": "^1.2.2",
     "proxyquire": "^2.0.1",
     "qodaa": "^1.0.1",


Test patch:
diff --git a/test/fixtures/pretty/serializers.js b/test/fixtures/pretty/serializers.js
index d9bbd04..fcdb211 100644
--- a/test/fixtures/pretty/serializers.js
+++ b/test/fixtures/pretty/serializers.js
@@ -6,6 +6,10 @@ var log = pino({
   prettyPrint: true,
   serializers: {
     foo (obj) {
+      if (obj.an !== 'object') {
+        throw new Error('kaboom')
+      }
+
       return 'bar'
     }
   }