Skip to content

feat: add node-builtin-specifier rule#1306

Merged
bartlomieju merged 1 commit into
mainfrom
node_specifier_rule
Jun 29, 2026
Merged

feat: add node-builtin-specifier rule#1306
bartlomieju merged 1 commit into
mainfrom
node_specifier_rule

Conversation

@marvinhagemeister

@marvinhagemeister marvinhagemeister commented Aug 8, 2024

Copy link
Copy Markdown
Contributor

Adds a new 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 ships an autofix that adds the node: prefix.

The rule is tagged recommended and emits diagnostics at warning severity
rather than error, so existing code keeps working while nudging users toward
the correct specifier. Warning severity is wired through the
LintDiagnosticSeverity::Warning API added in #1487.

Invalid:

import * as path from "path";
import * as fs from "fs";
import * as fsPromises from "fs/promises";
await import("os");

Valid:

import * as path from "node:path";
import * as fs from "node:fs";
import * as fsPromises from "node:fs/promises";
await import("node:os");

Documentation is added in denoland/docs#3366.

Related denoland/deno#24930

@dsherret dsherret left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This looks good. I think though that we should add it to cli/tools/lint/rules in the deno repo instead so that we can keep the node built-in modules in sync with the cli?

#[derive(Debug)]
pub struct NodeBuiltinsSpecifier;

const CODE: &str = "node-builtin-specifier";

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Maybe require-node-prefix or require-node-scheme or something like that?

@marvinhagemeister

Copy link
Copy Markdown
Contributor Author

Err... sure, didn't know that it was possible to add lint rules directly to the deno codebase. I'll try porting it.

+1 I like the require-node-prefix naming suggestion

@dsherret

dsherret commented Aug 8, 2024

Copy link
Copy Markdown
Contributor

Another option is making this rule accept a list of built-in node modules that we can provide in the CLI, then we can construct this rule in the CLI's list of rules.

@bartlomieju

Copy link
Copy Markdown
Member

@marvinhagemeister can you move it to the deno repo? Let's land it, it's super useful.

@yacinehmito

Copy link
Copy Markdown

@marvinhagemeister @bartlomieju Is it OK if I move it myself?

@iuioiua

iuioiua commented Nov 21, 2025

Copy link
Copy Markdown
Contributor

This looks good. I think though that we should add it to cli/tools/lint/rules in the deno repo instead so that we can keep the node built-in modules in sync with the cli?

Is there anything else to gain from having it in the main repo? I find it funny that lint rules would be split over 2 repos instead of 1.

@bartlomieju

Copy link
Copy Markdown
Member

Thanks! This is a useful rule and there's no overlap with no-import-prefix (which targets inline npm:/jsr:/https: deps). We'd like to take it, defaulting to warning severity rather than error. Could you rebase on latest main and wire it in at warning severity? Once CI is green we can review for merge.

Adds a new 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 is tagged `recommended` and emits diagnostics at warning severity
rather than error, so existing code keeps working while nudging users toward
the correct specifier.

Co-authored-by: Bartek Iwańczuk <bartek@deno.com>
@bartlomieju
bartlomieju force-pushed the node_specifier_rule branch from 96969a0 to f39cb75 Compare June 29, 2026 08:45
@bartlomieju bartlomieju changed the title feat: add node: specifier rule feat: add node-builtin-specifier rule Jun 29, 2026
@bartlomieju
bartlomieju merged commit d42bc49 into main Jun 29, 2026
5 checks passed
@dsherret

Copy link
Copy Markdown
Contributor

@bartlomieju did you see the comments on this PR?

@dsherret

dsherret commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Is there anything else to gain from having it in the main repo? I find it funny that lint rules would be split over 2 repos instead of 1.

Yes, the main thing to gain would be that the node built-in modules can be forced to be kept in sync. It would actually be nice to move this entire repo over there.

For example, this PR is already out of date and is missing the following built-in node modules:

  • sqlite
  • test
  • test/reporters

And these, but questionable to add these or not:

"_http_agent"
"_http_common"
"_http_outgoing"
"_http_server"
"_stream_duplex",
"_stream_passthrough",
"_stream_readable",
"_stream_transform",
"_stream_writable",
"_tls_common",
"_tls_wrap",

@bartlomieju

bartlomieju commented Jun 29, 2026

Copy link
Copy Markdown
Member

Yeah I think node-builtin-specifier name is fine.

@bartlomieju

Copy link
Copy Markdown
Member

Ah I missed the comment about list of modules. That's a good point. I think I will go with the same approach as in #1517. That way it can use the list defined in one of the crates.

It would actually be nice to move this entire repo over there.

Yes, I would like to that in the near future.

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.

5 participants