Repository: yargs/yargs (js)

Issue:
.strict() allows extra args
Documentation states that in strict mode, extra arguments are reported as errors. However, none of the constructs allowed by yargs seems to demonstrate that behaviour. For example, the following configs:

```js
require("yargs")
  .command("foo <bar>")
  .strict()
  .argv
```
```js
require("yargs")
  .command("foo <bar>", "foo cmd", yargs => yargs.strict())
  .strict()
  .argv
```
```js
require("yargs")
  .command({
    command: "foo <bar>",
    builder: yargs => yargs.strict()
  })
  .command({
    command: "baz <qux>",
    builder: yargs => yargs.strict()
  })
  .demandCommand()
  .strict()
  .argv;
```
all result in commands like

```
$ ./cmd foo 123 extra
$ ./cmd bar 456 extra-1 extra-2
```

being accepted without any error.

Pull request description:
fix!: do not allow additional positionals in strict mode
The test was disabled for commandless yargs, but as the validation is done on the innermost yargs, it was always disabled.

Closes #1313 

Patch:
diff --git a/lib/validation.js b/lib/validation.js
index e9bbb12..5cbe964 100644
--- a/lib/validation.js
+++ b/lib/validation.js
@@ -102,7 +102,7 @@ module.exports = function validation (yargs, usage, y18n) {
       }
     })
 
-    if (commandKeys.length > 0) {
+    if ((currentContext.commands.length > 0) || (commandKeys.length > 0)) {
       argv._.slice(currentContext.commands.length).forEach((key) => {
         if (commandKeys.indexOf(key) === -1) {
           unknown.push(key)


Test patch:
diff --git a/test/validation.js b/test/validation.js
index f704816..bd0bd1d 100644
--- a/test/validation.js
+++ b/test/validation.js
@@ -335,6 +335,18 @@ describe('validation tests', () => {
         .parse()
     })
 
+    it('fails in strict mode with extra positionals', (done) => {
+      yargs(['kangaroo', 'jumping', 'fast'])
+        .command('kangaroo <status>', 'kangaroo handlers')
+        .strict()
+        .fail((msg) => {
+          msg.should.equal('Unknown argument: fast')
+          return done()
+        })
+        .parse()
+      expect.fail('no parsing failure')
+    })
+
     it('does not fail in strict mode when no commands configured', () => {
       const argv = yargs('koala')
         .demand(1)