PrimeIntellect/SWE-rebench-V2 huggingface dataset:
Repository: yargs/yargs (js)

Issue:
requiresArg is enforced when option is not passed
index.js
```
const yargs = require('yargs');

yargs.options({
  a: {
    type: "string",
    requiresArg: true
  },
});
console.log(yargs.argv);
```
`node index.js` now fails, but it worked in versions prior 10.0.3.

I ran into the problem when using webpack-dev-server, but I think it probably is not the only thing being affected.

I have spent some time on this, and found the behavior was introduced in https://github.com/yargs/yargs/pull/1015.

Pull request:
fix: requiresArg should only be enforced if argument exists
fixes #1041 

CC: @TheLarkInn, @shellscape, @jddxf

Patch:
diff --git a/lib/validation.js b/lib/validation.js
index 3f5c49d..d44d350 100644
--- a/lib/validation.js
+++ b/lib/validation.js
@@ -59,13 +59,15 @@ module.exports = function validation (yargs, usage, y18n) {
   self.missingArgumentValue = function missingArgumentValue (argv) {
     const defaultValues = [true, false, '', undefined]
     const options = yargs.getOptions()
-
     if (options.requiresArg.length > 0) {
       const missingRequiredArgs = []
 
       options.requiresArg.forEach((key) => {
-        const value = argv[key]
+        // if the argument is not set in argv no need to check
+        // whether a right-hand-side has been provided.
+        if (!argv.hasOwnProperty(key)) return
 
+        const value = argv[key]
         // if a value is explicitly requested,
         // flag argument as missing if it does not
         // look like foo=bar was entered.


Test patch:
diff --git a/test/validation.js b/test/validation.js
index cd9fb14..5e8bafe 100644
--- a/test/validation.js
+++ b/test/validation.js
@@ -419,6 +419,16 @@ describe('validation tests', () => {
         .argv
     })
 
+    // see: https://github.com/yargs/yargs/issues/1041
+    it('does not fail if required argument is not provided', (done) => {
+      yargs('')
+        .option('w', {type: 'array', requiresArg: true})
+        .parse('', (err, argv, output) => {
+          expect(err).to.equal(null)
+          return done()
+        })
+    })
+
     it('fails without a message if msg is null', (done) => {
       yargs([])
         .demand(1, null)