1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-01 16:51:13 -05:00
denoland-deno/tests/specs/lint/node_globals_no_duplicate_imports
Nathan Whitaker 5ec3c5c3a4
feat(lint): Add lint for usage of node globals (with autofix) (#25048)
From upgrading `deno_lint`.

Previously if you had a node project that used a bunch of node globals
(`process.env`, etc), you would have to fix the errors by hand. This PR
includes a new lint that detects usages of node globals (`process`,
`setImmediate`, `Buffer`, etc.) and provides an autofix to import the
correct value. For instance:

```ts
// main.ts
const _foo = process.env.FOO;
```

`deno lint` gives you

```ts
error[no-node-globals]: NodeJS globals are not available in Deno
 --> /home/foo.ts:1:14
  |
1 | const _foo = process.env.FOO;
  |              ^^^^^^^
  = hint: Add `import process from "node:process";`

  docs: https://lint.deno.land/rules/no-node-globals


Found 1 problem (1 fixable via --fix)
Checked 1 file
```
And `deno lint --fix` adds the import for you:

```ts
// main.ts
import process from "node:process";
const _foo = process.env.FOO;
```
2024-08-15 20:43:04 +00:00
..
__test__.jsonc feat(lint): Add lint for usage of node globals (with autofix) (#25048) 2024-08-15 20:43:04 +00:00
error.out feat(lint): Add lint for usage of node globals (with autofix) (#25048) 2024-08-15 20:43:04 +00:00
lint.out feat(lint): Add lint for usage of node globals (with autofix) (#25048) 2024-08-15 20:43:04 +00:00
main.ts feat(lint): Add lint for usage of node globals (with autofix) (#25048) 2024-08-15 20:43:04 +00:00