Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add node: specifier rule #1306

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open

Conversation

marvinhagemeister
Copy link
Contributor

@marvinhagemeister marvinhagemeister commented Aug 8, 2024

This PR adds a rule that warns when the node: specifier is missing when trying to import a built-in node module.

Invalid:

import * as path from "path";
import * as fs from "fs";
import * as fsPromises from "fs/promises";

Valid:

import * as path from "node:path";
import * as fs from "node:fs";
import * as fsPromises from "node:fs/promises";

Related denoland/deno#24930

Copy link
Member

@dsherret dsherret left a comment

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
Member

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
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
Copy link
Member

dsherret commented Aug 8, 2024

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.

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.

2 participants