Skip to content

Commit

Permalink
chore: format files
Browse files Browse the repository at this point in the history
  • Loading branch information
lirantal committed Sep 25, 2023
1 parent 9b30fc1 commit bf3cdbc
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 72 deletions.
12 changes: 6 additions & 6 deletions __tests__/__fixtures__/test.marshall.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,24 @@ const BaseMarshall = require('../../lib/marshalls/baseMarshall')
const MARSHALL_NAME = 'test.marshall'

class TestMarshall extends BaseMarshall {
constructor (options) {
constructor(options) {
super(options)
this.name = MARSHALL_NAME
}

title () {
title() {
return 'A test marshall'
}

run (ctx, task) {
run(ctx, task) {
const tasks = ctx.pkgs.reduce((prevPkg, currPkg) => {
return prevPkg.concat(this.mockCheck(currPkg, ctx, task))
}, [])

return Promise.all(tasks)
}

mockCheck (pkg, ctx, task) {
mockCheck(pkg, ctx, task) {
return this.validateSomething(pkg)
.then(() => {
const data = 'mock data check'
Expand All @@ -39,15 +39,15 @@ class TestMarshall extends BaseMarshall {
})
}

validateSomething (pkg) {
validateSomething(pkg) {
if (pkg === 'express' || pkg === 'semver') {
return Promise.resolve()
} else {
return Promise.reject(new Error('simulating mock error'))
}
}

validate (pkg) {
validate(pkg) {
if (pkg === 'express' || pkg === 'semver') {
return Promise.resolve('validation-result')
} else {
Expand Down
2 changes: 1 addition & 1 deletion __tests__/marshalls.tasks.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const path = require('path')
const marshalls = require('../lib/marshalls')

const PackageRepoUtilsMock = class Fake {
getPackageInfo () {
getPackageInfo() {
return Promise.resolve(true)
}
}
Expand Down
4 changes: 2 additions & 2 deletions lib/cliCommons.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const npa = require('npm-package-arg')
class cliCommons {
static getInstallCommand () {
static getInstallCommand() {
return {
command: 'install [package...]',
aliases: [
Expand Down Expand Up @@ -31,7 +31,7 @@ class cliCommons {
}
}

static getOptions () {
static getOptions() {
return {
P: {
alias: ['save-prod', 'peer'],
Expand Down
16 changes: 8 additions & 8 deletions lib/helpers/packageRepoUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ const NPM_REGISTRY = 'http://registry.npmjs.org'
const NPM_REGISTRY_API = 'https://api.npmjs.org'

class PackageRepoUtils {
constructor (options = {}) {
constructor(options = {}) {
this.registryUrl = options.registryUrl ? options.registryUrl : NPM_REGISTRY
this.registryApiUrl = options.registryApiUrl ? options.registryApiUrl : NPM_REGISTRY_API
this.pkgInfoCache = {}
}

formatPackageForUrl (pkg) {
formatPackageForUrl(pkg) {
return pkg.replace(/\//g, '%2F')
}

getPackageInfo (pkg) {
getPackageInfo(pkg) {
if (this.pkgInfoCache[pkg]) {

Check warning on line 20 in lib/helpers/packageRepoUtils.js

View workflow job for this annotation

GitHub Actions / Node 16 (ubuntu-latest)

Generic Object Injection Sink

Check warning on line 20 in lib/helpers/packageRepoUtils.js

View workflow job for this annotation

GitHub Actions / Node 18 (ubuntu-latest)

Generic Object Injection Sink

Check warning on line 20 in lib/helpers/packageRepoUtils.js

View workflow job for this annotation

GitHub Actions / Node 14 (ubuntu-latest)

Generic Object Injection Sink

Check warning on line 20 in lib/helpers/packageRepoUtils.js

View workflow job for this annotation

GitHub Actions / Node 12 (ubuntu-latest)

Generic Object Injection Sink
return Promise.resolve(this.pkgInfoCache[pkg])

Check warning on line 21 in lib/helpers/packageRepoUtils.js

View workflow job for this annotation

GitHub Actions / Node 16 (ubuntu-latest)

Function Call Object Injection Sink

Check warning on line 21 in lib/helpers/packageRepoUtils.js

View workflow job for this annotation

GitHub Actions / Node 18 (ubuntu-latest)

Function Call Object Injection Sink

Check warning on line 21 in lib/helpers/packageRepoUtils.js

View workflow job for this annotation

GitHub Actions / Node 14 (ubuntu-latest)

Function Call Object Injection Sink

Check warning on line 21 in lib/helpers/packageRepoUtils.js

View workflow job for this annotation

GitHub Actions / Node 12 (ubuntu-latest)

Function Call Object Injection Sink
} else {
Expand All @@ -29,27 +29,27 @@ class PackageRepoUtils {
}
}

getLatestVersion (pkg) {
getLatestVersion(pkg) {
return this.getPackageInfo(pkg).then((data) => {
return data['dist-tags'] && data['dist-tags']['latest'] ? data['dist-tags']['latest'] : null
})
}

getDownloadInfo (pkg) {
getDownloadInfo(pkg) {
return fetch(`${this.registryApiUrl}/downloads/point/last-month/${pkg}`)
.then((response) => response.json())
.then(({ downloads }) => downloads)
}

getReadmeInfo (pkg) {
getReadmeInfo(pkg) {
return this.getPackageInfo(pkg).then(({ readme }) => readme)
}

getLicenseInfo (pkg) {
getLicenseInfo(pkg) {
return this.getPackageInfo(pkg).then(({ license }) => license)
}

parsePackageVersion (version) {
parsePackageVersion(version) {
return semver.coerce(version)
}
}
Expand Down
14 changes: 7 additions & 7 deletions lib/marshall.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ const MESSAGE_TYPE = {
}

class Marshall {
constructor (options = {}) {
constructor(options = {}) {
this.pkgs = options ? options.pkgs : null
this.packageRepoUtils = new PackageRepoUtils()
}

process () {
process() {
// nothing to do? move on
if (!this.pkgs) {
return Promise.resolve()
Expand All @@ -37,7 +37,7 @@ class Marshall {
})
}

createPackageVersionMaps (packages) {
createPackageVersionMaps(packages) {
const packageVersionMapping = packages.reduce((prev, curr) => {
const versionSymbolPosition = curr.lastIndexOf('@')
const versionPosition =
Expand All @@ -57,7 +57,7 @@ class Marshall {
return packageVersionMapping
}

report (marshalls) {
report(marshalls) {
const messages = this.collectPackageMessages(marshalls)

if (!messages) {
Expand All @@ -81,7 +81,7 @@ class Marshall {
return { error: true, data: messages }
}

collectPackageMessages (marshalls) {
collectPackageMessages(marshalls) {
const allPackageMessages = {}
for (const key in marshalls) {
this.prepareMessages(allPackageMessages, marshalls[key].errors)
Expand All @@ -91,7 +91,7 @@ class Marshall {
return allPackageMessages
}

prepareMessages (allPackageMessages, messages, isWarning) {
prepareMessages(allPackageMessages, messages, isWarning) {
if (Array.isArray(messages) && messages.length > 0) {
messages.forEach((msg) => {
this.appendPackageMessage(allPackageMessages, msg.pkg, {
Expand All @@ -102,7 +102,7 @@ class Marshall {
}
}

appendPackageMessage (packages, packageName, packageMessage) {
appendPackageMessage(packages, packageName, packageMessage) {
packages[packageName]
? packages[packageName].push(packageMessage)
: (packages[packageName] = [packageMessage])
Expand Down
6 changes: 3 additions & 3 deletions lib/marshalls/age.marshall.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const MARSHALL_NAME = 'age'
const PACKAGE_AGE_THRESHOLD = 22 // specified in days

class Marshall extends BaseMarshall {
constructor (options) {
constructor(options) {
super(options)
this.name = MARSHALL_NAME
}

title () {
title() {
return 'Checking package maturity'
}

validate (pkg) {
validate(pkg) {
return this.packageRepoUtils.getPackageInfo(pkg.packageName).then((data) => {
if (data && data.time && data.time.created) {
const pkgCreatedDate = data.time.created
Expand Down
6 changes: 3 additions & 3 deletions lib/marshalls/author.marshall.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ const Warning = require('../helpers/warning')
const MARSHALL_NAME = 'author'

class Marshall extends BaseMarshall {
constructor (options) {
constructor(options) {
super(options)
this.name = MARSHALL_NAME
}

title () {
title() {
return 'Identifying package author...'
}

validate (pkg) {
validate(pkg) {
return this.packageRepoUtils.getPackageInfo(pkg.packageName).then((data) => {
const lastVersionData =
data.versions && data['dist-tags'] && data.versions[data['dist-tags']['latest']]
Expand Down
16 changes: 8 additions & 8 deletions lib/marshalls/baseMarshall.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
const Warning = require('../helpers/warning')

class BaseMarshall {
constructor (options) {
constructor(options) {
this.packageRepoUtils = options.packageRepoUtils
}

init (ctx, task) {
init(ctx, task) {
this.ctx = ctx
this.task = task

Expand All @@ -19,15 +19,15 @@ class BaseMarshall {
}
}

run (ctx, task) {
run(ctx, task) {
const tasks = ctx.pkgs.reduce((prevPkg, currPkg) => {
return prevPkg.concat(this.checkPackage(currPkg, ctx, task))
}, [])

return Promise.all(tasks)
}

checkPackage (pkg, ctx, task) {
checkPackage(pkg, ctx, task) {
return this.validate(pkg)
.then((data) => {
task.output = `querying ${pkg.packageString}...`
Expand All @@ -36,7 +36,7 @@ class BaseMarshall {
// not explicitly required, but a task can return its results
return data
})
.catch(err => {
.catch((err) => {
this.setMessage(
{
pkg: pkg.packageString,
Expand All @@ -47,13 +47,13 @@ class BaseMarshall {
})
}

isEnabled () {
isEnabled() {
const isMarshallSilent = process.env[`MARSHALL_DISABLE_${this.name.toUpperCase()}`] || false

return !isMarshallSilent
}

setMessage (msg, isWarning) {
setMessage(msg, isWarning) {
const messages = isWarning
? this.ctx.marshalls[this.name].warnings
: this.ctx.marshalls[this.name].errors
Expand All @@ -64,7 +64,7 @@ class BaseMarshall {
})
}

handleMessages () {
handleMessages() {
const errors = this.ctx.marshalls[this.name].errors
const warnings = this.ctx.marshalls[this.name].warnings
if ((errors && errors.length) || (warnings && warnings.length)) {
Expand Down
6 changes: 3 additions & 3 deletions lib/marshalls/downloads.marshall.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const MARSHALL_NAME = 'downloads'
const DOWNLOAD_COUNT_THRESHOLD = 20 // threshold per month

class Marshall extends BaseMarshall {
constructor (options) {
constructor(options) {
super(options)
this.name = MARSHALL_NAME
}

title () {
title() {
return 'Checking package download popularity'
}

validate (pkg) {
validate(pkg) {
return this.packageRepoUtils.getDownloadInfo(pkg.packageName).then((downloadCount) => {
if (downloadCount < DOWNLOAD_COUNT_THRESHOLD) {
throw new Error(
Expand Down
6 changes: 3 additions & 3 deletions lib/marshalls/expiredDomains.marshall.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ const dns = require('dns').promises
const MARSHALL_NAME = 'maintainers_expired_emails'

class Marshall extends BaseMarshall {
constructor (options) {
constructor(options) {
super(options)
this.name = MARSHALL_NAME
}

title () {
title() {
return 'Detecting expired domains for authors account...'
}

validate (pkg) {
validate(pkg) {
return this.packageRepoUtils
.getPackageInfo(pkg.packageName)
.then((data) => {
Expand Down
10 changes: 5 additions & 5 deletions lib/marshalls/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const Listr = require('listr')
const glob = require('glob')

class Marshalls {
static collectMarshalls () {
static collectMarshalls() {
return new Promise((resolve, reject) => {
glob(
this.GLOB_MARSHALLS,
Expand All @@ -23,7 +23,7 @@ class Marshalls {
})
}

static buildMarshallTasks (marshalls, config) {
static buildMarshallTasks(marshalls, config) {
if (!marshalls || !Array.isArray(marshalls) || marshalls.length === 0) {
return Promise.reject(new Error('unable to collect marshalls, or no marshalls found'))
}
Expand All @@ -46,7 +46,7 @@ class Marshalls {
return new Listr(marshallTasks, { exitOnError: false, concurrent: true })
}

static tasks (options) {
static tasks(options) {
return Marshalls.warmUpPackagesCache(options)
.then(() => Marshalls.collectMarshalls())
.then((marshalls) => {
Expand All @@ -59,7 +59,7 @@ class Marshalls {
})
}

static warmUpPackagesCache (options) {
static warmUpPackagesCache(options) {
const fetchPackagesInfoPromises = []
options.pkgs.forEach((packageMeta) => {
fetchPackagesInfoPromises.push(
Expand All @@ -70,7 +70,7 @@ class Marshalls {
return Promise.all(fetchPackagesInfoPromises)
}

static runTasks (tasks, options) {
static runTasks(tasks, options) {
return tasks.run({
pkgs: options.pkgs,
marshalls: {}
Expand Down
6 changes: 3 additions & 3 deletions lib/marshalls/license.marshall.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,16 @@ const BaseMarshall = require('./baseMarshall')
const MARSHALL_NAME = 'license'

class Marshall extends BaseMarshall {
constructor (options) {
constructor(options) {
super(options)
this.name = MARSHALL_NAME
}

title () {
title() {
return 'Checking availability of a LICENSE'
}

validate (pkg) {
validate(pkg) {
return this.packageRepoUtils.getLicenseInfo(pkg.packageName).then((licenseContents) => {
if (!licenseContents || licenseContents === 'ERROR: No LICENSE data found!') {
throw new Error('package has no LICENSE file available')
Expand Down
Loading

0 comments on commit bf3cdbc

Please sign in to comment.