[Fix] no-unresolved: handle template literal requires - #3276
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
|
CI baseline note: the failing The focused rule test also passes locally with |
…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>
What changed
Treat no-substitution template literals passed to CommonJS
require()as static module paths inmoduleVisitor.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`)reportsimport/no-unresolved.Fixes #1575.
Validation
BABEL_ENV=test ./node_modules/.bin/mocha --require babel-register tests/src/rules/no-unresolved.js --reporter dot— 157 passingnpm test— full tests, ESLint, generated documentation checks, and Markdown lint passed