Skip to content

feat: support go 1.24 ignore directives#35

Open
miguelvr wants to merge 1 commit into
baz-scm:mainfrom
miguelvr:miguelvr/support-ignore
Open

feat: support go 1.24 ignore directives#35
miguelvr wants to merge 1 commit into
baz-scm:mainfrom
miguelvr:miguelvr/support-ignore

Conversation

@miguelvr
Copy link
Copy Markdown

@miguelvr miguelvr commented May 22, 2026

User description

This pull request adds support for parsing the new ignore directive in Go module files added in Go 1.24


Generated description

Below is a concise technical summary of the changes proposed in this PR:
Add ignore directive handling to the Go module parser by wiring the new field into GoMod::from_str and returning parsed ignore paths from the directive dispatch. Update parser logic and supporting sample data to read single/multi-line ignore blocks and verify that GoMod reports the expected ignored paths.

TopicDetails
Ignore parsing Add parser handling for ignore directives so that the module parser captures single and parenthesized ignore blocks, records them on the GoMod struct, and accepts directives at the end of files.
Modified files (3)
  • src/lib.rs
  • src/parser.rs
  • tests/data/ignore.mod
Latest Contributors(0)
UserCommitDate
Ignore tests Expand tests to cover ignore directives, including parser unit tests and data file scenarios to ensure the new field is populated as expected.
Modified files (2)
  • src/lib.rs
  • tests/parse.rs
Latest Contributors(0)
UserCommitDate
Review this PR on Baz | Customize your next review

Comment thread src/parser.rs
Comment on lines +326 to +330
fn ignore_multi(input: &mut &str) -> Result<Vec<String>> {
let _ = ("(", multispace1).parse_next(input)?;
let res: Vec<Vec<String>> =
repeat(1.., terminated(ignore_single, multispace0)).parse_next(input)?;
let _ = (")", multispace0).parse_next(input)?;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

ignore_multi duplicates the ( ... ) block parsing shared by require_multi, replace_multi, etc. — should we extract a helper? Also, ignore_single calls take_till before opt(comment), so whole-line // comments inside ignore (...) get parsed as bogus path entries; should we detect and consume comment lines first, like the Go module parser does?

Finding types: Code Dedup and Conventions Logical Bugs | Severity: 🟠 Medium


Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents
In src/parser.rs around lines 326-333, fix `ignore_multi()`/`ignore_single()` so
whole-line `// ...` comments inside `ignore (...)` blocks are consumed instead of being
parsed as path entries. In `ignore_single` (lines 314-324), detect and consume a comment
at the start of the line (after optional whitespace) and return an empty result, rather
than calling `take_till(..., WHITESPACES)` before `opt(comment)`. Ensure
`ignore_multi`'s `repeat(…, terminated(ignore_single, multispace0))` still skips
newlines/spaces after comment lines. Additionally, consider extracting the shared `(`
... `)` repetition and `<single>` parser pattern into a helper reused by
`require_multi`, `replace_multi`, `retract_multi`, `godebug_multi`, and `ignore_multi`.

Comment thread src/lib.rs
Comment on lines 53 to 57
pub exclude: Vec<ModuleDependency>,
pub replace: Vec<ModuleReplacement>,
pub retract: Vec<ModuleRetract>,
pub ignore: Vec<String>,
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Adding public ignore: Vec<String> to GoMod makes GoMod { ... } construction non-exhaustive, so downstream crates will fail to compile unless they set it too — should we treat this as a breaking change or hide direct construction with a builder/#[non_exhaustive] + accessors?

Finding type: Breaking Changes | Severity: 🟠 Medium


Want Baz to fix this for you? Activate Fixer

Other fix methods

Fix in Cursor

Prompt for AI Agents
Before applying, verify this suggestion against the current code. In src/lib.rs around
lines 45-57, the GoMod struct adds a new public field `pub ignore: Vec<String>`, which
breaks downstream crates using `GoMod { ... }` exhaustive struct literals because they
now must include `ignore`. Refactor the API to restore source compatibility by either
marking GoMod with `#[non_exhaustive]` and making `ignore` non-public (or replacing it
with a private field plus a public accessor like `ignore()`), and/or introducing a
dedicated constructor/builder so external code doesn’t need to construct the struct
via a struct literal. Keep FromStr behavior the same (still parsing Ignore directives)
but update any internal/tests to use the new accessor where needed.

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