Skip to content

Commit 234703c

Browse files
ZauberNerdmysticatea
authored andcommitted
Fix: ensure "version" always has a valid value in parseOptions (#109)
The rule no-unsupported-features would sometimes fail with a TypeError: ``` Error while loading rule 'node/no-unsupported-features': Cannot read property 'split' of null TypeError: Error while loading rule 'node/no-unsupported-features': Cannot read property 'split' of null at new Range (.../node_modules/semver/semver.js:780:20) at Function.intersects (.../node_modules/semver/semver.js:1305:8) at Object.freeze.features.Object.freeze.OPTIONS.reduce (.../node_modules/eslint-plugin-node/lib/rules/no-unsupported-features.js:191:44) at Array.reduce (<anonymous>) at parseOptions (.../node_modules/eslint-plugin-node/lib/rules/no-unsupported-features.js:175:41) at Object.create (.../node_modules/eslint-plugin-node/lib/rules/no-unsupported-features.js:281:25) ``` This happens, when neither "engines" are set in the "package.json", nor "version" is set in the rule configuration but the rule still has configuration options, because version will then be set to `options.version`, even if that is `undefined`. This commit ensures that `version` always has a valid value before trying to construct a semver range from it.
1 parent bbf4b60 commit 234703c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/rules/no-unsupported-features.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ function getDefaultVersion(filename) {
104104
const info = getPackageJson(filename)
105105
const nodeVersion = info && info.engines && info.engines.node
106106

107-
return nodeVersion ? semver.validRange(nodeVersion) : null
107+
return semver.validRange(nodeVersion) || DEFAULT_VERSION
108108
}
109109

110110
/**
@@ -147,7 +147,7 @@ function isIgnored(key, ignores) {
147147
* @returns {object} Parsed value.
148148
*/
149149
function parseOptions(options, defaultVersion) {
150-
let version = defaultVersion ? null : DEFAULT_VERSION
150+
let version = null
151151
let range = null
152152
let ignores = []
153153

0 commit comments

Comments
 (0)