From fd46adc01dc192b78fc3a3395d5552a693283cf4 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Tue, 21 Jan 2020 15:06:20 +0800 Subject: [PATCH] Fix `expiring-todo-comments` crashing on invalid package version (#494) --- rules/expiring-todo-comments.js | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/rules/expiring-todo-comments.js b/rules/expiring-todo-comments.js index 40c5f3e1ce..ca2ad5b0f9 100644 --- a/rules/expiring-todo-comments.js +++ b/rules/expiring-todo-comments.js @@ -159,7 +159,11 @@ function reachedDate(past) { } function tryToCoerceVersion(rawVersion) { - let version = rawVersion; + if (!rawVersion) { + return false; + } + + let version = String(rawVersion); // Remove leading things like `^1.0.0`, `>1.0.0` const leadingNoises = [ @@ -312,10 +316,10 @@ const create = context => { const [{condition, version}] = packageVersions; const packageVersion = tryToCoerceVersion(packageJson.version); - const desidedPackageVersion = tryToCoerceVersion(version); + const decidedPackageVersion = tryToCoerceVersion(version); const compare = semverComparisonForOperator(condition); - if (compare(packageVersion, desidedPackageVersion)) { + if (packageVersion && compare(packageVersion, decidedPackageVersion)) { context.report({ node: null, loc: comment.loc,