Skip to content

Commit bb21bd0

Browse files
authored
fix: false negatives for https in prefer-node-protocol, and false negatives for node:sqlite in node-builtins (#432)
1 parent 002ac9c commit bb21bd0

File tree

5 files changed

+169
-5
lines changed

5 files changed

+169
-5
lines changed

lib/unsupported-features/node-builtins-modules/https.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const { READ } = require("@eslint-community/eslint-utils")
55
/**
66
* @satisfies {import('../types.js').SupportVersionTraceMap}
77
*/
8-
const http = {
8+
const https = {
99
globalAgent: { [READ]: { supported: ["0.5.9"] } },
1010
createServer: { [READ]: { supported: ["0.3.4"] } },
1111
get: { [READ]: { supported: ["0.3.6"] } },
@@ -18,12 +18,12 @@ const http = {
1818
* @satisfies {import('../types.js').SupportVersionTraceMap}
1919
*/
2020
module.exports = {
21-
http: {
21+
https: {
2222
[READ]: { supported: ["0.3.4"] },
23-
...http,
23+
...https,
2424
},
25-
"node:http": {
25+
"node:https": {
2626
[READ]: { supported: ["14.13.1", "12.20.0"] },
27-
...http,
27+
...https,
2828
},
2929
}

lib/unsupported-features/node-builtins.js

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const NodeBuiltinModules = {
3737
...require("./node-builtins-modules/sea.js"),
3838
...require("./node-builtins-modules/stream.js"),
3939
...require("./node-builtins-modules/string_decoder.js"),
40+
...require("./node-builtins-modules/sqlite.js"),
4041
...require("./node-builtins-modules/test.js"),
4142
...require("./node-builtins-modules/timers.js"),
4243
...require("./node-builtins-modules/tls.js"),

tests/lib/rules/no-unsupported-features/node-builtins.js

+125
Original file line numberDiff line numberDiff line change
@@ -5626,5 +5626,130 @@ new RuleTester({ languageOptions: { sourceType: "module" } }).run(
56265626
},
56275627
],
56285628
},
5629+
5630+
//----------------------------------------------------------------------
5631+
// sqlite
5632+
//----------------------------------------------------------------------
5633+
{
5634+
valid: [
5635+
{
5636+
code: `
5637+
import { DatabaseSync } from 'node:sqlite';
5638+
const database = new DatabaseSync(':memory:');
5639+
`,
5640+
options: [
5641+
{
5642+
version: ">=22.5.0",
5643+
allowExperimental: true,
5644+
},
5645+
],
5646+
languageOptions: { ecmaVersion: "latest" },
5647+
},
5648+
{
5649+
code: `
5650+
import { DatabaseSync } from 'node:sqlite';
5651+
const database = new DatabaseSync(':memory:');
5652+
`,
5653+
options: [
5654+
{
5655+
version: ">=22.3.0",
5656+
ignores: ["sqlite", "sqlite.DatabaseSync"],
5657+
},
5658+
],
5659+
languageOptions: { ecmaVersion: "latest" },
5660+
},
5661+
{
5662+
code: `
5663+
const { DatabaseSync } = require('node:sqlite');
5664+
const database = new DatabaseSync(':memory:');
5665+
`,
5666+
options: [
5667+
{
5668+
version: ">=22.5.0",
5669+
allowExperimental: true,
5670+
},
5671+
],
5672+
languageOptions: { ecmaVersion: "latest" },
5673+
},
5674+
],
5675+
invalid: [
5676+
{
5677+
code: `
5678+
import { DatabaseSync } from 'node:sqlite';
5679+
const database = new DatabaseSync(':memory:');
5680+
`,
5681+
options: [
5682+
{
5683+
version: ">=22.5.0",
5684+
},
5685+
],
5686+
languageOptions: { ecmaVersion: "latest" },
5687+
5688+
errors: [
5689+
{
5690+
messageId: "not-supported-yet",
5691+
data: {
5692+
name: "sqlite",
5693+
version: ">=22.5.0",
5694+
},
5695+
},
5696+
],
5697+
},
5698+
{
5699+
code: `
5700+
import { DatabaseSync } from 'node:sqlite';
5701+
const database = new DatabaseSync(':memory:');
5702+
`,
5703+
options: [{ version: ">=22.3.0", allowExperimental: true }],
5704+
languageOptions: { ecmaVersion: "latest" },
5705+
5706+
errors: [
5707+
{
5708+
messageId: "not-experimental-till",
5709+
data: {
5710+
name: "sqlite",
5711+
experimental: "22.5.0",
5712+
version: ">=22.3.0",
5713+
},
5714+
},
5715+
{
5716+
messageId: "not-supported-till",
5717+
data: {
5718+
name: "sqlite.DatabaseSync",
5719+
supported: "22.5.0",
5720+
version: ">=22.3.0",
5721+
},
5722+
},
5723+
],
5724+
},
5725+
{
5726+
code: `
5727+
const { DatabaseSync } = require('node:sqlite');
5728+
const database = new DatabaseSync(':memory:');
5729+
`,
5730+
options: [{ version: ">=22.3.0", allowExperimental: true }],
5731+
languageOptions: { ecmaVersion: "latest" },
5732+
5733+
errors: [
5734+
{
5735+
messageId: "not-supported-till",
5736+
data: {
5737+
name: "sqlite.DatabaseSync",
5738+
supported: "22.5.0",
5739+
version: ">=22.3.0",
5740+
},
5741+
},
5742+
{
5743+
messageId: "not-experimental-till",
5744+
data: {
5745+
name: "sqlite",
5746+
experimental: "22.5.0",
5747+
version: ">=22.3.0",
5748+
},
5749+
},
5750+
],
5751+
},
5752+
],
5753+
},
56295754
])
56305755
)

tests/lib/rules/prefer-node-protocol.js

+7
Original file line numberDiff line numberDiff line change
@@ -242,5 +242,12 @@ new RuleTester({
242242
`,
243243
errors: ["Prefer `node:buffer` over `buffer`."],
244244
},
245+
246+
// https://github.com/eslint-community/eslint-plugin-n/issues/431
247+
{
248+
code: 'import https from "https";',
249+
output: 'import https from "node:https";',
250+
errors: ["Prefer `node:https` over `https`."],
251+
},
245252
],
246253
})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use strict"
2+
const fs = require("fs")
3+
const path = require("path")
4+
5+
const {
6+
NodeBuiltinModules,
7+
} = require("../../../lib/unsupported-features/node-builtins")
8+
const assert = require("assert")
9+
10+
const RESOURCES_ROOT = path.resolve(
11+
__dirname,
12+
"../../../lib/unsupported-features/node-builtins-modules"
13+
)
14+
15+
describe("unsupported-features/node-builtins", () => {
16+
for (const dirent of fs.readdirSync(RESOURCES_ROOT, {
17+
withFileTypes: true,
18+
})) {
19+
if (!dirent.isFile() || !dirent.name.endsWith(".js")) continue
20+
const filePath = path.join(RESOURCES_ROOT, dirent.name)
21+
const resource = require(filePath)
22+
it(`should be the same resource defined in ${dirent.name} that is defined in NodeBuiltinModules.`, () => {
23+
const picked = Object.fromEntries(
24+
Object.entries(NodeBuiltinModules).filter(
25+
([key]) => resource[key]
26+
)
27+
)
28+
assert.deepStrictEqual(picked, resource)
29+
})
30+
}
31+
})

0 commit comments

Comments
 (0)