Skip to content

[Fix] no-relative-packages: do not resolve non-relative imports - #3298

Open
guru-irl wants to merge 2 commits into
import-js:mainfrom
guru-irl:no-relative-packages-skip-bare-specifiers
Open

guru-irl wants to merge 2 commits into
import-js:mainfrom
guru-irl:no-relative-packages-skip-bare-specifiers

Conversation

@guru-irl

Copy link
Copy Markdown

Problem

no-relative-packages calls importType() for every import, re-export and require it visits. importType() resolves the specifier before it classifies it, so every bare specifier (some-package, @scope/package/subpath) goes through the configured resolver: node_modules lookups, package.json reads and entry-point probes.

The rule only reports parent, index and sibling imports, and those types come from the specifier text alone. Resolving a non-relative specifier can never change the result.

The extra resolution costs time in large projects, and it touches files the rule does not need, such as the entry points of other packages in a monorepo. That matters for tools that sandbox or track file accesses.

Change

  • Return early when the specifier is not relative. The check reuses isRelativeToParent, isIndex and isRelativeToSibling, now exported from src/core/importType.js.
  • Relative specifiers keep the existing path, including import/internal-regex taking precedence.

Tests

  • Non-relative imports, re-exports and require calls with a resolver that throws: each one produced a "Resolve error" before this change; now none is resolved.
  • Relative specifiers, including Windows separators, still reach the resolver. Index specifiers and the internal-regex precedence keep their results.
  • Rule tests: 38 passing; 15 of the new cases fail without the change. importType tests: 36 passing.
  • Full suite: 3,151 passing, 6 pending (existing platform and version guards), 0 failing. Lint passes.

Return before import classification for specifiers that cannot be
parent, index, or sibling imports. Reuse the existing lexical checks
and retain classification for relative imports so internal-regex
settings keep their precedence.

Add resolver-backed regression coverage to ensure non-relative imports
are not resolved and relative imports retain their existing behavior.
@codecov

codecov Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 40.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 79.63%. Comparing base (a60d715) to head (d8e3d07).

Files with missing lines Patch % Lines
src/core/importType.js 0.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3298      +/-   ##
==========================================
+ Coverage   79.59%   79.63%   +0.03%     
==========================================
  Files          98       98              
  Lines        4549     4551       +2     
  Branches     1543     1576      +33     
==========================================
+ Hits         3621     3624       +3     
+ Misses        928      927       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant