Skip to content

Commit 95536a0

Browse files
authored
refactor: updates to comments and code per feedback (#101)
1 parent be153db commit 95536a0

File tree

3 files changed

+17
-18
lines changed

3 files changed

+17
-18
lines changed

index.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ const parseArgs = ({
174174
ArrayPrototypePush(expanded, `-${shortOption}`);
175175
} else {
176176
// String option in middle. Yuck.
177-
// ToDo: if strict then throw
178177
// Expand -abfFILE to -a -b -fFILE
179178
ArrayPrototypePush(expanded, `-${StringPrototypeSlice(arg, index)}`);
180179
break; // finished short group

test/index.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ test('short option group does not consume subsequent positional', (t) => {
9191
t.end();
9292
});
9393

94-
// // See: Guideline 5 https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
94+
// See: Guideline 5 https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html
9595
test('if terminal of short-option group configured `type: "string"`, subsequent positional is stored', (t) => {
9696
const passedArgs = ['-rvf', 'foo'];
9797
const passedOptions = { f: { type: 'string' } };
@@ -249,7 +249,7 @@ test('when expecting `multiple:true` boolean option and option used multiple tim
249249
t.end();
250250
});
251251

252-
test('order of option and positional does not matter (per README)', function(t) {
252+
test('order of option and positional does not matter (per README)', (t) => {
253253
const passedArgs1 = ['--foo=bar', 'baz'];
254254
const passedArgs2 = ['baz', '--foo=bar'];
255255
const passedOptions = { foo: { type: 'string' } };
@@ -362,17 +362,17 @@ test('invalid argument passed for options', (t) => {
362362
const passedArgs = ['--so=wat'];
363363
const passedOptions = 'bad value';
364364

365-
t.throws(function() { parseArgs({ args: passedArgs, options: passedOptions }); }, {
365+
t.throws(() => { parseArgs({ args: passedArgs, options: passedOptions }); }, {
366366
code: 'ERR_INVALID_ARG_TYPE'
367367
});
368368

369369
t.end();
370370
});
371371

372-
test('then type property missing for option then throw', function(t) {
372+
test('then type property missing for option then throw', (t) => {
373373
const knownOptions = { foo: { } };
374374

375-
t.throws(function() { parseArgs({ options: knownOptions }); }, {
375+
t.throws(() => { parseArgs({ options: knownOptions }); }, {
376376
code: 'ERR_INVALID_ARG_TYPE'
377377
});
378378

@@ -383,7 +383,7 @@ test('boolean passed to "type" option', (t) => {
383383
const passedArgs = ['--so=wat'];
384384
const passedOptions = { foo: { type: true } };
385385

386-
t.throws(function() { parseArgs({ args: passedArgs, options: passedOptions }); }, {
386+
t.throws(() => { parseArgs({ args: passedArgs, options: passedOptions }); }, {
387387
code: 'ERR_INVALID_ARG_TYPE'
388388
});
389389

@@ -394,7 +394,7 @@ test('invalid union value passed to "type" option', (t) => {
394394
const passedArgs = ['--so=wat'];
395395
const passedOptions = { foo: { type: 'str' } };
396396

397-
t.throws(function() { parseArgs({ args: passedArgs, options: passedOptions }); }, {
397+
t.throws(() => { parseArgs({ args: passedArgs, options: passedOptions }); }, {
398398
code: 'ERR_INVALID_ARG_TYPE'
399399
});
400400

@@ -405,7 +405,7 @@ test('invalid short option length', (t) => {
405405
const passedArgs = [];
406406
const passedOptions = { foo: { short: 'fo', type: 'boolean' } };
407407

408-
t.throws(function() { parseArgs({ args: passedArgs, options: passedOptions }); }, {
408+
t.throws(() => { parseArgs({ args: passedArgs, options: passedOptions }); }, {
409409
code: 'ERR_INVALID_ARG_VALUE'
410410
});
411411

utils.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ function isOptionValue(value) {
4343
}
4444

4545
/**
46-
* Determines if `arg` is a just a short option.
46+
* Determines if `arg` is just a short option.
4747
* @example '-f'
4848
*/
4949
function isLoneShortOption(arg) {
@@ -57,7 +57,7 @@ function isLoneShortOption(arg) {
5757
* @example
5858
* isLoneLongOption('a') // returns false
5959
* isLoneLongOption('-a') // returns false
60-
* isLoneLongOption('--foo) // returns true
60+
* isLoneLongOption('--foo') // returns true
6161
* isLoneLongOption('--foo=bar') // returns false
6262
*/
6363
function isLoneLongOption(arg) {
@@ -69,7 +69,7 @@ function isLoneLongOption(arg) {
6969
/**
7070
* Determines if `arg` is a long option and value in the same argument.
7171
* @example
72-
* isLongOptionAndValue('--foo) // returns false
72+
* isLongOptionAndValue('--foo') // returns false
7373
* isLongOptionAndValue('--foo=bar') // returns true
7474
*/
7575
function isLongOptionAndValue(arg) {
@@ -90,14 +90,14 @@ function isLongOptionAndValue(arg) {
9090
* isShortOptionGroup('-ab', {}) // returns true
9191
* // -fb is an option and a value, not a short option group
9292
* isShortOptionGroup('-fb', {
93-
* options: { f: { type: 'string' }}
93+
* options: { f: { type: 'string' } }
9494
* }) // returns false
9595
* isShortOptionGroup('-bf', {
96-
* options: { f: { type: 'string' }}
96+
* options: { f: { type: 'string' } }
9797
* }) // returns true
9898
* // -bfb is an edge case, return true and caller sorts it out
9999
* isShortOptionGroup('-bfb', {
100-
* options: { f: { type: 'string' }}
100+
* options: { f: { type: 'string' } }
101101
* }) // returns true
102102
*/
103103
function isShortOptionGroup(arg, options) {
@@ -111,10 +111,10 @@ function isShortOptionGroup(arg, options) {
111111
}
112112

113113
/**
114-
* Determine is arg is a short string option followed by its value.
114+
* Determine if arg is a short string option followed by its value.
115115
* @example
116-
* isShortOptionAndValue('-a, {}); // returns false
117-
* isShortOptionAndValue('-ab, {}); // returns false
116+
* isShortOptionAndValue('-a', {}); // returns false
117+
* isShortOptionAndValue('-ab', {}); // returns false
118118
* isShortOptionAndValue('-fFILE', {
119119
* options: { foo: { short: 'f', type: 'string' }}
120120
* }) // returns true

0 commit comments

Comments
 (0)