Skip to content

Bug: unsupported-features/node-builtins-modules doesn't work for semver range in v17 #250

Closed
@teppeis

Description

@teppeis

Environment

Node version: v20.12.2
npm version: 10.5.0
ESLint version: 8.57.0
eslint-plugin-n version: 17.2.1
Operating System: macOS

What rule do you want to report?

unsupported-features/node-builtins-modules

Link to Minimal Reproducible Example

https://eslint-online-playground.netlify.app/#eNpdkl1PwyAUhv8K4Woma7cmxmnNduW9N8abMROkx6WzBTzAnNn63z2U7pMr+nJ4eDh0zx2qCexkaxvIN46XXBntPJPOAXo2Zwg/oUYYCZ4iwe+ehdbwO5TkCBtQ3o1izMc8B9fU2qMimtHE2wvNmOCw86ArJ3jJlvTVF5UIyrQt5VAJPqYq24R1rUs9uVpZjRPDSqQjX62vyTGSenZPV618B3S0EHPBG+nBkWy/M1Y4E1DB25+FVNCaKjQ0j+vdwEdKLrlpCK4n2mRBu2CtQQ9V9gXSBwRHeQXZZ6gbXyej5XknWSEaPDnEcQPeXiov5k/5NJ8mpTS643TVawrdUYetVN9yHV/rqr+aGndlT95kl9gfxX1ezPIpOxzYYl48nA863r2C7QvY2HCt6htOeq1Eerzoacqz9GjZcI1iNoDJlv6I7h9Tur5F

What did you expect to happen?

This works fine (expectedly fail),

"n/no-unsupported-features/node-builtins": ["error", {version: "9.0.0"}]

but this doesn't work (unexpectedly success) in v17: demo

"n/no-unsupported-features/node-builtins": ["error", {version: ">=9.0.0"}]

v16 works fine: demo

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

Since specifying the version by range is common in the engines field of package.json, this bug is likely to occur in many cases.
However, this is not included in the test cases.

The logic of this range comparison seems to be the cause.

const range = getSemverRange(
[
...supported.map(
version => `>= ${version} < ${major(version) + 1}`
),
`> ${major(latest)}`,
].join("||")
)
if (range == null) {
return false
}
return configured.intersects(range)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions