From 95536a09a1b2725599ec547bda4df156868ebdbe Mon Sep 17 00:00:00 2001 From: John Gee Date: Tue, 12 Apr 2022 00:38:45 +1200 Subject: [PATCH] refactor: updates to comments and code per feedback (#101) --- index.js | 1 - test/index.js | 16 ++++++++-------- utils.js | 18 +++++++++--------- 3 files changed, 17 insertions(+), 18 deletions(-) diff --git a/index.js b/index.js index f69fba3..4cc0c4a 100644 --- a/index.js +++ b/index.js @@ -174,7 +174,6 @@ const parseArgs = ({ ArrayPrototypePush(expanded, `-${shortOption}`); } else { // String option in middle. Yuck. - // ToDo: if strict then throw // Expand -abfFILE to -a -b -fFILE ArrayPrototypePush(expanded, `-${StringPrototypeSlice(arg, index)}`); break; // finished short group diff --git a/test/index.js b/test/index.js index 576478d..9562586 100644 --- a/test/index.js +++ b/test/index.js @@ -91,7 +91,7 @@ test('short option group does not consume subsequent positional', (t) => { t.end(); }); -// // See: Guideline 5 https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html +// See: Guideline 5 https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html test('if terminal of short-option group configured `type: "string"`, subsequent positional is stored', (t) => { const passedArgs = ['-rvf', 'foo']; const passedOptions = { f: { type: 'string' } }; @@ -249,7 +249,7 @@ test('when expecting `multiple:true` boolean option and option used multiple tim t.end(); }); -test('order of option and positional does not matter (per README)', function(t) { +test('order of option and positional does not matter (per README)', (t) => { const passedArgs1 = ['--foo=bar', 'baz']; const passedArgs2 = ['baz', '--foo=bar']; const passedOptions = { foo: { type: 'string' } }; @@ -362,17 +362,17 @@ test('invalid argument passed for options', (t) => { const passedArgs = ['--so=wat']; const passedOptions = 'bad value'; - t.throws(function() { parseArgs({ args: passedArgs, options: passedOptions }); }, { + t.throws(() => { parseArgs({ args: passedArgs, options: passedOptions }); }, { code: 'ERR_INVALID_ARG_TYPE' }); t.end(); }); -test('then type property missing for option then throw', function(t) { +test('then type property missing for option then throw', (t) => { const knownOptions = { foo: { } }; - t.throws(function() { parseArgs({ options: knownOptions }); }, { + t.throws(() => { parseArgs({ options: knownOptions }); }, { code: 'ERR_INVALID_ARG_TYPE' }); @@ -383,7 +383,7 @@ test('boolean passed to "type" option', (t) => { const passedArgs = ['--so=wat']; const passedOptions = { foo: { type: true } }; - t.throws(function() { parseArgs({ args: passedArgs, options: passedOptions }); }, { + t.throws(() => { parseArgs({ args: passedArgs, options: passedOptions }); }, { code: 'ERR_INVALID_ARG_TYPE' }); @@ -394,7 +394,7 @@ test('invalid union value passed to "type" option', (t) => { const passedArgs = ['--so=wat']; const passedOptions = { foo: { type: 'str' } }; - t.throws(function() { parseArgs({ args: passedArgs, options: passedOptions }); }, { + t.throws(() => { parseArgs({ args: passedArgs, options: passedOptions }); }, { code: 'ERR_INVALID_ARG_TYPE' }); @@ -405,7 +405,7 @@ test('invalid short option length', (t) => { const passedArgs = []; const passedOptions = { foo: { short: 'fo', type: 'boolean' } }; - t.throws(function() { parseArgs({ args: passedArgs, options: passedOptions }); }, { + t.throws(() => { parseArgs({ args: passedArgs, options: passedOptions }); }, { code: 'ERR_INVALID_ARG_VALUE' }); diff --git a/utils.js b/utils.js index b921b96..b718c01 100644 --- a/utils.js +++ b/utils.js @@ -43,7 +43,7 @@ function isOptionValue(value) { } /** - * Determines if `arg` is a just a short option. + * Determines if `arg` is just a short option. * @example '-f' */ function isLoneShortOption(arg) { @@ -57,7 +57,7 @@ function isLoneShortOption(arg) { * @example * isLoneLongOption('a') // returns false * isLoneLongOption('-a') // returns false - * isLoneLongOption('--foo) // returns true + * isLoneLongOption('--foo') // returns true * isLoneLongOption('--foo=bar') // returns false */ function isLoneLongOption(arg) { @@ -69,7 +69,7 @@ function isLoneLongOption(arg) { /** * Determines if `arg` is a long option and value in the same argument. * @example - * isLongOptionAndValue('--foo) // returns false + * isLongOptionAndValue('--foo') // returns false * isLongOptionAndValue('--foo=bar') // returns true */ function isLongOptionAndValue(arg) { @@ -90,14 +90,14 @@ function isLongOptionAndValue(arg) { * isShortOptionGroup('-ab', {}) // returns true * // -fb is an option and a value, not a short option group * isShortOptionGroup('-fb', { - * options: { f: { type: 'string' }} + * options: { f: { type: 'string' } } * }) // returns false * isShortOptionGroup('-bf', { - * options: { f: { type: 'string' }} + * options: { f: { type: 'string' } } * }) // returns true * // -bfb is an edge case, return true and caller sorts it out * isShortOptionGroup('-bfb', { - * options: { f: { type: 'string' }} + * options: { f: { type: 'string' } } * }) // returns true */ function isShortOptionGroup(arg, options) { @@ -111,10 +111,10 @@ function isShortOptionGroup(arg, options) { } /** - * Determine is arg is a short string option followed by its value. + * Determine if arg is a short string option followed by its value. * @example - * isShortOptionAndValue('-a, {}); // returns false - * isShortOptionAndValue('-ab, {}); // returns false + * isShortOptionAndValue('-a', {}); // returns false + * isShortOptionAndValue('-ab', {}); // returns false * isShortOptionAndValue('-fFILE', { * options: { foo: { short: 'f', type: 'string' }} * }) // returns true