From fd860260ad0fd72d638c4cc69ff45c25dbaafaa6 Mon Sep 17 00:00:00 2001 From: Divy Srivastava Date: Thu, 19 Sep 2024 00:20:42 +0530 Subject: [PATCH] feat(lint): add `no-process-global` lint rule (#25709) Closes https://github.com/denoland/deno/issues/25679 --- Cargo.lock | 4 ++-- cli/Cargo.toml | 2 +- .../node_globals_no_duplicate_imports/__test__.jsonc | 3 ++- .../lint/node_globals_no_duplicate_imports/lint.out | 12 ++++++------ .../lint/node_globals_no_duplicate_imports/main.out | 4 ++++ .../lint/node_globals_no_duplicate_imports/main.ts | 4 ++-- 6 files changed, 17 insertions(+), 12 deletions(-) create mode 100644 tests/specs/lint/node_globals_no_duplicate_imports/main.out diff --git a/Cargo.lock b/Cargo.lock index 9dbd78e97d..d548b2a583 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1701,9 +1701,9 @@ dependencies = [ [[package]] name = "deno_lint" -version = "0.66.0" +version = "0.67.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f5d2c81b9e0308b43fc76c4ddf72663f590f7ded43e6cb80dfe7b85ab88ea00" +checksum = "871b60e32bfb6c110cbb9b0688dbf048f81e5d347fe4ce5a42239263de9dd938" dependencies = [ "anyhow", "deno_ast", diff --git a/cli/Cargo.toml b/cli/Cargo.toml index b59667f825..209c40dc7f 100644 --- a/cli/Cargo.toml +++ b/cli/Cargo.toml @@ -69,7 +69,7 @@ deno_config = { version = "=0.34.3", features = ["workspace", "sync"] } deno_core = { workspace = true, features = ["include_js_files_for_snapshotting"] } deno_doc = { version = "0.148.0", features = ["html", "syntect"] } deno_graph = { version = "=0.82.1" } -deno_lint = { version = "=0.66.0", features = ["docs"] } +deno_lint = { version = "=0.67.0", features = ["docs"] } deno_lockfile.workspace = true deno_npm = "=0.25.1" deno_package_json.workspace = true diff --git a/tests/specs/lint/node_globals_no_duplicate_imports/__test__.jsonc b/tests/specs/lint/node_globals_no_duplicate_imports/__test__.jsonc index a632e896ef..3feb6eaba9 100644 --- a/tests/specs/lint/node_globals_no_duplicate_imports/__test__.jsonc +++ b/tests/specs/lint/node_globals_no_duplicate_imports/__test__.jsonc @@ -3,7 +3,8 @@ "steps": [ { "args": "run main.ts", - "output": "" + "output": "main.out", + "exitCode": 1 }, { "args": "lint main.ts", diff --git a/tests/specs/lint/node_globals_no_duplicate_imports/lint.out b/tests/specs/lint/node_globals_no_duplicate_imports/lint.out index b396e71ebd..d9ff7f77e2 100644 --- a/tests/specs/lint/node_globals_no_duplicate_imports/lint.out +++ b/tests/specs/lint/node_globals_no_duplicate_imports/lint.out @@ -1,9 +1,9 @@ error[no-node-globals]: NodeJS globals are not available in Deno --> [WILDCARD]main.ts:3:14 | -3 | const _foo = process.env.FOO; - | ^^^^^^^ - = hint: Add `import process from "node:process";` +3 | const _foo = setImmediate; + | ^^^^^^^^^^^^ + = hint: Add `import { setImmediate } from "node:timers";` docs: https://lint.deno.land/rules/no-node-globals @@ -11,9 +11,9 @@ error[no-node-globals]: NodeJS globals are not available in Deno error[no-node-globals]: NodeJS globals are not available in Deno --> [WILDCARD]main.ts:7:14 | -7 | const _bar = process.env.BAR; - | ^^^^^^^ - = hint: Add `import process from "node:process";` +7 | const _bar = setImmediate; + | ^^^^^^^^^^^^ + = hint: Add `import { setImmediate } from "node:timers";` docs: https://lint.deno.land/rules/no-node-globals diff --git a/tests/specs/lint/node_globals_no_duplicate_imports/main.out b/tests/specs/lint/node_globals_no_duplicate_imports/main.out new file mode 100644 index 0000000000..56df10eba4 --- /dev/null +++ b/tests/specs/lint/node_globals_no_duplicate_imports/main.out @@ -0,0 +1,4 @@ +error: Uncaught (in promise) ReferenceError: setImmediate is not defined +const _foo = setImmediate; + ^ + at [WILDCARD]main.ts:3:14 diff --git a/tests/specs/lint/node_globals_no_duplicate_imports/main.ts b/tests/specs/lint/node_globals_no_duplicate_imports/main.ts index bff428d012..73ccb255e1 100644 --- a/tests/specs/lint/node_globals_no_duplicate_imports/main.ts +++ b/tests/specs/lint/node_globals_no_duplicate_imports/main.ts @@ -1,7 +1,7 @@ import {} from "node:console"; -const _foo = process.env.FOO; +const _foo = setImmediate; import {} from "node:assert"; -const _bar = process.env.BAR; +const _bar = setImmediate;