feat: add node-builtin-specifier rule#1306
Conversation
| #[derive(Debug)] | ||
| pub struct NodeBuiltinsSpecifier; | ||
|
|
||
| const CODE: &str = "node-builtin-specifier"; |
There was a problem hiding this comment.
Maybe require-node-prefix or require-node-scheme or something like that?
|
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 |
|
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. |
|
@marvinhagemeister can you move it to the |
|
@marvinhagemeister @bartlomieju Is it OK if I move it myself? |
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. |
|
Thanks! This is a useful rule and there's no overlap with |
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>
96969a0 to
f39cb75
Compare
node: specifier rulenode-builtin-specifier rule
|
@bartlomieju did you see the comments on this PR? |
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:
And these, but questionable to add these or not: "_http_agent" |
|
Yeah I think |
|
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.
Yes, I would like to that in the near future. |
This reverts commit d42bc49.
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 requirednode:prefix(e.g.
"node:fs"). It covers both static imports and dynamicimport()calls and ships an autofix that adds the
node:prefix.The rule is tagged
recommendedand emits diagnostics at warning severityrather than error, so existing code keeps working while nudging users toward
the correct specifier. Warning severity is wired through the
LintDiagnosticSeverity::WarningAPI added in #1487.Invalid:
Valid:
Documentation is added in denoland/docs#3366.
Related denoland/deno#24930