Skip to content

Commit

Permalink
refactor to if / else if / else if and remove the early returns.
Browse files Browse the repository at this point in the history
  • Loading branch information
alicewriteswrongs committed Nov 3, 2022
1 parent 1b67a3b commit 59cd113
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions src/cli/parse-flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,35 +127,31 @@ const parseCLITerm = (flags: ConfigFlags, args: string[]) => {
// we're dealing with an EqualsArg, we have a special helper for that
const [originalArg, value] = parseEqualsArg(arg);
setCLIArg(flags, arg.split('=')[0], normalizeFlagName(originalArg), value);
return;
}

// AliasEqualsArg → "-" AliasName "=" CLIValue ;
if (arg.startsWith('-') && arg.includes('=')) {
else if (arg.startsWith('-') && arg.includes('=')) {
// we're dealing with an AliasEqualsArg, we have a special helper for that
const [originalArg, value] = parseEqualsArg(arg);
setCLIArg(flags, arg.split('=')[0], normalizeFlagName(originalArg), value);
return;
}

// AliasArg → "-" AliasName ( " " CLIValue )? ;
if (CLI_FLAG_REGEX.test(arg)) {
else if (CLI_FLAG_REGEX.test(arg)) {
// this is a short alias, like `-c` for Config
setCLIArg(flags, arg, normalizeFlagName(arg), parseCLIValue(args));
return;
}

// NegativeDashArg → "--no-" ArgName ;
if (arg.startsWith('--no-') && arg.length > 5) {
else if (arg.startsWith('--no-') && arg.length > 5) {
// this is a `NegativeDashArg` term, so we need to normalize the negative
// flag name and then set an appropriate value
const normalized = normalizeNegativeFlagName(arg);
setCLIArg(flags, arg, normalized, '');
return;
}

// NegativeArg → "--no" ArgName ;
if (
else if (
arg.startsWith('--no') &&
!readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizeFlagName(arg)) &&
readOnlyArrayHasStringMember(BOOLEAN_CLI_FLAGS, normalizeNegativeFlagName(arg))
Expand All @@ -165,14 +161,18 @@ const parseCLITerm = (flags: ConfigFlags, args: string[]) => {
// `notify`, so we need to test if a normalized form of the raw argument is
// a valid and supported boolean flag.
setCLIArg(flags, arg, normalizeNegativeFlagName(arg), '');
return;
}

// SimpleArg → "--" ArgName ( " " CLIValue )? ;
if (arg.startsWith('--') && arg.length > 2) {
else if (arg.startsWith('--') && arg.length > 2) {
setCLIArg(flags, arg, normalizeFlagName(arg), parseCLIValue(args));
return;
}

// if we get here it is not an argument in our list of supported arguments.
// This doesn't necessarily mean we want to report an error or anything
// though! Instead, with unknown / unrecognized arguments we stick them into
// the `unknownArgs` array, which is used when we pass CLI args to Jest, for
// instance. So we just return void here.
};

/**
Expand Down

0 comments on commit 59cd113

Please sign in to comment.