Skip to content

fix: respect dot option in brace alternatives - #200

Open
mrmlnc wants to merge 1 commit into
masterfrom
fg-405
Open

mrmlnc wants to merge 1 commit into
masterfrom
fg-405

Conversation

@mrmlnc

@mrmlnc mrmlnc commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Fix leading-dot handling for direct brace alternatives that begin with a star wildcard (*) or a negated extglob (!(...)) when the brace group starts a path segment.

Previously, these alternatives were not recognized as segment starts because their preceding token is { or , rather than the beginning of the pattern or /. As a result, they could match dotfiles even when dot was disabled.

picomatch.isMatch('.js', '**/{*.js,x}', { dot: false });
// before: true
// after:  false

picomatch.isMatch('.mts', '**/{x,!(*.d).mts}', { dot: false });
// before: true
// after:  false

This fixes the pattern reported in mrmlnc/fast-glob#405:

**/{!(*.d).mts,!(*.d).cts,*.{mjs,cjs,js}}

Implementation

When parsing an ordinary * or !(...), use the existing brace stack and token chain to determine whether the token belongs to a direct brace alternative at the beginning of a path segment.

This allows the parser to:

  • handle both the first and subsequent brace alternatives;
  • apply the rule only when the brace group itself starts a path segment;
  • ignore commas owned by nested extglobs;
  • preserve mid-segment and literal-brace behavior;
  • distinguish an ordinary * from the *(...) extglob;
  • preserve zero-length *(...) matches;
  • preserve bash, dot, and noextglob behavior.

No additional parser metadata is introduced.

Scope

This change handles direct, flat brace alternatives only.

Nested-brace alternatives such as {a,{*.js,b}} remain outside its scope. Supporting them requires propagating path-segment context through enclosing brace groups. An alternative implementation covering that case is available in micromatch/picomatch#193.

Refs

mrmlnc/fast-glob#405

@github-code-quality

github-code-quality Bot commented Aug 24, 2026

Copy link
Copy Markdown

Code Coverage Overview

Languages: JavaScript

JavaScript / code-coverage/nyc

The overall line coverage in commit 6b3bc3e in the fg-405 branch is 96%. Line coverage data for the master branch is not yet available.

Show a line coverage summary of the most covered files.
File master fg-405 6b3bc3e +/-
lib/constants.js 100%
index.js 100%
posix.js 100%
lib/scan.js 99%
lib/parse.js 95%
lib/picomatch.js 95%
lib/utils.js 90%

Updated August 25, 2026 10:03 UTC

@mrmlnc
mrmlnc marked this pull request as ready for review August 24, 2026 21:22
@mrmlnc
mrmlnc marked this pull request as draft August 24, 2026 22:08
@mrmlnc
mrmlnc force-pushed the fg-405 branch 4 times, most recently from 8ed4726 to 73b5a72 Compare August 25, 2026 09:35
@mrmlnc
mrmlnc marked this pull request as ready for review August 25, 2026 10:04
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