parseArgs: --help and --version silently accept extra positional arguments
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 75/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- cli
Research direction
Start by locating the parseArgs entry point and reproduce the documented --help and --version cases with extra positional arguments. Update the argument validation so these flags do not silently discard extras, while preserving the existing config-path behavior; done means the reproductions throw the expected error and normal help/version parsing still works.
Written by the indexing model from the issue text.
Description
Observed behavior
parseArgs short-circuits when either --help or --version is present and returns immediately, before the positional.length > 1 check that was added to reject extra positional arguments (see #33). As a result:
parseArgs(['--help']) -> { help: true, ... } (OK)
parseArgs(['--help', 'foo', 'bar']) -> { help: true, ... } (silently ignores foo, bar)
parseArgs(['--version', 'extra1', 'extra2']) -> { version: true, ... } (silently ignores extras)
parseArgs(['config.json', 'extra']) -> THROW: Unexpected extra arguments: extra (correct)
The relevant block in parseArgs:
if (booleans.help || booleans.version) {
return {
help: booleans.help,
version: booleans.version,
verbose: booleans.verbose,
dryRun: booleans.dryRun,
maxPrompts,
};
}
if (positional.length > 1) {
throw new Error(
`Unexpected extra arguments: ${positional.slice(1).join(' ')}`,
);
}
Expected behavior
For consistency with #33's fix, --help and --version should also reject extra positional arguments (or at least reject anything beyond a single positional). Silent acceptance hides typos like loop-the-loop --help confg.json and is inconsistent with the rest of the parser's strictness.
Minimal reproduction
parseArgs(['--help', 'foo', 'bar']);
// Returns { help: true, ... } with no warning that 'foo' and 'bar' were dropped.
Suggested fix
Move the positional.length > 1 check (or a positional.length > 0 check for the help/version branch) above the help/version short-circuit, or duplicate it inside the branch. For example:
if (booleans.help || booleans.version) {
if (positional.length > 0) {
throw new Error(
`Unexpected extra arguments: ${positional.join(' ')}`,
);
}
return { help: booleans.help, version: booleans.version, ... };
}
This mirrors how the parser already treats trailing args after a config path.
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from joewalker/loop-the-loop
-
Git exec(): child killed by a signal rejects with new Error('') and loses the signal information Openbug S3
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
joewalker/loop-the-loop#84 ·
-
bug S3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
joewalker/loop-the-loop#83 ·
-
bug S3
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
joewalker/loop-the-loop#82 ·
-
bug S4
Difficulty 1/5 Under an hour Newbie friendliness 90/100
joewalker/loop-the-loop#79 ·
-
bug S4
Difficulty 1/5 Under an hour Newbie friendliness 92/100
joewalker/loop-the-loop#78 ·
All issues in joewalker/loop-the-loop
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100