From e91ba691583e6ee7fd2cac08ad36c70a00429930 Mon Sep 17 00:00:00 2001 From: Caleb Eby Date: Mon, 6 Jun 2022 09:18:14 -0700 Subject: [PATCH 1/4] Enforce using the node: protocol for imports to node built-in modules --- src/config.js | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/config.js b/src/config.js index 77f00613..0db865c9 100644 --- a/src/config.js +++ b/src/config.js @@ -172,11 +172,6 @@ module.exports.configs = { // There isn't a good reason to force use of Number.POSITIVE_INFINITY instead of Infinity { checkInfinity: false }, ], - // The node: protocol for imports is supported for imports starting in node 12 - // and for require()'s starting in node 16. - // Since for most projects, we are transpiling imports to requires, - // This rule is not ready until we only support node 16+ - 'unicorn/prefer-node-protocol': 'off', // This rule suggests incorrect code with the destructured object is modified // That is a fairly common case, and it is too annoying to always disable the rule on each line 'unicorn/consistent-destructuring': 'off', From a644101ec651e51f05fdf3a194a95d71ea95ad77 Mon Sep 17 00:00:00 2001 From: Caleb Eby Date: Mon, 6 Jun 2022 09:27:22 -0700 Subject: [PATCH 2/4] Add changeset --- .changeset/long-olives-give.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 .changeset/long-olives-give.md diff --git a/.changeset/long-olives-give.md b/.changeset/long-olives-give.md new file mode 100644 index 00000000..e2b85920 --- /dev/null +++ b/.changeset/long-olives-give.md @@ -0,0 +1,13 @@ +--- +'@cloudfour/eslint-plugin': major +--- + +Enforce using the `node`: protocol for imports to node built-in modules ([`prefer-node-protocol`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/rules/prefer-node-protocol.js)). + +❌ `require('fs')` -> ✅ `require('node:fs')` +❌ `import * as fs from 'fs'` -> ✅ `import * as fs from 'node:fs'` + +The `import` form is supported in node v14.13.1+. +The `require` form is supported in node v14.18.0+. + +It is auto-fixable. From 508789b1c375dfa5447f0e0059128d3ae0c19e20 Mon Sep 17 00:00:00 2001 From: Caleb Eby Date: Mon, 6 Jun 2022 09:29:21 -0700 Subject: [PATCH 3/4] use arrow symbol in changeset --- .changeset/long-olives-give.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.changeset/long-olives-give.md b/.changeset/long-olives-give.md index e2b85920..3787e437 100644 --- a/.changeset/long-olives-give.md +++ b/.changeset/long-olives-give.md @@ -4,8 +4,8 @@ Enforce using the `node`: protocol for imports to node built-in modules ([`prefer-node-protocol`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/rules/prefer-node-protocol.js)). -❌ `require('fs')` -> ✅ `require('node:fs')` -❌ `import * as fs from 'fs'` -> ✅ `import * as fs from 'node:fs'` +❌ `require('fs')` → ✅ `require('node:fs')` +❌ `import * as fs from 'fs'` → ✅ `import * as fs from 'node:fs'` The `import` form is supported in node v14.13.1+. The `require` form is supported in node v14.18.0+. From 2b3d0cf716d287fc6e8333cd78763c670ac82ef9 Mon Sep 17 00:00:00 2001 From: Caleb Eby Date: Mon, 6 Jun 2022 09:34:51 -0700 Subject: [PATCH 4/4] lint --- generate-changeset.mjs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/generate-changeset.mjs b/generate-changeset.mjs index 5cd4ded3..9f9a464a 100644 --- a/generate-changeset.mjs +++ b/generate-changeset.mjs @@ -1,8 +1,8 @@ // @ts-check -import { spawn } from 'child_process'; -import { promises as fs } from 'fs'; -import { join } from 'path'; +import { spawn } from 'node:child_process'; +import { promises as fs } from 'node:fs'; +import { join } from 'node:path'; import kleur from 'kleur'; import _writeChangeset from '@changesets/write'; import prompts from 'prompts';