Skip to content

Enhancement: keep Go 1.24 tool directive modules as development dependencies in vg scan #567

Closed

Description

@vibgrate-team

Context

Go 1.24 added the tool directive to go.mod (go get -tool golang.org/x/tools/cmd/stringer). The tool's module is added to require, usually marked // indirect because no package in the main module imports it:

go 1.24

tool golang.org/x/tools/cmd/stringer

require golang.org/x/tools v0.30.0 // indirect

parseGoMod in src/core-open/scanners/go-scanner.ts doesn't read tool lines, and scanOneGoProject drops every // indirect require before building rows (allDeps.filter(d => !d.indirect)). So build tools pinned this way disappear from vg scan entirely, even though they're real, version-pinned development dependencies that drift like anything else.

What to do

  • Parse tool directives in both forms (tool path and tool ( … )) and collect the tool package paths.
  • Map each tool package to the required module that provides it (the longest require module path that is a prefix of the tool path).
  • Keep those modules in the scan even when they're // indirect, and record them in the devDependencies section rather than dependencies.
  • Add tool to the looksLikeGoModule keyword list so a bare tool token is never treated as a module.
  • Add unit tests for the single-line and block forms, a tool whose module is also a direct import (it should stay in dependencies), and a tool path nested under its module path.

Acceptance

  • The example go.mod above produces a golang.org/x/tools row under development dependencies in vg scan.
  • Indirect requires that aren't providing a tool are still filtered out as today.
  • A module that is both imported directly and used as a tool stays a production dependency.

Activity

  1. added
    enhancement
    on Nov 3, 2026
  2. vibgrate-team commented on Nov 3, 2026

    @vibgrate-team
    ContributorAuthor

    Good catch, Go 1.24 tool pins are easy to miss. Some pointers from the current code:

    • parseGoMod in src/core-open/scanners/go-scanner.ts only looks at require lines; a tool … line or a tool ( … ) block body goes straight to continue. Collect tool paths with the same single-line vs block handling used for require (including the one-line tool ( … ) edge case the require parser already handles).
    • The drop happens at const directDeps = allDeps.filter(d => !d.indirect); in scanOneGoProject. After mapping each tool path to its providing module (longest require path that equals the tool path or is a prefix followed by /), keep those modules even when indirect, and carry a flag so the row is pushed with section: 'devDependencies' instead of the hardcoded 'dependencies'.
    • Watch the prefix match: golang.org/x/tool must not match golang.org/x/tools/cmd/stringer, so compare on a / boundary.
    • Precedence: a module that's a non-indirect require stays in dependencies even if it also provides a tool.
    • Add 'tool' to the keyword list in looksLikeGoModule alongside toolchain.
    • Framework detection (KNOWN_GO_FRAMEWORKS) should keep working for these rows; it's harmless either way, but don't skip it by accident.

    Tests can call an exported parseGoMod directly, or go through scanGoProjects with a stubbed GoCache so nothing hits the network.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions