Repository: yargs/yargs (js)

Issue:
Hidden option is not recognized
An option is not recognised when declared `hidden` by specifying a `falsy` describe.

```js
var yargs = require("yargs");

yargs
.strict()
.option('foo', { type: 'boolean', describe: false })
.parse(['node', 'my-script.js', '--foo']);

// "Unknown argument: foo"
```

```js
var yargs = require("yargs");

yargs
.strict()
.option('foo', { type: 'boolean', describe: 'Foo option' })
.parse(['node', 'my-script.js', '--foo']);

// { foo: true }
```

Am I missing something here?

Thanks!

Pull request:
fix: strict mode should not fail for hidden options
Address a bug @satazor found related to `strict()` mode firing for hidden options -- in the process I cleaned up strict mode logic for options a bit ... it seems like simply looking at the `aliases` map covers most of our bases.

fixes #948 

Patch:
diff --git a/lib/validation.js b/lib/validation.js
index f66c04f..0b322a3 100644
--- a/lib/validation.js
+++ b/lib/validation.js
@@ -120,26 +120,16 @@ module.exports = function validation (yargs, usage, y18n) {
 
   // check for unknown arguments (strict-mode).
   self.unknownArguments = function unknownArguments (argv, aliases, positionalMap) {
-    const aliasLookup = {}
-    const descriptions = usage.getDescriptions()
-    const demandedOptions = yargs.getDemandedOptions()
     const commandKeys = yargs.getCommandInstance().getCommands()
     const unknown = []
     const currentContext = yargs.getContext()
 
-    Object.keys(aliases).forEach((key) => {
-      aliases[key].forEach((alias) => {
-        aliasLookup[alias] = key
-      })
-    })
-
     Object.keys(argv).forEach((key) => {
       if (specialKeys.indexOf(key) === -1 &&
-        !descriptions.hasOwnProperty(key) &&
-        !demandedOptions.hasOwnProperty(key) &&
         !positionalMap.hasOwnProperty(key) &&
         !yargs._getParseContext().hasOwnProperty(key) &&
-        !aliasLookup.hasOwnProperty(key)) {
+        !aliases.hasOwnProperty(key)
+      ) {
         unknown.push(key)
       }
     })


Test patch:
diff --git a/test/validation.js b/test/validation.js
index 685d61d..b65c19f 100644
--- a/test/validation.js
+++ b/test/validation.js
@@ -724,6 +724,32 @@ describe('validation tests', () => {
             })
         .argv
     })
+
+    it('does not fail for hidden options', () => {
+      const args = yargs('--foo hey')
+        .strict()
+        .option('foo', {boolean: true, describe: false})
+        .fail((msg) => {
+          expect.fail()
+        })
+        .argv
+      args.foo.should.equal(true)
+    })
+
+    it('does not fail if an alias is provided, rather than option itself', () => {
+      const args = yargs('--cat hey')
+        .strict()
+        .option('foo', {boolean: true, describe: false})
+        .alias('foo', 'bar')
+        .alias('bar', 'cat')
+        .fail((msg) => {
+          expect.fail()
+        })
+        .argv
+      args.cat.should.equal(true)
+      args.foo.should.equal(true)
+      args.bar.should.equal(true)
+    })
   })
 
   describe('demandOption', () => {