Skip to content

feat(lint): add node-builtin-specifier rule - #35628

Open
bartlomieju wants to merge 1 commit into
mainfrom
node-builtin-specifier-lint-rule
Open

feat(lint): add node-builtin-specifier rule#35628
bartlomieju wants to merge 1 commit into
mainfrom
node-builtin-specifier-lint-rule

Conversation

@bartlomieju

Copy link
Copy Markdown
Member

Adds a node-builtin-specifier lint rule that 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"). It covers both
static imports and dynamic import() calls and provides an autofix that
adds 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 (via node_resolver's
DenoIsBuiltInNodeModuleChecker). That gives a single source of truth
for which modules count as Node built-ins.

The rule is tagged recommended. Note that, unlike the original
deno_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.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant