feat(lint): add node-builtin-specifier rule - #35628
Open
bartlomieju wants to merge 1 commit into
Open
Conversation
Warns when a Node.js built-in module is imported with a bare specifier (e.g. "fs") instead of the required "node:" prefix (e.g. "node:fs"), covering both static imports and dynamic import() calls, with an autofix that adds the prefix. The rule was previously implemented in deno_lint but maintained its own hardcoded copy of the built-in module list. It now lives here as an extended CLI lint rule that reuses the canonical list from ext/node via node_resolver's DenoIsBuiltInNodeModuleChecker, so there is a single source of truth for which modules are Node built-ins.
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.
Adds a
node-builtin-specifierlint rule that warns when a Node.jsbuilt-in module is imported with a bare specifier (e.g.
"fs") insteadof the required
"node:"prefix (e.g."node:fs"). It covers bothstatic imports and dynamic
import()calls and provides an autofix thatadds the
"node:"prefix.The rule previously lived in deno_lint, where it carried its own
hardcoded copy of the Node built-in module list that had to be kept in
sync by hand. It is being removed there
(denoland/deno_lint#1532) and reintroduced here as an
extended CLI lint rule so it can reuse the canonical list that already
lives in
ext/node(vianode_resolver'sDenoIsBuiltInNodeModuleChecker). That gives a single source of truthfor which modules count as Node built-ins.
The rule is tagged
recommended. Note that, unlike the originaldeno_lint implementation which emitted at warning severity, this version
emits at the default (error) severity because the pinned deno_lint
release does not yet expose the per-diagnostic severity API. Once
deno_lint ships that API and we bump the dependency, this can be
switched back to a warning.