Skip to content

fix: validate negative deep option values#501

Open
abhu85 wants to merge 1 commit into
mrmlnc:masterfrom
abhu85:fix/validate-negative-deep-500
Open

fix: validate negative deep option values#501
abhu85 wants to merge 1 commit into
mrmlnc:masterfrom
abhu85:fix/validate-negative-deep-500

Conversation

@abhu85
Copy link
Copy Markdown

@abhu85 abhu85 commented Feb 23, 2026

Summary

This PR adds validation for the deep option to throw a TypeError when a negative value is provided.

Fixes #500

Problem

Currently, fast-glob accepts negative values for the deep option without any error or warning, even though negative depth doesn't make logical sense:

import fg from 'fast-glob';

const results = await fg('**/*.js', { 
  deep: -10,  // This is accepted but semantically invalid
  cwd: '.' 
});

This can lead to:

  • Unexpected behavior in consuming code
  • Unclear semantics (what does negative depth mean?)
  • Potential bugs that are hard to track down

Solution

Add validation at the start of the Settings constructor to throw a TypeError when deep is negative:

if (options.deep !== undefined && options.deep < 0) {
  throw new TypeError(`options.deep must be a non-negative number, received: ${options.deep}`);
}

Test plan

  • Added unit tests for negative deep values (-1, -10)
  • Added tests confirming zero and positive values still work correctly
  • Verified validation runs before other option processing

Notes

The build currently has a pre-existing issue with fdir and @types/picomatch dependencies (TS1259 error). The new tests follow the existing test patterns and were verified manually with ts-node.

Throw a TypeError when the `deep` option is set to a negative value,
as negative depth doesn't make logical sense and can lead to unexpected
behavior in consuming code.

Fixes mrmlnc#500

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant