Skip to content

fix(rules): prevent flag negation from being consumed as preceding flag's value#191

Merged
fohte merged 3 commits intomainfrom
fohte/fix-negation-requires-token
Mar 12, 2026
Merged

fix(rules): prevent flag negation from being consumed as preceding flag's value#191
fohte merged 3 commits intomainfrom
fohte/fix-negation-requires-token

Conversation

@fohte
Copy link
Owner

@fohte fohte commented Mar 11, 2026

Why

  • --flag !--other-flag patterns incorrectly consumed !--other-flag as the preceding flag's value instead of treating it as an independent negation token
    • Rules like git interpret-trailers --parse !--in-place * failed to match git interpret-trailers --parse

What

  • Treat flag negations (!--flag, !-f) as independent tokens rather than consuming them as flag values

Open with Devin

…ag's value

A flag negation like `!--in-place` following a bare flag like `--parse` was
incorrectly parsed as the flag's value (FlagWithValue), causing the pattern
`git interpret-trailers --parse !--in-place *` to never match any command.

Treat negation tokens whose inner value is a flag as independent negation
tokens rather than flag values in `should_consume_as_value`.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@gemini-code-assist
Copy link

Summary of Changes

Hello, 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 addresses a critical parsing bug that caused command-line patterns with negated flags to be misinterpreted. By refining the token consumption logic, the system now accurately distinguishes negated flags from flag values, leading to more reliable rule matching and preventing unexpected failures in command evaluation.

Highlights

  • Parsing Correction: Fixed an issue where flag negation tokens (e.g., !--other-flag) were incorrectly consumed as the value of a preceding flag, rather than being treated as independent negation tokens.
  • Rule Matching: Ensured that rules involving flag negations, such as git interpret-trailers --parse !--in-place *, now correctly match commands by properly recognizing the negated flag as a distinct element.
Changelog
  • src/rules/pattern_matcher/mod.rs
    • Added new test cases to negation_matching to cover scenarios involving long flag negations, ensuring they are correctly handled when preceded by other arguments.
  • src/rules/pattern_parser.rs
    • Modified the should_consume_as_value function to explicitly prevent flag negations (e.g., !--flag, !-f) from being consumed as values, treating them as independent tokens.
    • Introduced a new test case flag_not_consuming_flag_negation to validate the updated parsing behavior for negated flags.
  • tests/integration/config_to_rule_evaluation.rs
    • Added a new integration test suite long_flag_negation_with_preceding_literals to verify the end-to-end evaluation of rules containing long flag negations.
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
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 2 additional findings.

Open in Devin Review

@codecov
Copy link

codecov bot commented Mar 11, 2026

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.29%. Comparing base (a470cd0) to head (6d47e93).
⚠️ Report is 6 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/pattern_parser.rs 50.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #191      +/-   ##
==========================================
- Coverage   90.41%   90.29%   -0.12%     
==========================================
  Files          40       40              
  Lines        7520     7522       +2     
==========================================
- Hits         6799     6792       -7     
- Misses        721      730       +9     
Flag Coverage Δ
Linux 90.16% <50.00%> (+0.09%) ⬆️
macOS 91.93% <50.00%> (-0.16%) ⬇️

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[bot]

This comment was marked as resolved.

fohte added 2 commits March 12, 2026 09:00
The comment said "no trailing arguments" but two of the three test
cases do include trailing arguments. Simplify to match all cases.
The parser previously consumed `!--flag` as a preceding flag's value.
Add PBT to verify `{cmd} {literal} !{flag} *` patterns correctly
allow when the negated flag is absent and reject when present.
@fohte fohte merged commit 31b76a8 into main Mar 12, 2026
7 checks passed
@fohte fohte deleted the fohte/fix-negation-requires-token branch March 12, 2026 00:23
@fohte-bot fohte-bot bot mentioned this pull request Mar 12, 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