Skip to content

Commit

Permalink
Fix expiring-todo-comments crashing on invalid package version
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker committed Jan 3, 2020
1 parent cea1346 commit 2eea9bb
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions rules/expiring-todo-comments.js
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 2eea9bb

Please sign in to comment.