Skip to content

Commit

Permalink
fix: Use our data set to work out if a module is a node module (#338)
Browse files Browse the repository at this point in the history
* test: Add failing test for #337

* fix: Use our data set to work out if a module is a node module
  • Loading branch information
scagood authored Sep 18, 2024
1 parent e5e758e commit 6a1b2c5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/rules/prefer-node-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,22 @@
*/
"use strict"

const { isBuiltin } = require("node:module")
const getConfiguredNodeVersion = require("../util/get-configured-node-version")
const getSemverRange = require("../util/get-semver-range")
const visitImport = require("../util/visit-import")
const visitRequire = require("../util/visit-require")
const mergeVisitorsInPlace = require("../util/merge-visitors-in-place")
const {
NodeBuiltinModules,
} = require("../unsupported-features/node-builtins.js")

/**
* @param {string} name The name of the node module
* @returns {boolean}
*/
function isBuiltin(name) {
return Object.hasOwn(NodeBuiltinModules, name)
}

const messageId = "preferNodeProtocol"

Expand Down
2 changes: 2 additions & 0 deletions tests/lib/rules/prefer-node-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ new RuleTester({
const fs = await import(\`fs\`);
}
`,
// punycode has no `node:` equivelent
'import "punycode";',
'import "punycode/";',
// https://bun.sh/docs/runtime/bun-apis
'import "bun";',
Expand Down

0 comments on commit 6a1b2c5

Please sign in to comment.