diff --git a/index.js b/index.js index 41088f6c..3d65758a 100644 --- a/index.js +++ b/index.js @@ -227,7 +227,7 @@ function parse (args, opts) { next = args[i + 1] key = arg.match(/^-(.\..+)/)[1] - if(!configuration['ignore-unknown-options'] || hasAnyFlag(key)) { + if (!configuration['ignore-unknown-options'] || hasAnyFlag(key)) { if (next !== undefined && !next.match(/^-/) && !checkAllAliases(key, flags.bools) && !checkAllAliases(key, flags.counts)) { @@ -242,7 +242,7 @@ function parse (args, opts) { } else if (arg.match(/^-[^-]+/) && !arg.match(negative)) { letters = arg.slice(1, -1).split('') broken = false - unmatched = [] + let unmatched = [] for (var j = 0; j < letters.length; j++) { next = arg.slice(j + 2) @@ -262,9 +262,9 @@ function parse (args, opts) { } else if (!configuration['ignore-unknown-options'] || hasAnyFlag(key)) { setArg(key, value) } else { - unmatched.push(key); - unmatched.push('='); - unmatched.push(value); + unmatched.push(key) + unmatched.push('=') + unmatched.push(value) } broken = true @@ -275,8 +275,8 @@ function parse (args, opts) { if (!configuration['ignore-unknown-options'] || hasAnyFlag(letters[j])) { setArg(letters[j], next) } else { - unmatched.push(letters[j]); - unmatched.push(next); + unmatched.push(letters[j]) + unmatched.push(next) } continue } @@ -287,8 +287,8 @@ function parse (args, opts) { if (!configuration['ignore-unknown-options'] || hasAnyFlag(letters[j])) { setArg(letters[j], next) } else { - unmatched.push(letters[j]); - unmatched.push(next); + unmatched.push(letters[j]) + unmatched.push(next) } broken = true break @@ -298,8 +298,8 @@ function parse (args, opts) { if (!configuration['ignore-unknown-options'] || hasAnyFlag(letters[j])) { setArg(letters[j], next) } else { - unmatched.push(letters[j]); - unmatched.push(next); + unmatched.push(letters[j]) + unmatched.push(next) } broken = true break @@ -335,7 +335,7 @@ function parse (args, opts) { setArg(key, defaultValue(key)) } } else { - unmatched.push(key); + unmatched.push(key) } } if (unmatched.length > 0) { @@ -805,7 +805,7 @@ function parse (args, opts) { return isSet } - + function hasAnyFlag (key) { var isSet = false var toCheck = [].concat(Object.values(flags)) diff --git a/test/yargs-parser.js b/test/yargs-parser.js index af74a19d..c4f890b8 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -3040,7 +3040,7 @@ describe('yargs-parser', function () { }) argv.should.deep.equal({ _: ['-u=2'], - 'k': 1 + 'k': 1 }) }) it('should ignore unknown options in short format followed by hyphen', function () { @@ -3052,7 +3052,7 @@ describe('yargs-parser', function () { }) argv.should.deep.equal({ _: ['-u-'], - 'k': '-' + 'k': '-' }) }) it('should ignore unknown options in short format separated by space', function () { @@ -3064,7 +3064,7 @@ describe('yargs-parser', function () { }) argv.should.deep.equal({ _: ['-u', 2], - 'k': 1 + 'k': 1 }) }) it('should ignore unknown options in short format followed by a number', function () { @@ -3076,7 +3076,7 @@ describe('yargs-parser', function () { }) argv.should.deep.equal({ _: ['-u2'], - 'k': 1 + 'k': 1 }) }) it('should ignore unknown options in short format followed by a non-word character', function () { @@ -3088,7 +3088,7 @@ describe('yargs-parser', function () { }) argv.should.deep.equal({ _: ['-u/2/'], - 'k': '/1/' + 'k': '/1/' }) }) }) @@ -3101,7 +3101,7 @@ describe('yargs-parser', function () { }) argv.should.deep.equal({ _: ['-u'], - 'k': true, + 'k': true, 'v': true }) it('should ignore unknown options in short format with multiple flags in one argument where an unknown flag is at the end', function () { @@ -3113,7 +3113,7 @@ describe('yargs-parser', function () { }) argv.should.deep.equal({ _: ['-u'], - 'k': true, + 'k': true, 'v': true }) })