Skip to content

Commit

Permalink
Fix expiring-todo-comments crashing on invalid package version (#494)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and sindresorhus committed Jan 21, 2020
1 parent b1d3f37 commit fd46adc
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 fd46adc

Please sign in to comment.