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

fix: Use our data set to work out if a module is a node module #338

Merged
merged 2 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nits: we could move node-builtins.js to outer - it's now not just used by those rules. :)

Copy link
Author

@scagood scagood Sep 18, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you think we should put the directory?

I was also thinking about going through and merging the no-deprecated-api into the unsupported-features so its all in one place as a consistent data set 🤔

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where do you think we should put the directory?

maybe /lib/dataset/?

I was also thinking about going through and merging the no-deprecated-api into the unsupported-features

It would be nice if these rules could share data, so we don't have to worry about updating one and forgetting the other.


/**
* @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