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

Lint: Add a rule for Node built ins not having the node: prefix #24930

Open
marvinhagemeister opened this issue Aug 7, 2024 · 1 comment · May be fixed by #24959
Open

Lint: Add a rule for Node built ins not having the node: prefix #24930

marvinhagemeister opened this issue Aug 7, 2024 · 1 comment · May be fixed by #24959
Labels
feat new feature (which has been agreed to/accepted) lint Issues related to deno lint

Comments

@marvinhagemeister
Copy link
Contributor

We should add a lint rule that warns when you're importing Node built-in modules without the node: specifier.

// This should error
import * as fs from "fs"

// This should not error
import * as fs from "node:fs"

Preferable with an integration into deno lint --fix as well.

@marvinhagemeister marvinhagemeister added feat new feature (which has been agreed to/accepted) lint Issues related to deno lint labels Aug 7, 2024
@ry
Copy link
Member

ry commented Aug 7, 2024

The LSP already errors properly on this but it probably would be better as a lint rule

deno/cli/lsp/diagnostics.rs

Lines 1176 to 1197 in 9d6da10

"import-node-prefix-missing" => {
let data = diagnostic
.data
.clone()
.ok_or_else(|| anyhow!("Diagnostic is missing data"))?;
let data: DiagnosticDataStrSpecifier = serde_json::from_value(data)?;
lsp::CodeAction {
title: format!("Update specifier to node:{}", data.specifier),
kind: Some(lsp::CodeActionKind::QUICKFIX),
diagnostics: Some(vec![diagnostic.clone()]),
edit: Some(lsp::WorkspaceEdit {
changes: Some(HashMap::from([(
specifier.clone(),
vec![lsp::TextEdit {
new_text: format!("\"node:{}\"", data.specifier),
range: diagnostic.range,
}],
)])),
..Default::default()
}),
..Default::default()
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat new feature (which has been agreed to/accepted) lint Issues related to deno lint
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants