From 7a75525196a2ace4fb21707b2aa34c1416a5681a Mon Sep 17 00:00:00 2001 From: Eric Henderson Date: Sun, 9 Jun 2019 08:58:47 -0400 Subject: [PATCH] fix formatting and add a missing "let" keyword --- index.js | 26 +++++++++++++------------- test/yargs-parser.js | 14 +++++++------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/index.js b/index.js index a101b8f9..692a5985 100644 --- a/index.js +++ b/index.js @@ -218,7 +218,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)) { @@ -233,7 +233,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) @@ -253,9 +253,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 @@ -266,8 +266,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 } @@ -278,8 +278,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 @@ -289,8 +289,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 @@ -326,7 +326,7 @@ function parse (args, opts) { setArg(key, defaultValue(key)) } } else { - unmatched.push(key); + unmatched.push(key) } } if (unmatched.length > 0) { @@ -794,7 +794,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 34339b06..5b8b6569 100644 --- a/test/yargs-parser.js +++ b/test/yargs-parser.js @@ -3092,7 +3092,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 () { @@ -3104,7 +3104,7 @@ describe('yargs-parser', function () { }) argv.should.deep.equal({ _: ['-u-'], - 'k': '-' + 'k': '-' }) }) it('should ignore unknown options in short format separated by space', function () { @@ -3116,7 +3116,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 () { @@ -3128,7 +3128,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 () { @@ -3140,7 +3140,7 @@ describe('yargs-parser', function () { }) argv.should.deep.equal({ _: ['-u/2/'], - 'k': '/1/' + 'k': '/1/' }) }) }) @@ -3153,7 +3153,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 () { @@ -3165,7 +3165,7 @@ describe('yargs-parser', function () { }) argv.should.deep.equal({ _: ['-u'], - 'k': true, + 'k': true, 'v': true }) })