fix(import-detect): drop commented-out and relative imports - #85
Open
eeshsaxena wants to merge 1 commit into
Open
fix(import-detect): drop commented-out and relative imports#85eeshsaxena wants to merge 1 commit into
eeshsaxena wants to merge 1 commit into
Conversation
Three false positives in the added-line import scanner:
- Go import blocks matched quoted paths on every line, including
`//`-commented ones, so a commented-out `// "github.com/foo/bar"` inside
a block was attributed as a real dependency. The single-line form already
rejects comments via isRealStatement; the block body now skips
isCommentLine lines too.
- JS relative/absolute specifiers ("./util", "../lib/x", "/abs") were
normalized to a bare "." or ".." and leaked into the candidate list.
- Python relative from-imports ("from . import x", "from .m import Y")
produced an empty "" candidate.
Both now skip local specifiers, the same intent Ruby's require_relative and
Rust's crate/self/super exclusions already encode. Adds regression tests for
all three.
Contributor
Author
|
Hi! Gentle nudge on this one whenever you have some bandwidth. It's a small, self-contained fix ( |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Three false positives in
extractImportedPackages(the added-line import scanner feeding skill detection). Each makes it attribute a dependency the code doesn't actually import, which the module's "bounded false positives" contract is meant to prevent.1. Commented-out imports inside a Go
import (...)blockThe single-line Go form already drops
// import "..."viaisRealStatement, but the block form scans every quoted path in the block body, comments included:Before:
["fmt", "github.com/spf13/cobra", "github.com/gin-gonic/gin"]— the commented-outcobrais credited.After:
["fmt", "github.com/gin-gonic/gin"].The block body now skips
isCommentLinelines, matching the single-line path.2. JS relative/absolute specifiers leak
./..normalizeJs("./util")returns"."(and"../lib/x"returns".."), so every relative import adds a bogus token:Before:
[".", "..", "react"]· After:["react"]3. Python relative from-imports leak
""from . import x/from .models import Ysplit to an empty first segment, pushed unguarded (the siblingimportbranch already guards withif (name)):Before:
["", "", "django"]· After:["django"]#2 and #3 are the same "a relative module is not a package" case that Ruby's
require_relativeand Rust'scrate/self/superare already excluded for; JS and Python just weren't.Tests
Adds three regression tests to
test/import-detect.test.ts(one per case). They fail onmainand pass with this change; the fullimport-detectsuite stays green (90 passed).