nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: keithamus/sort-package-json
Pull request #257 (2022-04-30 21:08:15)

feat: add support for `volta`
The goal of this PR is to add support for [Volta](https://volta.sh/), which is a JavaScript tool manager.


Patch:
diff --git a/defaultRules.md b/defaultRules.md
index 77bb676..c1b684c 100644
--- a/defaultRules.md
+++ b/defaultRules.md
@@ -92,6 +92,7 @@ _Note: when a specific key order is used, any other keys will be sorted in the e
 | packageManager        |                                                                                |
 | engines               | Key sort                                                                       |
 | engineStrict          | Key sort                                                                       |
+| volta                 | Key order: `node`, `npm`, `yarn`                                               |
 | languageName          |                                                                                |
 | os                    |                                                                                |
 | cpu                   |                                                                                |
diff --git a/index.js b/index.js
index 7d6d521..d183bb1 100755
--- a/index.js
+++ b/index.js
@@ -124,6 +124,8 @@ const sortPrettierConfig = onObject(
   ]),
 )
 
+const sortVolta = sortObjectBy(['node', 'npm', 'yarn'])
+
 // See https://docs.npmjs.com/misc/scripts
 const defaultNpmScripts = new Set([
   'install',
@@ -290,6 +292,7 @@ const fields = [
   { key: 'packageManager' },
   { key: 'engines', over: sortObject },
   { key: 'engineStrict', over: sortObject },
+  { key: 'volta', over: sortVolta },
   { key: 'languageName' },
   { key: 'os' },
   { key: 'cpu' },


Test patch:
diff --git a/tests/fields.js b/tests/fields.js
index 0401b8d..1a17c33 100644
--- a/tests/fields.js
+++ b/tests/fields.js
@@ -186,6 +186,20 @@ test('directories', macro.sortObject, {
   },
 })
 
+test('volta', macro.sortObject, {
+  path: 'volta',
+  value: {
+    yarn: '0.0.0',
+    npm: '0.0.0',
+    node: '0.0.0',
+  },
+  expect: {
+    node: '0.0.0',
+    npm: '0.0.0',
+    yarn: '0.0.0',
+  },
+})
+
 test('contributors', (t) => {
   const contributors = {
     contributors: [
diff --git a/tests/snapshots/main.js.md b/tests/snapshots/main.js.md
index 0d41813..020e0f2 100644
--- a/tests/snapshots/main.js.md
+++ b/tests/snapshots/main.js.md
@@ -107,6 +107,7 @@ Generated by [AVA](https://avajs.dev).
         "umd:main": "umd:main",␊
         "unpkg": "unpkg",␊
         "version": "version",␊
+        "volta": "volta",␊
         "workspaces": "workspaces",␊
         "xo": "xo"␊
       }`,
@@ -201,6 +202,7 @@ Generated by [AVA](https://avajs.dev).
         "packageManager": "packageManager",␊
         "engines": "engines",␊
         "engineStrict": "engineStrict",␊
+        "volta": "volta",␊
         "languageName": "languageName",␊
         "os": "os",␊
         "cpu": "cpu",␊
Repository: keithamus/sort-package-json
Pull request #309 (2024-01-29 12:06:59)

feat: don’t sort scripts when `npm-run-all2` is installed
Closes https://github.com/keithamus/sort-package-json/issues/308. Context: https://github.com/keithamus/sort-package-json/pull/232


Patch:
diff --git a/index.js b/index.js
index 26dfe9d..cb02bc6 100755
--- a/index.js
+++ b/index.js
@@ -163,7 +163,10 @@ const sortScripts = onObject((scripts, packageJson) => {
     return name
   })
 
-  if (!hasDevDependency('npm-run-all', packageJson)) {
+  if (
+    !hasDevDependency('npm-run-all', packageJson) &&
+    !hasDevDependency('npm-run-all2', packageJson)
+  ) {
     keys.sort()
   }
 


Test patch:
diff --git a/tests/scripts.js b/tests/scripts.js
index 0e5aa1d..8a417c6 100644
--- a/tests/scripts.js
+++ b/tests/scripts.js
@@ -68,3 +68,20 @@ for (const field of ['scripts', 'betterScripts']) {
     },
   })
 }
+
+for (const field of ['scripts', 'betterScripts']) {
+  test(`${field} when npm-run-all2 is not a dev dependency`, macro.sortObject, {
+    value: { [field]: fixture },
+    expect: { [field]: expectAllSorted },
+  })
+  test(`${field} when npm-run-all2 is a dev dependency`, macro.sortObject, {
+    value: {
+      [field]: fixture,
+      devDependencies: { 'npm-run-all2': '^1.0.0' },
+    },
+    expect: {
+      [field]: expectPreAndPostSorted,
+      devDependencies: { 'npm-run-all2': '^1.0.0' },
+    },
+  })
+}
Repository: TechnologyAdvice/obey
Pull request #30 (2016-03-08 21:19:33)

Rules: Process falsey global props


Patch:
diff --git a/src/rules.js b/src/rules.js
index 9f4b015..3d5a91a 100644
--- a/src/rules.js
+++ b/src/rules.js
@@ -63,7 +63,7 @@ const rules = {
     if (!def.type) throw new Error('Model properties must define a \'type\'')
     let chain = Promise.resolve(data)
     props.forEach(prop => {
-      if (def[prop.name]) {
+      if (def.hasOwnProperty(prop.name)) {
         chain = chain.then(prop.fn.bind(context, def, key)).then(res => {
           return res === undefined ? data : res
         })


Test patch:
diff --git a/test/src/rules.spec.js b/test/src/rules.spec.js
index 54d018f..a3c05e8 100644
--- a/test/src/rules.spec.js
+++ b/test/src/rules.spec.js
@@ -18,6 +18,12 @@ describe('rules', () => {
           expect(data).to.equal('foo')
         })
     })
+    it('processes global props even when falsey', () => {
+      return rules.validate({ type: 'number', default: 0 }, undefined)
+        .then(data => {
+          expect(data).to.equal(0)
+        })
+    })
   })
   describe('build', () => {
     it('returns an object with the original definition and validate method', () => {
Repository: TechnologyAdvice/obey
Pull request #45 (2016-04-16 03:36:42)

ValidationError Update
- Add test to make sure `ValidationError` inherits from `Error`.
- use `inherits` method from [`util`](https://nodejs.org/dist/latest-v4.x/docs/api/util.html#util_util_inherits_constructor_superconstructor) module.
- omit `ValidationError` from [generated stack trace](https://nodejs.org/dist/latest-v4.x/docs/api/errors.html#errors_error_capturestacktrace_targetobject_constructoropt).
- add test to make sure `ValidationError` is not included in `stack` property.


Patch:
diff --git a/src/lib/error.js b/src/lib/error.js
index 349229f..4d74076 100644
--- a/src/lib/error.js
+++ b/src/lib/error.js
@@ -1,6 +1,7 @@
 /*
  * Copyright (c) 2015 TechnologyAdvice
  */
+import util from 'util'
 
 /**
  * Compiles array items into string error messages
@@ -25,11 +26,10 @@ function ValidationError(message) {
   Object.defineProperty(this, 'name', { value: 'ValidationError' })
   Object.defineProperty(this, 'message', { value: getMessages(message).join('\n') })
   Object.defineProperty(this, 'collection', { value: message })
-  Error.captureStackTrace(this, this.name)
+  Error.captureStackTrace(this, ValidationError)
 }
 
 // Creates instance of ValidationError as Error object
-ValidationError.prototype = Object.create(Error.prototype)
-ValidationError.prototype.constructor = ValidationError
+util.inherits(ValidationError, Error)
 
 export default ValidationError


Test patch:
diff --git a/test/src/lib/error.spec.js b/test/src/lib/error.spec.js
index c12a6b1..dacaa41 100644
--- a/test/src/lib/error.spec.js
+++ b/test/src/lib/error.spec.js
@@ -2,9 +2,15 @@
 import ValidationError from 'src/lib/error'
 
 describe('ValidationError', () => {
+  it('inherits from Error', () => {
+    expect(new ValidationError([])).to.be.instanceOf(Error)
+  })
   it('creates a new instance of ValidationError', () => {
     expect(new ValidationError([])).to.be.instanceOf(ValidationError)
   })
+  it('contains stack property', () => {
+    expect(new ValidationError([])).to.have.property('stack')
+  })
   it('creates an error without a key if key is not present', () => {
     const origError = [
       { value: 'foo', message: 'Not cool, bro' }
@@ -21,4 +27,11 @@ describe('ValidationError', () => {
     expect(err.message).to.equal('foo (bar): Not ok\nfizz (buzz): Nope')
     expect(err.collection).to.deep.equal(origError)
   })
+  it('does not include ValidationError on stack', () => {
+    const sampleError = [
+        { value: 'bar', message: 'Not ok'}
+    ]
+    const err = new ValidationError(sampleError)
+    expect(err.stack).to.not.contain('error.js')
+  })
 })
Repository: TechnologyAdvice/obey
Pull request #67 (2017-02-07 17:14:27)

fix(array-return): if array values not defined, return original value
This fixes "loose" array definitions (i.e. just specifying `type: 'array'` without declaring the array items' types). Has bitten us in the ass a few times.

thomasruns: 🐖 

Patch:
diff --git a/src/typeStrategies/array.js b/src/typeStrategies/array.js
index 5c1dea1..7039df6 100644
--- a/src/typeStrategies/array.js
+++ b/src/typeStrategies/array.js
@@ -16,7 +16,7 @@ const array = {
       return context.fail('Value must not be empty array')
     }
     // Specific array sub-validation
-    if (!context.def.values) return true
+    if (!context.def.values) return context.value
     const promises = context.value.map((elem, idx) => {
       return rules.validate(context.def.values, elem, context.def.opts, `${context.key}[${idx}]`, context.errors, false, context.initData)
     })


Test patch:
diff --git a/test/src/typeStrategies/array.spec.js b/test/src/typeStrategies/array.spec.js
index 4440d49..18df495 100644
--- a/test/src/typeStrategies/array.spec.js
+++ b/test/src/typeStrategies/array.spec.js
@@ -16,8 +16,9 @@ describe('type:array', () => {
       fail: sinon.spy(),
       def: {}
     }
-    array.default(context)
+    const actual = array.default(context)
     expect(context.fail).to.not.be.called
+    expect(actual).to.deep.equal(context.value)
   })
   it('allows an empty array to pass if empty flag is set to true', () => {
     const context = {