Skip to content

Commit

Permalink
feat: Add a better error for unsupported builtins
Browse files Browse the repository at this point in the history
  • Loading branch information
scagood committed Feb 22, 2024
1 parent 8bd0964 commit a0159d5
Show file tree
Hide file tree
Showing 3 changed files with 331 additions and 321 deletions.
31 changes: 26 additions & 5 deletions lib/util/check-unsupported-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,11 @@ function isSupported({ supported }, configured) {
/**
* Get the formatted text of a given supported version.
* @param {SupportInfo} info The support info.
* @returns {null|string}
*/
function supportedVersionToString({ supported }) {
if (supported == null || supported.length === 0) {
return "(none yet)"
return null
}

const [latest, ...backported] = rsort(supported)
Expand Down Expand Up @@ -96,10 +97,23 @@ module.exports.checkUnsupportedBuiltins = function checkUnsupportedBuiltins(
const name = unprefixNodeColon(path.join("."))
const supported = isSupported(info, options.version)

if (!supported && !options.ignores.has(name)) {
if (supported === true || options.ignores.has(name)) {
continue
}
const supportedVersion = supportedVersionToString(info)
if (supportedVersion == null) {
context.report({
node,
messageId: "not-supported-yet",
data: {
name: path.join("."),
version: options.version.raw,
},
})
} else {
context.report({
node,
messageId: "unsupported",
messageId: "not-supported-till",
data: {
name: path.join("."),
supported: supportedVersionToString(info),
Expand All @@ -111,6 +125,13 @@ module.exports.checkUnsupportedBuiltins = function checkUnsupportedBuiltins(
}

exports.messages = {
unsupported:
"The '{{name}}' is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.",
"not-supported-till": [
"The '{{name}}' is still an experimental feature",
"and is not supported until Node.js {{supported}}.",
"The configured version range is '{{version}}'.",
].join(" "),
"not-supported-yet": [
"The '{{name}}' is still an experimental feature",
"The configured version range is '{{version}}'.",
].join(" "),
}
Loading

0 comments on commit a0159d5

Please sign in to comment.