nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: yargs/yargs-parser
Pull request #94 (2017-08-02 15:53:59)

Allow configuration of prefix for boolean negation
This PR adds a configuration setting `negation-prefix` which allows the prefix used in boolean negation to be specified. The default value of `no-` ensures backward compatibility.

**Justification:** I am using `yargs-parser` to parse the command lines of 3rd party programs and not all of them follow the `--no-foo` convention. Some programs seem to use `--nofoo` instead of `--no-foo`.

bcoe: @yitzchak this seems quite reasonable to me 👍 

I am going to go ahead and land, but it might be a few days before I get this pulled into yargs proper. Feel free to join yargs' community chat, if you want to help kick the process along (or would like to learn more about what the release process looks like).

http://devtoolscommunity.herokuapp.com/

Patch:
diff --git a/README.md b/README.md
index d1817fc..a368e63 100644
--- a/README.md
+++ b/README.md
@@ -250,6 +250,25 @@ node example.js -x 1 2 -x 3 4
 { _: [], x: [[1, 2], [3, 4]] }
 ```
 
+### negation prefix
+
+* default: `no-`
+* key: `negation-prefix`
+
+The prefix to use for negated boolean variables.
+
+```sh
+node example.js --no-foo
+{ _: [], foo: false }
+```
+
+_if set to `quux`:_
+
+```sh
+node example.js --quuxfoo
+{ _: [], foo: false }
+```
+
 ### populate --
 
 * default: `false`.
diff --git a/index.js b/index.js
index 7315406..2ab9c2c 100644
--- a/index.js
+++ b/index.js
@@ -16,6 +16,7 @@ function parse (args, opts) {
     'dot-notation': true,
     'parse-numbers': true,
     'boolean-negation': true,
+    'negation-prefix': 'no-',
     'duplicate-arguments-array': true,
     'flatten-duplicate-arrays': true,
     'populate--': false
@@ -45,6 +46,7 @@ function parse (args, opts) {
     coercions: {}
   }
   var negative = /^-[0-9]+(\.[0-9]+)?/
+  var negatedBoolean = new RegExp('^--' + configuration['negation-prefix'] + '(.+)')
 
   ;[].concat(opts.array).filter(Boolean).forEach(function (key) {
     flags.arrays[key] = true
@@ -141,8 +143,8 @@ function parse (args, opts) {
       } else {
         setArg(m[1], m[2])
       }
-    } else if (arg.match(/^--no-.+/) && configuration['boolean-negation']) {
-      key = arg.match(/^--no-(.+)/)[1]
+    } else if (arg.match(negatedBoolean) && configuration['boolean-negation']) {
+      key = arg.match(negatedBoolean)[1]
       setArg(key, false)
 
     // -- seperated by space.


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 373f8d3..fa296b6 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -1968,6 +1968,16 @@ describe('yargs-parser', function () {
         parsed['no-dice'].should.equal(true)
         expect(parsed.dice).to.equal(undefined)
       })
+
+      it('negates boolean arguments with correct prefix', function () {
+        var parsed = parser(['--foodice'], {
+          configuration: {
+            'negation-prefix': 'foo'
+          }
+        })
+
+        expect(parsed['dice']).to.equal(false)
+      })
     })
 
     describe('duplicate arguments array', function () {
Repository: yargs/yargs-parser
Pull request #106 (2017-10-07 21:09:07)

fix: tokenizer should ignore spaces at the beginning of the argString
See #100 


Patch:
diff --git a/.gitignore b/.gitignore
index 2454630..db9974f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
+.idea
 .nyc_output
 node_modules
 .DS_Store
+package-lock.json
 ./test/fixtures/package.json
diff --git a/index.js b/index.js
index c06d937..1a2c7cb 100644
--- a/index.js
+++ b/index.js
@@ -479,7 +479,7 @@ function parse (args, opts) {
       // if the value is an inner object and we have dot-notation
       // enabled, treat inner objects in config the same as
       // heavily nested dot notations (foo.bar.apple).
-      if (typeof value === 'object' && !Array.isArray(value) && configuration['dot-notation']) {
+      if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) {
         // if the value is an object but not an array, check nested object
         setConfigObject(value, fullKey)
       } else {
diff --git a/lib/tokenize-arg-string.js b/lib/tokenize-arg-string.js
index 7015442..6c8d23e 100644
--- a/lib/tokenize-arg-string.js
+++ b/lib/tokenize-arg-string.js
@@ -2,6 +2,8 @@
 module.exports = function (argString) {
   if (Array.isArray(argString)) return argString
 
+  argString = argString.trim()
+
   var i = 0
   var prevC = null
   var c = null


Test patch:
diff --git a/test/tokenize-arg-string.js b/test/tokenize-arg-string.js
index 63ad295..2f7cffc 100644
--- a/test/tokenize-arg-string.js
+++ b/test/tokenize-arg-string.js
@@ -39,8 +39,10 @@ describe('TokenizeArgString', function () {
     args[2].should.equal('--bar=foo "bar"')
   })
 
-  it('multiple spaces only counted in quotes', function () {
-    var args = tokenizeArgString('foo  bar  "foo  bar"')
+  // https://github.com/yargs/yargs-parser/pull/100
+  // https://github.com/yargs/yargs-parser/pull/106
+  it('ignores unneeded spaces', function () {
+    var args = tokenizeArgString('  foo  bar  "foo  bar"  ')
     args[0].should.equal('foo')
     expect(args[1]).equal('bar')
     expect(args[2]).equal('foo  bar')
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index d2d5654..0c9bb97 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -642,13 +642,15 @@ describe('yargs-parser', function () {
         configObjects: [{
           apple: 'apple',
           banana: 42,
-          foo: 'baz'
+          foo: 'baz',
+          gotcha: null
         }]
       })
 
       argv.should.have.property('apple', 'apple')
       argv.should.have.property('banana', 42)
       argv.should.have.property('foo', 'bar')
+      argv.should.have.property('gotcha', null)
     })
 
     it('should use value from config object, if argv value is using default value', function () {
Repository: yargs/yargs-parser
Pull request #108 (2017-11-14 22:11:21)

Fix: Allow null config values
See #107


Patch:
diff --git a/index.js b/index.js
index c06d937..1a2c7cb 100644
--- a/index.js
+++ b/index.js
@@ -479,7 +479,7 @@ function parse (args, opts) {
       // if the value is an inner object and we have dot-notation
       // enabled, treat inner objects in config the same as
       // heavily nested dot notations (foo.bar.apple).
-      if (typeof value === 'object' && !Array.isArray(value) && configuration['dot-notation']) {
+      if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) {
         // if the value is an object but not an array, check nested object
         setConfigObject(value, fullKey)
       } else {


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index d2d5654..0c9bb97 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -642,13 +642,15 @@ describe('yargs-parser', function () {
         configObjects: [{
           apple: 'apple',
           banana: 42,
-          foo: 'baz'
+          foo: 'baz',
+          gotcha: null
         }]
       })
 
       argv.should.have.property('apple', 'apple')
       argv.should.have.property('banana', 42)
       argv.should.have.property('foo', 'bar')
+      argv.should.have.property('gotcha', null)
     })
 
     it('should use value from config object, if argv value is using default value', function () {
Repository: yargs/yargs-parser
Pull request #109 (2017-11-28 09:57:57)

.idea directory and package-lock.json are added to .gitignore as it's done in yargs
This pull request adds `.idea` directory and `package-lock.json` file to `.gitignore` as it's [done in yargs](https://github.com/yargs/yargs/blob/master/.gitignore).


Patch:
diff --git a/.gitignore b/.gitignore
index 2454630..db9974f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,6 @@
+.idea
 .nyc_output
 node_modules
 .DS_Store
+package-lock.json
 ./test/fixtures/package.json
diff --git a/index.js b/index.js
index c06d937..1a2c7cb 100644
--- a/index.js
+++ b/index.js
@@ -479,7 +479,7 @@ function parse (args, opts) {
       // if the value is an inner object and we have dot-notation
       // enabled, treat inner objects in config the same as
       // heavily nested dot notations (foo.bar.apple).
-      if (typeof value === 'object' && !Array.isArray(value) && configuration['dot-notation']) {
+      if (typeof value === 'object' && value !== null && !Array.isArray(value) && configuration['dot-notation']) {
         // if the value is an object but not an array, check nested object
         setConfigObject(value, fullKey)
       } else {


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index d2d5654..0c9bb97 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -642,13 +642,15 @@ describe('yargs-parser', function () {
         configObjects: [{
           apple: 'apple',
           banana: 42,
-          foo: 'baz'
+          foo: 'baz',
+          gotcha: null
         }]
       })
 
       argv.should.have.property('apple', 'apple')
       argv.should.have.property('banana', 42)
       argv.should.have.property('foo', 'bar')
+      argv.should.have.property('gotcha', null)
     })
 
     it('should use value from config object, if argv value is using default value', function () {
Repository: yargs/yargs-parser
Pull request #110 (2017-12-18 06:41:53)

fix: scientific notation circumvented bounds check
due to a bug in our bounds checking logic, scientific notation could be entered greater than MAX_INTEGER.

fixes: https://github.com/yargs/yargs/issues/1017
see: https://github.com/yargs/yargs/pull/1019


Patch:
diff --git a/index.js b/index.js
index 8514583..1865649 100644
--- a/index.js
+++ b/index.js
@@ -425,7 +425,9 @@ function parse (args, opts) {
 
   function maybeCoerceNumber (key, value) {
     if (!checkAllAliases(key, flags.strings) && !checkAllAliases(key, flags.coercions)) {
-      const shouldCoerceNumber = isNumber(value) && configuration['parse-numbers'] && (Number.isSafeInteger(parseInt(value)))
+      const shouldCoerceNumber = isNumber(value) && configuration['parse-numbers'] && (
+        Number.isSafeInteger(Math.floor(value))
+      )
       if (shouldCoerceNumber || (!isUndefined(value) && checkAllAliases(key, flags.numbers))) value = Number(value)
     }
     return value


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 055d056..49766e4 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -2479,6 +2479,11 @@ describe('yargs-parser', function () {
     argv.foo.should.equal('93940495950949399948393')
   })
 
+  it('does not magically convert scientific notation larger than Number.MAX_SAFE_INTEGER', () => {
+    const argv = parser([ '--foo', '33e99999' ])
+    argv.foo.should.equal('33e99999')
+  })
+
   it('converts numeric options larger than Number.MAX_SAFE_INTEGER to number', () => {
     const argv = parser([ '--foo', '93940495950949399948393' ], {
       number: ['foo']
Repository: yargs/yargs-parser
Pull request #114 (2018-01-20 22:20:34)

feat: narg arguments no longer consume flag arguments
BREAKING CHANGE: arguments of form --foo, -abc, will no longer be consumed by nargs

This is in prep for replacing the crufty legacy method `requiresArg` with nargs(1).

CC: @evocateur for review

bcoe: @evocateur I don't remember if I consciously made this design decision when building nargs, or if it was an oversight -- this behavior feels better to me. 

Patch:
diff --git a/index.js b/index.js
index 1d3e6b9..5c5638b 100644
--- a/index.js
+++ b/index.js
@@ -302,11 +302,20 @@ function parse (args, opts) {
   // how many arguments should we consume, based
   // on the nargs option?
   function eatNargs (i, key, args) {
+    var ii
     var toEat = checkAllAliases(key, flags.nargs)
 
-    if (args.length - (i + 1) < toEat) error = Error(__('Not enough arguments following: %s', key))
+    // nargs will not consume flag arguments, e.g., -abc, --foo,
+    // and terminates when one is observed.
+    var available = 0
+    for (ii = i + 1; ii < args.length; ii++) {
+      if (!args[ii].match(/^-[^0-9]/)) available++
+      else break
+    }
+
+    if (available < toEat) error = Error(__('Not enough arguments following: %s', key))
 
-    for (var ii = i + 1; ii < (toEat + i + 1); ii++) {
+    for (ii = i + 1; ii < (available + i + 1); ii++) {
       setArg(key, args[ii])
     }
 
diff --git a/package.json b/package.json
index 0c940b1..72d3749 100644
--- a/package.json
+++ b/package.json
@@ -4,8 +4,8 @@
   "description": "the mighty option parser used by yargs",
   "main": "index.js",
   "scripts": {
-    "pretest": "standard",
     "test": "nyc mocha test/*.js",
+    "posttest": "standard",
     "coverage": "nyc report --reporter=text-lcov | coveralls",
     "release": "standard-version"
   },


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 24825f9..6e1ae0c 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -1643,6 +1643,16 @@ describe('yargs-parser', function () {
       result['1'][0].should.equal('a')
       result['1'][1].should.equal('b')
     })
+
+    it('should not treat flag arguments as satisfying narg requirements', function () {
+      var result = parser.detailed(['--foo', '--bar'], {
+        narg: {
+          foo: 1
+        }
+      })
+
+      result.error.message.should.equal('Not enough arguments following: foo')
+    })
   })
 
   describe('env vars', function () {
Repository: yargs/yargs-parser
Pull request #195 (2019-08-11 22:02:00)

did you mean expansion?


Patch:
diff --git a/README.md b/README.md
index dde9f84..95d70b9 100644
--- a/README.md
+++ b/README.md
@@ -370,7 +370,7 @@ node example.js --test-field 1
 * key: `strip-dashed`
 
 Should dashed keys be removed before returning results?  This option has no effect if
-`camel-case-exansion` is disabled.
+`camel-case-expansion` is disabled.
 
 _If disabled:_
 
diff --git a/index.js b/index.js
index 79d433c..7f00f36 100644
--- a/index.js
+++ b/index.js
@@ -555,7 +555,7 @@ function parse (args, opts) {
       } else {
         // setting arguments via CLI takes precedence over
         // values within the config file.
-        if (!hasKey(argv, fullKey.split('.')) || (flags.arrays[fullKey] && configuration['combine-arrays'])) {
+        if (!hasKey(argv, fullKey.split('.')) || (checkAllAliases(fullKey, flags.arrays) && configuration['combine-arrays'])) {
           setArg(fullKey, value)
         }
       }


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 65d90e4..e51bb3d 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -774,6 +774,21 @@ describe('yargs-parser', function () {
       argv.should.have.property('foo', 'bar')
       argv.should.have.property('bar', 'baz')
     })
+
+    it('should combine array typed options with alias and camel-case', function () {
+      var argv = parser(['--camEl', 'foo', '--camEl', 'bar', '-a', 'red'], {
+        array: ['cam-el', 'apple'],
+        alias: { apple: 'a' },
+        configObjects: [{ camEl: 'baz' }, { a: 'sweet' }],
+        configuration: {
+          'combine-arrays': true,
+          'camel-case-expansion': true
+        }
+      })
+
+      argv['cam-el'].should.deep.equal(['foo', 'bar', 'baz'])
+      argv.apple.should.deep.equal(['red', 'sweet'])
+    })
   })
 
   describe('dot notation', function () {
Repository: yargs/yargs-parser
Pull request #207 (2019-10-15 00:48:08)

fix(unknown-options-as-args): '--' is not an unknown option
This fixes an edge case created by @henderea's #181 and #202 when `unknown-options-as-args` and `populate--` are _both_ `true`. I encountered it when attempting to upgrade Lerna from yargs v12 to yargs latest (v14).

In the process of identifying the fix, I realized I probably shouldn't be using `populate--` 🤣 (the new `unknown-options-as-args` is much better for my use-case!)


Patch:
diff --git a/index.js b/index.js
index 395f5fe..03dd140 100644
--- a/index.js
+++ b/index.js
@@ -143,7 +143,8 @@ function parse (args, opts) {
     var next
     var value
 
-    if (isUnknownOptionAsArg(arg)) {
+    // any unknown option (except for end-of-options, "--")
+    if (arg !== '--' && isUnknownOptionAsArg(arg)) {
       argv._.push(arg)
     // -- separated by =
     } else if (arg.match(/^--.+=/) || (


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 349549b..79ccf97 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -2894,6 +2894,36 @@ describe('yargs-parser', function () {
           k: true
         })
       })
+
+      it('should not identify "--" as an unknown option', function () {
+        const argv = parser('-a -k one -1 -- -b -k two -2', {
+          boolean: ['k'],
+          configuration: {
+            'unknown-options-as-args': true
+          }
+        })
+        argv.should.deep.equal({
+          _: ['-a', 'one', -1, '-b', '-k', 'two', '-2'],
+          k: true
+        })
+      })
+
+      it('should not identify "--" as an unknown option when "populate--" is true', function () {
+        const argv = parser('-a -k one -1 -- -b -k two -2', {
+          boolean: ['k'],
+          configuration: {
+            'populate--': true,
+            'unknown-options-as-args': true
+          }
+        })
+        argv.should.deep.equal({
+          // populate argv._ with everything before the --
+          _: ['-a', 'one', -1],
+          // and argv['--'] with everything after the --
+          '--': ['-b', '-k', 'two', '-2'],
+          k: true
+        })
+      })
     })
   })
Repository: yargs/yargs-parser
Pull request #208 (2019-10-20 17:55:39)

support negative numbers with decimal places
This pull request fixes some issues with negative numbers containing decimal places.  It also adds support for negative numbers that don't have a leading 0, such as `-.1`.

Fixes yargs/yargs#1204

bcoe: @henderea :wave: thanks for the patch; I've had a fairly busy past few weeks, am hoping to have a bit of free time for open-source this weekend.

Patch:
diff --git a/index.js b/index.js
index 03dd140..3ce3e22 100644
--- a/index.js
+++ b/index.js
@@ -51,7 +51,7 @@ function parse (args, opts) {
     coercions: {},
     keys: []
   }
-  var negative = /^-[0-9]+(\.[0-9]+)?/
+  var negative = /^-([0-9]+(\.[0-9]+)?|\.[0-9]+)$/
   var negatedBoolean = new RegExp('^--' + configuration['negation-prefix'] + '(.+)')
 
   ;[].concat(opts.array).filter(Boolean).forEach(function (opt) {
@@ -206,7 +206,7 @@ function parse (args, opts) {
       setArg(m[1], m[2])
 
     // dot-notation flag separated by space.
-    } else if (arg.match(/^-.\..+/)) {
+    } else if (arg.match(/^-.\..+/) && !arg.match(negative)) {
       next = args[i + 1]
       key = arg.match(/^-(.\..+)/)[1]
 
@@ -362,7 +362,7 @@ function parse (args, opts) {
     // and terminates when one is observed.
     var available = 0
     for (ii = i + 1; ii < args.length; ii++) {
-      if (!args[ii].match(/^-[^0-9]/) || isUnknownOptionAsArg(args[ii])) available++
+      if (!args[ii].match(/^-[^0-9]/) || args[ii].match(negative) || isUnknownOptionAsArg(args[ii])) available++
       else break
     }
 


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 79ccf97..1ecc37b 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -159,6 +159,21 @@ describe('yargs-parser', function () {
     argv.other.should.deep.equal([-99, -220])
   })
 
+  it('should handle negative (and positive) numbers with decimal places, with or without a leading 0', function () {
+    var argv = parser([
+      '-0.1', '-1.1', '-.5', '-.1', '.1', '.5',
+      '--bounds', '-5.1', '-.1', '.1',
+      '--other', '.9', '-.5'
+    ], {
+      array: 'bounds',
+      narg: { 'other': 2 }
+    })
+
+    argv._.should.deep.equal([-0.1, -1.1, -0.5, -0.1, 0.1, 0.5])
+    argv.bounds.should.deep.equal([-5.1, -0.1, 0.1])
+    argv.other.should.deep.equal([0.9, -0.5])
+  })
+
   it('should set the value of a single short option to the next supplied value, even if the value is empty', function () {
     var parse = parser(['-p', ''])
     parse.should.have.property('p', '')
Repository: yargs/yargs-parser
Pull request #247 (2020-02-29 20:28:32)

fix: normalized keys were not enumerable
This was breaking upstream behavior in yargs (and in turn mocha), because the parsed options object is iterated over in yargs and appended to another object:

```bash
mocha init <path>

create a client-side Mocha setup at <path>

Positional Arguments
  path                                                       [string] [required]

Other Options
  --help, -h     Show usage information & exit                         [boolean]
  --version, -V  Show version number & exit                            [boolean]

✖ ERROR: Missing required argument: path
```


Patch:
diff --git a/index.js b/index.js
index 0c5ad4e..0e7448c 100644
--- a/index.js
+++ b/index.js
@@ -465,6 +465,7 @@ function parse (args, opts) {
       const keys = [key].concat(flags.aliases[key] || [])
       keys.forEach(function (key) {
         Object.defineProperty(argvReturn, key, {
+          enumerable: true,
           get () {
             return val
           },


Test patch:
diff --git a/test/yargs-parser.js b/test/yargs-parser.js
index 0fd4c6f..6b22360 100644
--- a/test/yargs-parser.js
+++ b/test/yargs-parser.js
@@ -342,6 +342,16 @@ describe('yargs-parser', function () {
       a.should.have.property('s').and.deep.equal(expected)
       a.should.have.property('save').and.deep.equal(expected)
     })
+
+    it('should allow normalized keys to be enumerated', () => {
+      var a = parser(['-s', ['', 'tmp', '..', ''].join(path.sep)], {
+        alias: {
+          s: ['save']
+        },
+        normalize: 's'
+      })
+      Object.keys(a).should.include('s')
+    })
   })
 
   describe('alias', function () {