Skip to content

feat(pattern): support alternation syntax in command name position#91

Merged
fohte merged 1 commit intomainfrom
fohte/command-name-alternation
Feb 24, 2026
Merged

feat(pattern): support alternation syntax in command name position#91
fohte merged 1 commit intomainfrom
fohte/command-name-alternation

Conversation

@fohte
Copy link
Owner

@fohte fohte commented Feb 24, 2026

Why

  • Allow | (alternation) syntax in the command name position of patterns
    • Commands with aliases (e.g., ast-grep and sg) currently require duplicating the same rule on two separate lines

What

  • Accept alternation syntax in the command name position so that a rule applies when any of the specified command names match

Open with Devin

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Feb 24, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.82%. Comparing base (9882e01) to head (532cccf).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #91      +/-   ##
==========================================
+ Coverage   88.78%   88.82%   +0.03%     
==========================================
  Files          29       29              
  Lines        5705     5707       +2     
==========================================
+ Hits         5065     5069       +4     
+ Misses        640      638       -2     
Flag Coverage Δ
Linux 88.64% <100.00%> (+0.03%) ⬆️
macOS 90.88% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@gemini-code-assist
Copy link

Summary of Changes

Hello @fohte, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request enhances the pattern matching capabilities by introducing support for alternation syntax in the command name position. This allows users to define a single pattern that can match multiple command aliases, significantly reducing redundancy and simplifying pattern definitions for tools with aliased commands.

Highlights

  • New CommandPattern::Alternation variant: Introduced a new Alternation variant to the CommandPattern enum, allowing patterns to match against multiple command names using | syntax (e.g., ast-grep|sg).
  • Updated pattern matching logic: Modified the matches method for CommandPattern to correctly evaluate the new Alternation variant, checking if the given command matches any of the specified alternatives.
  • Enhanced pattern parsing: Updated the parse function to recognize and correctly construct CommandPattern::Alternation when the input pattern includes the | syntax in the command name position.
  • Comprehensive test coverage: Added new rstest test cases to validate the parsing of command alternations with various numbers of aliases and to ensure the matches logic functions as expected for these new patterns.
Changelog
  • src/rules/pattern_parser.rs
    • Added Alternation variant to CommandPattern enum to represent multiple command names.
    • Updated CommandPattern::matches to support matching against Alternation variants.
    • Modified parse function to handle LexToken::Alternation and create CommandPattern::Alternation.
    • Included new test cases for parsing and matching command alternation patterns.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for alternation syntax in the command name position of patterns, allowing rules to apply to multiple command aliases (e.g., "ast-grep|sg"). The changes include adding a new Alternation variant to the CommandPattern enum, updating the matches logic, and integrating it into the parse function. New parameterized tests have been added to cover this functionality, ensuring correctness and adherence to the testing style guide by naming #[case] variants and using rstest effectively. The implementation is clean and directly addresses the stated goal of improving pattern flexibility.

Copy link
Contributor

@devin-ai-integration devin-ai-integration bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no potential bugs to report.

View in Devin Review to see 3 additional findings.

Open in Devin Review

@fohte fohte merged commit 6fabb81 into main Feb 24, 2026
6 checks passed
@fohte fohte deleted the fohte/command-name-alternation branch February 24, 2026 15:21
@fohte-bot fohte-bot bot mentioned this pull request Feb 24, 2026
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