Skip to content

[Fix] no-unresolved: handle template literal requires - #3276

Merged
ljharb merged 1 commit into
import-js:mainfrom
pratyushsinghal7:issue-1575
Aug 21, 2026
Merged

[Fix] no-unresolved: handle template literal requires#3276
ljharb merged 1 commit into
import-js:mainfrom
pratyushsinghal7:issue-1575

Conversation

@pratyushsinghal7

@pratyushsinghal7 pratyushsinghal7 commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

What changed

Treat no-substitution template literals passed to CommonJS require() as static module paths in moduleVisitor.

The template's cooked string value is exposed on a shallow source-node copy, so existing resolution logic and visitor-based rules can consume it without mutating the parser AST. Template literals containing expressions remain dynamic and are ignored.

Regression coverage verifies that:

  • require(`./bar`) resolves successfully.
  • require(`./baz`) reports import/no-unresolved.
  • Both the node and webpack resolver test configurations exercise the cases.

Fixes #1575.

Validation

  • BABEL_ENV=test ./node_modules/.bin/mocha --require babel-register tests/src/rules/no-unresolved.js --reporter dot — 157 passing
  • npm test — full tests, ESLint, generated documentation checks, and Markdown lint passed

@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.60%. Comparing base (ee005b6) to head (950393e).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3276      +/-   ##
==========================================
+ Coverage   79.57%   79.60%   +0.02%     
==========================================
  Files          98       98              
  Lines        4539     4545       +6     
  Branches     1537     1572      +35     
==========================================
+ Hits         3612     3618       +6     
  Misses        927      927              

☔ 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.

@pratyushsinghal7
pratyushsinghal7 marked this pull request as ready for review July 24, 2026 04:45
@pratyushsinghal7

Copy link
Copy Markdown
Contributor Author

CI baseline note: the failing Tests: eslint (old versions) matrix is unchanged from main. The latest main run at https://github.com/import-js/eslint-plugin-import/actions/runs/29535690274 and this PR run each have the same 50 failing jobs (the Node 10–15 / ESLint 2–6 combinations), while all 194 other matrix jobs pass.

The focused rule test also passes locally with npm run mocha -- tests/src/rules/no-unresolved.js. The old-version matrix failures appear to be pre-existing dependency/runtime failures rather than failures introduced by this two-file change.

…plate literal requires

Normalize no-substitution template literal arguments in CommonJS require calls before passing them to module visitors.
Add valid and invalid resolution coverage for node and webpack resolvers.

Co-authored-by: Pratyush Singhal <pratyushsinghal7@gmail.com>
Co-authored-by: Jordan Harband <ljharb@gmail.com>

@ljharb ljharb left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is a good fix, but i hope nobody's actually using no-substitution template literals anywhere

(added additional test coverage)

@ljharb ljharb added the package: utils eslint-module-utils package label Aug 21, 2026
@ljharb
ljharb merged commit 950393e into import-js:main Aug 21, 2026
438 of 439 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

package: utils eslint-module-utils package

Development

Successfully merging this pull request may close these issues.

import/no-unresolved ignores require statements with backticks

2 participants