Skip to content

fix(rules): let doublestar expand brace groups in rule and filter patterns - #2099

Open
alex09x wants to merge 1 commit into
alibaba:mainfrom
alex09x:fix/nested-brace-patterns
Open

alex09x wants to merge 1 commit into
alibaba:mainfrom
alex09x:fix/nested-brace-patterns

Conversation

@alex09x

@alex09x alex09x commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Description

expandBraces split a pattern at its first { and its first } before matching. It served rules, include and exclude in rule.json and the built-in path_rule_map, and broke two kinds of patterns:

  • nested groups: **/*.{ts,{js,jsx}} became *.ts}, *.{js} and *.jsx}, so only .js matched;
  • escaped braces: pages/\{id\}.ts was split as a group and never matched the literal pages/{id}.ts.

doublestar already expands brace groups, including nested groups and backslash escapes, so IsUserIncluded, IsUserExcluded, matchProjectRuleEntry and SystemRule.resolveDetail now hand it the whole lowercased pattern through one matchGlob helper. Patterns with a single group match exactly as before, and RuleDetail.Pattern still reports the original pattern.

expandBraces moves to the test file: only the system-rule integrity check that reads each arm's extension still needs it. The validity check now validates the whole pattern with doublestar.ValidatePattern, since that is what matching uses.

I first tried a full recursive expansion instead. It would also have rewritten braces inside [...] classes and built every combination of several groups for each path checked, so handing the pattern to doublestar is both simpler and exact.

Type of Change

  • Bug fix (non-breaking change that fixes an issue)
  • New feature (non-breaking change that adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Refactoring (no functional changes)
  • Documentation update
  • CI / Build / Tooling

How Has This Been Tested?

  • make test passes locally

  • Manual testing (describe below)

  • New TestBracePatternsMatchLikeDoublestar checks nested groups, a nested group in a suffix, two groups, escaped literal braces and an unclosed group against all four matchers, and first asserts each expectation against doublestar.Match itself. On the previous expandBraces 6 of its 10 cases fail (the nested and escaped ones); with this change all pass.

  • LC_ALL=C go test ./internal/config/rules/...: 534 passed. gofmt -s -l and go vet are clean.

  • ocr review --audience agent on the change: 0 findings.

Checklist

  • My code follows the project's coding style (go fmt, go vet)
  • I have performed a self-review of my code
  • I have added tests that prove my fix is effective or my feature works
  • New and existing unit tests pass locally with my changes
  • I have updated the documentation accordingly (if applicable)
  • I have signed the CLA
  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Used Claude Code (Claude Opus 5.5).

Related Issues

Closes #2097

…terns

expandBraces cut a pattern at its first '{' and first '}', so nested groups
such as **/*.{ts,{js,jsx}} stopped matching .ts and .jsx files and escaped
braces were split as a group. doublestar already reads both correctly, so
rules, include and exclude now hand it the whole pattern.
@github-actions

github-actions Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

🔍 OpenCodeReview found 1 issue(s) in this PR.

  • ✅ Successfully posted inline: 0 comment(s)
  • ❌ Failed to post inline: 1 comment(s)

documentation · low

📄 internal/config/rules/system_rules.go (L146-L146)

⚠️ GitHub could not post this as an inline comment: Line 146 could not be resolved (outside PR diff hunks)

This comment describes the old expandBraces behavior (splitting into individual strings). After this refactor, brace expansion is handled internally by doublestar.Match, which also supports nested groups ({ts,{js,jsx}}), multiple groups per pattern, and escaped literal braces. Consider updating the comment to reflect the current mechanism, e.g.:

// Patterns support full glob syntax including ** for recursive directory matching
// and brace expansion (e.g. "*.{go,py}", nested groups, escaped braces).
// The first match wins; if none match, it falls back to DefaultRule.

This branch has not been deployed

No deployments
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.

Nested or escaped braces in rule, include and exclude patterns are split wrongly (**/*.{ts,{js,jsx}} drops .ts)

1 participant