Skip to content

fix(golang): reject // indirect //exhortignore as ignore marker#538

Merged
a-oren merged 2 commits into
guacsec:mainfrom
a-oren:ignore-format
Jun 23, 2026
Merged

fix(golang): reject // indirect //exhortignore as ignore marker#538
a-oren merged 2 commits into
guacsec:mainfrom
a-oren:ignore-format

Conversation

@a-oren

@a-oren a-oren commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Fix greedy regex in IgnoredLine that incorrectly treated // indirect //exhortignore as an ignored dependency (TC-4345)
  • Parse the first // comment and only accept standalone ignore markers (// exhortignore) or the semicolon-separated format (// indirect; exhortignore), matching the JavaScript client behavior
  • Add test cases for the // indirect //exhortignore format

Test plan

  • Existing test_IgnoredLine_rejects_old_space_separated_indirect_format passes with new assertions
  • CI passes
  • Verify with integration test golang-go_mod_with_ignore[stack] that Java and JS clients produce matching results

🤖 Generated with Claude Code

Summary by Sourcery

Update Go modules ignore-line detection to only treat standalone or semicolon-separated ignore markers as valid, and align behavior with the JavaScript client.

Bug Fixes:

  • Prevent lines with the invalid "// indirect //exhortignore" or "// indirect //trustify-da-ignore" formats from being treated as ignored dependencies.

Tests:

  • Extend IgnoredLine tests to cover double-slash indirect formats and confirm they are not recognized while the semicolon format remains supported.

…345)

The greedy regex in IgnoredLine matched the last // in a line, causing
"// indirect //exhortignore" to be incorrectly treated as ignored.
Parse the first // comment instead and only accept standalone ignore
markers or the semicolon-separated format (// indirect; exhortignore),
matching the JavaScript client behavior.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@sourcery-ai

sourcery-ai Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Refines the Go modules ignore-line detection logic to only treat well-formed comment markers as ignore directives and adds tests to ensure malformed double-slash formats like "// indirect //exhortignore" are not incorrectly recognized.

File-Level Changes

Change Details Files
Tighten ignore-marker parsing in GoModulesProvider to inspect only the first comment and support specific allowed formats.
  • Trim each line, locate the first occurrence of "//", and parse only the trailing comment text for ignore markers.
  • Replace broad line-level regexes with comment-scoped patterns that recognize either a standalone ignore marker or an "indirect; ignore" format, optionally with a nested comment marker.
  • Keep existing guards that exclude module-level and non-dependency lines, and still require either a "require" prefix or a package-with-version pattern before treating the line as ignored.
src/main/java/io/github/guacsec/trustifyda/providers/GoModulesProvider.java
Extend tests to cover malformed double-slash ignore formats and confirm only the semicolon-separated format is recognized.
  • Update the ignore-line test to assert that space-separated and double-slash without semicolon comment formats are not treated as valid ignore markers.
  • Verify that the newer semicolon-separated "// indirect; exhortignore" format continues to be recognized as a valid ignore directive.
src/test/java/io/github/guacsec/trustifyda/providers/Golang_Modules_Provider_Test.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Hey - I've left some high level feedback:

  • The new comment.matches(...) checks in IgnoredLine will compile the regex on every call; consider extracting these into precompiled Pattern constants to avoid repeated compilation and make the ignore-format rules easier to read and maintain.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `comment.matches(...)` checks in `IgnoredLine` will compile the regex on every call; consider extracting these into precompiled `Pattern` constants to avoid repeated compilation and make the ignore-format rules easier to read and maintain.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@codecov-commenter

codecov-commenter commented Jun 22, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 12 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@cea1a4b). Learn more about missing BASE report.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main     #538   +/-   ##
=======================================
  Coverage        ?   68.72%           
  Complexity      ?     1000           
=======================================
  Files           ?       65           
  Lines           ?     4253           
  Branches        ?      744           
=======================================
  Hits            ?     2923           
  Misses          ?      990           
  Partials        ?      340           
Flag Coverage Δ
integration-tests 68.72% <50.00%> (?)

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

…tants

Avoids recompiling regexes on every IgnoredLine call.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@a-oren a-oren requested a review from Strum355 June 22, 2026 18:13
@a-oren a-oren merged commit 7d20efe into guacsec:main Jun 23, 2026
45 checks passed
@a-oren a-oren deleted the ignore-format branch June 23, 2026 12:29
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.

3 participants