Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
isaacs committed Feb 13, 2021
1 parent 2bce12a commit 5b71911
Show file tree
Hide file tree
Showing 10 changed files with 6,520 additions and 3,683 deletions.
21 changes: 9 additions & 12 deletions lib/advisory.js
Expand Up @@ -66,12 +66,12 @@ class Advisory {
// load up the data from a cache entry and a fetched packument
load (cached, packument) {
// basic data integrity gutcheck
if (!cached || typeof cached !== 'object') {
if (!cached || typeof cached !== 'object')
throw new TypeError('invalid cached data, expected object')
}
if (!packument || typeof packument !== 'object') {

if (!packument || typeof packument !== 'object')
throw new TypeError('invalid packument data, expected object')
}

if (cached.id && cached.id !== this.id) {
throw Object.assign(new Error('loading from incorrect cache entry'), {
expected: this.id,
Expand Down Expand Up @@ -103,9 +103,8 @@ class Advisory {
if (!this.versions.includes(v)) {
versionsAdded.push(v)
this.versions.push(v)
} else if (!pakuVersions.includes(v)) {
} else if (!pakuVersions.includes(v))
versionsRemoved.push(v)
}
}

// strip out any removed versions from our lists, and sort by semver
Expand Down Expand Up @@ -249,9 +248,8 @@ class Advisory {
// try to pick a version of the dep that isn't vulnerable
const avoid = this[_source].range

if (bundled) {
if (bundled)
return semver.intersects(spec, avoid, semverOpt)
}

return this[_source].testSpec(spec)
}
Expand All @@ -261,9 +259,8 @@ class Advisory {
// consistent across multiple versions, so memoize this as well, in case
// we're testing lots of versions.
const memo = this[_specVulnMemo]
if (memo.has(spec)) {
if (memo.has(spec))
return memo.get(spec)
}

const res = this[_testSpec](spec)
memo.set(spec, res)
Expand Down Expand Up @@ -379,14 +376,14 @@ class Advisory {
// marking as vulnerable if the midpoint item we picked is.
if (!/-/.test(String(pre[0]))) {
const midVuln = this.testVersion(pre[pre.length - 1])
while (/-/.test(String(pre[pre.length-1]))) {
while (/-/.test(String(pre[pre.length - 1]))) {
const v = pre.pop()
if (midVuln)
this[_markVulnerable](v)
}
}

if (!/-/.test(String(post[post.length-1]))) {
if (!/-/.test(String(post[post.length - 1]))) {
const midVuln = this.testVersion(post[0])
while (/-/.test(String(post[0]))) {
const v = post.shift()
Expand Down
16 changes: 9 additions & 7 deletions lib/get-dep-spec.js
Expand Up @@ -2,12 +2,14 @@ module.exports = (mani, name) => {
// skip dev because that only matters at the root,
// where we aren't fetching a manifest from the registry
// with multiple versions anyway.
return mani.dependencies && typeof mani.dependencies[name] === 'string'
? mani.dependencies[name]
: mani.optionalDependencies && typeof mani.optionalDependencies[name] === 'string'
? mani.optionalDependencies[name]
: mani.peerDependencies && typeof mani.peerDependencies[name] === 'string'
? mani.peerDependencies[name]
const {
dependencies: deps = {},
optionalDependencies: optDeps = {},
peerDependencies: peerDeps = {},
} = mani

return typeof deps[name] === 'string' ? deps[name]
: typeof optDeps[name] === 'string' ? optDeps[name]
: typeof peerDeps[name] === 'string' ? peerDeps[name]
: null
}

2 changes: 1 addition & 1 deletion lib/index.js
Expand Up @@ -53,7 +53,7 @@ class Calculator {
// load packument and cached advisory
const [cached, packument] = await Promise.all([
this[_cacheGet](advisory),
this[_packument](name)
this[_packument](name),
])
process.emit('time', `metavuln:load:${k}`)
advisory.load(cached, packument)
Expand Down

0 comments on commit 5b71911

Please sign in to comment.