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(prefer-node-protocol): continue on version range check #206

Merged
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
2 changes: 1 addition & 1 deletion lib/rules/prefer-node-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ module.exports = {
"Program:exit"() {
for (const { node, moduleStyle } of targets) {
if (!isEnablingThisRule(context, moduleStyle)) {
return
continue
}

if (node.type === "TemplateLiteral") {
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/prefer-node-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,5 +228,17 @@ new RuleTester({
output: 'const fs = require("node:fs");',
errors: ["Prefer `node:fs` over `fs`."],
},
{
options: [{ version: "12.20.0" }],
code: `
const fs = require("fs");
import buffer from 'buffer'
`,
output: `
const fs = require("fs");
import buffer from 'node:buffer'
Copy link
Author

@coderaiser coderaiser Mar 20, 2024

Choose a reason for hiding this comment

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

node: protocol in CJS isn't supported in v12.20, but it is already supported in ESM, so only ESM fixed. Rare case but still possible with help of createRequire()

`,
errors: ["Prefer `node:buffer` over `buffer`."],
},
],
})