Skip to content

fix: false negatives for https in prefer-node-protocol, and false negatives for node:sqlite in node-builtins #432

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

Merged
merged 3 commits into from
May 8, 2025
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
10 changes: 5 additions & 5 deletions lib/unsupported-features/node-builtins-modules/https.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const { READ } = require("@eslint-community/eslint-utils")
/**
* @satisfies {import('../types.js').SupportVersionTraceMap}
*/
const http = {
const https = {
globalAgent: { [READ]: { supported: ["0.5.9"] } },
createServer: { [READ]: { supported: ["0.3.4"] } },
get: { [READ]: { supported: ["0.3.6"] } },
Expand All @@ -18,12 +18,12 @@ const http = {
* @satisfies {import('../types.js').SupportVersionTraceMap}
*/
module.exports = {
http: {
https: {
[READ]: { supported: ["0.3.4"] },
...http,
...https,
},
"node:http": {
"node:https": {
[READ]: { supported: ["14.13.1", "12.20.0"] },
...http,
...https,
},
}
1 change: 1 addition & 0 deletions lib/unsupported-features/node-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const NodeBuiltinModules = {
...require("./node-builtins-modules/sea.js"),
...require("./node-builtins-modules/stream.js"),
...require("./node-builtins-modules/string_decoder.js"),
...require("./node-builtins-modules/sqlite.js"),
...require("./node-builtins-modules/test.js"),
...require("./node-builtins-modules/timers.js"),
...require("./node-builtins-modules/tls.js"),
Expand Down
125 changes: 125 additions & 0 deletions tests/lib/rules/no-unsupported-features/node-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -5626,5 +5626,130 @@ new RuleTester({ languageOptions: { sourceType: "module" } }).run(
},
],
},

//----------------------------------------------------------------------
// sqlite
//----------------------------------------------------------------------
{
valid: [
{
code: `
import { DatabaseSync } from 'node:sqlite';
const database = new DatabaseSync(':memory:');
`,
options: [
{
version: ">=22.5.0",
allowExperimental: true,
},
],
languageOptions: { ecmaVersion: "latest" },
},
{
code: `
import { DatabaseSync } from 'node:sqlite';
const database = new DatabaseSync(':memory:');
`,
options: [
{
version: ">=22.3.0",
ignores: ["sqlite", "sqlite.DatabaseSync"],
},
],
languageOptions: { ecmaVersion: "latest" },
},
{
code: `
const { DatabaseSync } = require('node:sqlite');
const database = new DatabaseSync(':memory:');
`,
options: [
{
version: ">=22.5.0",
allowExperimental: true,
},
],
languageOptions: { ecmaVersion: "latest" },
},
],
invalid: [
{
code: `
import { DatabaseSync } from 'node:sqlite';
const database = new DatabaseSync(':memory:');
`,
options: [
{
version: ">=22.5.0",
},
],
languageOptions: { ecmaVersion: "latest" },

errors: [
{
messageId: "not-supported-yet",
data: {
name: "sqlite",
version: ">=22.5.0",
},
},
],
},
{
code: `
import { DatabaseSync } from 'node:sqlite';
const database = new DatabaseSync(':memory:');
`,
options: [{ version: ">=22.3.0", allowExperimental: true }],
languageOptions: { ecmaVersion: "latest" },

errors: [
{
messageId: "not-experimental-till",
data: {
name: "sqlite",
experimental: "22.5.0",
version: ">=22.3.0",
},
},
{
messageId: "not-supported-till",
data: {
name: "sqlite.DatabaseSync",
supported: "22.5.0",
version: ">=22.3.0",
},
},
],
},
{
code: `
const { DatabaseSync } = require('node:sqlite');
const database = new DatabaseSync(':memory:');
`,
options: [{ version: ">=22.3.0", allowExperimental: true }],
languageOptions: { ecmaVersion: "latest" },

errors: [
{
messageId: "not-supported-till",
data: {
name: "sqlite.DatabaseSync",
supported: "22.5.0",
version: ">=22.3.0",
},
},
{
messageId: "not-experimental-till",
data: {
name: "sqlite",
experimental: "22.5.0",
version: ">=22.3.0",
},
},
],
},
],
},
])
)
7 changes: 7 additions & 0 deletions tests/lib/rules/prefer-node-protocol.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,5 +242,12 @@ new RuleTester({
`,
errors: ["Prefer `node:buffer` over `buffer`."],
},

// https://github.com/eslint-community/eslint-plugin-n/issues/431
{
code: 'import https from "https";',
output: 'import https from "node:https";',
errors: ["Prefer `node:https` over `https`."],
},
],
})
31 changes: 31 additions & 0 deletions tests/lib/unsupported-features/node-builtins.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
"use strict"
const fs = require("fs")
const path = require("path")

const {
NodeBuiltinModules,
} = require("../../../lib/unsupported-features/node-builtins")
const assert = require("assert")

const RESOURCES_ROOT = path.resolve(
__dirname,
"../../../lib/unsupported-features/node-builtins-modules"
)

describe("unsupported-features/node-builtins", () => {
for (const dirent of fs.readdirSync(RESOURCES_ROOT, {
withFileTypes: true,
})) {
if (!dirent.isFile() || !dirent.name.endsWith(".js")) continue
const filePath = path.join(RESOURCES_ROOT, dirent.name)
const resource = require(filePath)
it(`should be the same resource defined in ${dirent.name} that is defined in NodeBuiltinModules.`, () => {
const picked = Object.fromEntries(
Object.entries(NodeBuiltinModules).filter(
([key]) => resource[key]
)
)
assert.deepStrictEqual(picked, resource)
})
}
})