Skip to content

fix(rules): match flag-only negation patterns against =-joined tokens#175

Merged
fohte merged 1 commit intomainfrom
fohte/fix-negation-equals-form
Mar 9, 2026
Merged

fix(rules): match flag-only negation patterns against =-joined tokens#175
fohte merged 1 commit intomainfrom
fohte/fix-negation-equals-form

Conversation

@fohte
Copy link
Owner

@fohte fohte commented Mar 9, 2026

Why

What

  • Also compare the flag portion (before =) of =-joined command tokens when evaluating flag-only negation patterns

Open with Devin

Flag-only negation patterns like `\!--pre` did not reject `=`-joined
flags such as `--pre=pdftotext` because `--pre=pdftotext` was compared
as a single token against `--pre`. The matcher now also extracts the
flag portion before `=` and checks it against the negation pattern,
so both `--pre value` and `--pre=value` are correctly rejected.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@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 bug in the pattern matching logic, specifically for flag-only negation rules. The change ensures that these negation patterns correctly identify and apply to command-line arguments where flags and their values are joined by an equals sign, thereby preventing unintended allowances. The update improves the robustness and predictability of rule evaluation, aligning the system's behavior with user expectations for flag negation.

Highlights

  • Bug Fix: Resolved an issue where flag-only negation patterns (e.g., !--pre) failed to correctly match against command-line arguments that use an equals sign to join the flag and its value (e.g., --pre=pdftotext). Previously, such arguments were treated as a single raw token, leading to incorrect negation evaluation.
  • Core Logic Update: Introduced a new internal utility function, match_flag_token_with_equals, to specifically handle the matching logic for flag-only negation patterns against =-joined command tokens. This function extracts and compares the flag portion before the equals sign.
  • Documentation Enhancement: Updated the matching-behavior.md documentation to include examples and explanations of how flag-only negation patterns now correctly interact with =-joined flags, ensuring clarity for users.
  • Test Coverage: Expanded both unit and integration test suites with new cases specifically designed to validate the correct behavior of flag-only negation patterns when applied to =-joined command tokens, covering various scenarios including alternative negation patterns.
Changelog
  • docs/src/content/docs/pattern-syntax/matching-behavior.md
    • Added a new section explaining how flag-only negation patterns work with =-joined flags.
    • Included YAML examples and a table demonstrating matching behavior for !--pre with --pre=value.
  • src/rules/pattern_matcher.rs
    • Modified match_tokens_core to use match_flag_token_with_equals for flag-only negation.
    • Modified extract_placeholder_all to use match_flag_token_with_equals for flag-only negation.
    • Introduced match_flag_token_with_equals function to handle matching flag portions of =-joined command tokens.
    • Added new #[case] attributes to the negation_matching test module to cover =-joined tokens.
  • tests/integration/config_to_rule_evaluation.rs
    • Added a new test function flag_negation_equals_form with multiple #[case] scenarios.
    • Included tests for both rejected and allowed cases with =-joined flags and alternative negation 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.

@codecov
Copy link

codecov bot commented Mar 9, 2026

Codecov Report

❌ Patch coverage is 94.44444% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 89.94%. Comparing base (e4e3f50) to head (448af60).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/rules/pattern_matcher.rs 94.44% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##             main     #175   +/-   ##
=======================================
  Coverage   89.93%   89.94%           
=======================================
  Files          38       38           
  Lines        7232     7248   +16     
=======================================
+ Hits         6504     6519   +15     
- Misses        728      729    +1     
Flag Coverage Δ
Linux 89.80% <94.44%> (+<0.01%) ⬆️
macOS 91.66% <94.44%> (+<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.

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

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 correctly fixes an issue where flag-only negation patterns did not match against =-joined tokens. The changes are well-implemented, with a new helper function to handle the matching logic and consistent application in both match_tokens_core and extract_placeholder_all. The documentation has been updated accordingly, and the new behavior is thoroughly tested with both unit and integration tests that adhere to the project's testing style guide.

Note: Security Review is unavailable for this PR.

@fohte fohte merged commit 7cf8eaa into main Mar 9, 2026
10 checks passed
@fohte fohte deleted the fohte/fix-negation-equals-form branch March 9, 2026 16:20
@fohte-bot fohte-bot bot mentioned this pull request Mar 9, 2026
fohte added a commit that referenced this pull request Mar 10, 2026
…into single match_engine

Two nearly-identical recursive matching functions (match_tokens_core for
boolean matching, extract_placeholder_all for placeholder extraction)
duplicated all PatternToken variant handling. Bug fixes applied to one
function were frequently missed in the other (PR #175, #179, #180).

Merge both into a single `match_engine` function parameterized by an
optional `extract` tuple. Each PatternToken variant's logic now exists
in exactly one place.

Also introduce a flag normalization layer (`split_flag_equals`,
`flag_aliases_match_token`) to centralize `--flag=value` splitting,
replacing the ad-hoc `=`-joined handling scattered across
match_flag_token_with_equals, FlagWithValue, and optional_flags_absent.

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