Repository navigation
fix(project-detect): read all Go require directives #3910
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
haelyra
merged 3 commits into
affaan-m:main
from
Afloat16:ecc/fix-go-require-detection-20261111
Nov 16, 2026
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,89 @@ | ||
| 'use strict'; | ||
|
|
||
| const assert = require('node:assert/strict'); | ||
| const fs = require('node:fs'); | ||
| const os = require('node:os'); | ||
| const path = require('node:path'); | ||
| const { test } = require('node:test'); | ||
| const { detectProjectType, getGoDeps } = require('../../scripts/lib/project-detect'); | ||
|
|
||
| function withGoMod(contents, check) { | ||
| const dir = fs.mkdtempSync(path.join(os.tmpdir(), 'ecc-go-requires-')); | ||
| try { | ||
| fs.writeFileSync(path.join(dir, 'go.mod'), contents); | ||
| check(dir); | ||
| } finally { | ||
| fs.rmSync(dir, { recursive: true, force: true }); | ||
| } | ||
| } | ||
|
|
||
| test('detects a framework declared by a standalone require directive', () => { | ||
| withGoMod('module example.com/app\n\ngo 1.23\nrequire github.com/gin-gonic/gin v1.10.0\n', dir => { | ||
| assert.deepEqual(getGoDeps(dir), ['github.com/gin-gonic/gin']); | ||
| assert.equal(detectProjectType(dir).primary, 'gin'); | ||
| }); | ||
| }); | ||
|
|
||
| test('reads every require block and standalone directive in source order', () => { | ||
| withGoMod([ | ||
| 'module example.com/app', | ||
| 'require (', | ||
| ' example.com/first v1.0.0 // indirect', | ||
| ')', | ||
| 'require github.com/labstack/echo/v4 v4.13.0', | ||
| 'require ( // a second dependency group', | ||
| ' github.com/gin-gonic/gin v1.10.0', | ||
| ')', | ||
| ].join('\n'), dir => { | ||
| assert.deepEqual(getGoDeps(dir), [ | ||
| 'example.com/first', 'github.com/labstack/echo/v4', 'github.com/gin-gonic/gin', | ||
| ]); | ||
| assert.deepEqual(detectProjectType(dir).frameworks, ['gin', 'echo']); | ||
| }); | ||
| }); | ||
|
|
||
| test('ignores commented and replacement-only framework references', () => { | ||
| withGoMod([ | ||
| 'module example.com/app', | ||
| '// require github.com/gin-gonic/gin v1.10.0', | ||
| 'replace github.com/gin-gonic/gin => ../gin', | ||
| 'exclude github.com/labstack/echo/v4 v4.12.0', | ||
| 'require (', | ||
| ' // github.com/gin-gonic/gin v1.10.0', | ||
| ' example.com/actual v1.0.0', | ||
| ')', | ||
| ].join('\n'), dir => { | ||
| assert.deepEqual(getGoDeps(dir), ['example.com/actual']); | ||
| assert.deepEqual(detectProjectType(dir).frameworks, []); | ||
| }); | ||
| }); | ||
|
|
||
| test('accepts quoted module paths and CRLF require directives', () => { | ||
| withGoMod('module example.com/app\r\nrequire "github.com/gin-gonic/gin" v1.10.0\r\n', dir => { | ||
| assert.deepEqual(getGoDeps(dir), ['github.com/gin-gonic/gin']); | ||
| }); | ||
| }); | ||
|
|
||
| test('accepts quoted versions in standalone and grouped requirements', () => { | ||
| withGoMod([ | ||
| 'module example.com/app', | ||
| 'require "github.com/gin-gonic/gin" "v1.10.0"', | ||
| 'require (', | ||
| ' github.com/labstack/echo/v4 "v4.13.0"', | ||
| ')', | ||
| ].join('\n'), dir => { | ||
| assert.deepEqual(getGoDeps(dir), ['github.com/gin-gonic/gin', 'github.com/labstack/echo/v4']); | ||
| }); | ||
| }); | ||
|
|
||
| test('accepts adjacent block punctuation and raw string tokens', () => { | ||
| withGoMod([ | ||
| 'module example.com/app', | ||
| 'require(', | ||
| ' github.com/gin-gonic/gin `v1.10.0`', | ||
| ')', | ||
| 'require `github.com/labstack/echo/v4` "v4.13.0"', | ||
| ].join('\n'), dir => { | ||
| assert.deepEqual(getGoDeps(dir), ['github.com/gin-gonic/gin', 'github.com/labstack/echo/v4']); | ||
| }); | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.