Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/npm/cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorEdu93Jer <mailing_93@hotmail.com>2020-12-16 02:49:38 +0300
committerisaacs <i@izs.me>2020-12-18 22:35:16 +0300
commita92d310b7e9e4c48b08f52785c2e3a6d52a82ad7 (patch)
tree60a615230082a8cdac3d357ae7c59cbd94b0211d /lib
parentbe4a0900b14b2c6315bf62bed8f5affb648215ae (diff)
Add max-len to lint rules
PR-URL: https://github.com/npm/cli/pull/2361 Credit: @Edu93Jer Close: #2361 Reviewed-by: @isaacs EDIT(@isaacs): amended to match some of the fixes to our current style conventions
Diffstat (limited to 'lib')
-rw-r--r--lib/deprecate.js3
-rw-r--r--lib/doctor.js10
-rw-r--r--lib/init.js3
-rw-r--r--lib/npm.js3
-rw-r--r--lib/outdated.js24
-rw-r--r--lib/profile.js3
-rw-r--r--lib/repo.js3
-rw-r--r--lib/token.js19
-rw-r--r--lib/unpublish.js4
-rw-r--r--lib/utils/error-message.js12
-rw-r--r--lib/utils/file-exists.js4
-rw-r--r--lib/utils/reify-output.js2
-rw-r--r--lib/view.js13
13 files changed, 75 insertions, 28 deletions
diff --git a/lib/deprecate.js b/lib/deprecate.js
index fbaad54b7..1a46148e8 100644
--- a/lib/deprecate.js
+++ b/lib/deprecate.js
@@ -25,7 +25,8 @@ const completion = (opts, cb) => {
return libaccess.lsPackages(username, npm.flatOptions).then((packages) => {
return Object.keys(packages)
.filter((name) => packages[name] === 'write' &&
- (opts.conf.argv.remain.length === 0 || name.startsWith(opts.conf.argv.remain[0]))
+ (opts.conf.argv.remain.length === 0 ||
+ name.startsWith(opts.conf.argv.remain[0]))
)
})
}).then((list) => cb(null, list), (err) => cb(err))
diff --git a/lib/doctor.js b/lib/doctor.js
index 0b29936bb..f42b19fa6 100644
--- a/lib/doctor.js
+++ b/lib/doctor.js
@@ -59,7 +59,8 @@ const getLatestNodejsVersion = async () => {
if (lts && semver.gt(version, maxLTS))
maxLTS = version
- if (semver.satisfies(version, currentRange) && semver.gt(version, maxCurrent))
+ if (semver.satisfies(version, currentRange) &&
+ semver.gt(version, maxCurrent))
maxCurrent = version
}
const recommended = semver.gt(maxCurrent, maxLTS) ? maxCurrent : maxLTS
@@ -175,7 +176,12 @@ const verifyCachedFiles = async () => {
tracker.info('verifyCachedFiles', 'Verifying the npm cache')
try {
const stats = await cacache.verify(npm.flatOptions.cache)
- const { badContentCount, reclaimedCount, missingContent, reclaimedSize } = stats
+ const {
+ badContentCount,
+ reclaimedCount,
+ missingContent,
+ reclaimedSize,
+ } = stats
if (badContentCount || reclaimedCount || missingContent) {
if (badContentCount)
tracker.warn('verifyCachedFiles', `Corrupted content removed: ${badContentCount}`)
diff --git a/lib/init.js b/lib/init.js
index 6e4213c28..60ea52e16 100644
--- a/lib/init.js
+++ b/lib/init.js
@@ -41,8 +41,9 @@ const init = async args => {
}
}
npm.config.set('package', [])
+ const newArgs = [packageName, ...args.slice(1)]
return new Promise((res, rej) => {
- npm.commands.exec([packageName, ...args.slice(1)], er => er ? rej(er) : res())
+ npm.commands.exec(newArgs, er => er ? rej(er) : res())
})
}
diff --git a/lib/npm.js b/lib/npm.js
index 4430b8053..876432e5b 100644
--- a/lib/npm.js
+++ b/lib/npm.js
@@ -13,7 +13,8 @@ require('graceful-fs').gracefulify(require('fs'))
const procLogListener = require('./utils/proc-log-listener.js')
-const hasOwnProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key)
+const hasOwnProperty = (obj, key) =>
+ Object.prototype.hasOwnProperty.call(obj, key)
// the first time `npm.commands.xyz` is loaded, it gets added
// to the cmds object, so we don't have to load it again.
diff --git a/lib/outdated.js b/lib/outdated.js
index f0ec7a72f..b5f0f3b5b 100644
--- a/lib/outdated.js
+++ b/lib/outdated.js
@@ -167,7 +167,7 @@ async function outdated_ (tree, deps, opts) {
}
} catch (err) {
// silently catch and ignore ETARGET, E403 &
- // E404 errors, deps are just skipped
+ // E404 errors, deps are just skipped {
if (!(
err.code === 'ETARGET' ||
err.code === 'E403' ||
@@ -234,7 +234,16 @@ function makePretty (dep, opts) {
// <fullpath>:<name@wanted>:<name@installed>:<name@latest>:<dependedby>
function makeParseable (list, opts) {
return list.map(dep => {
- const { name, current, wanted, latest, path, dependent, type, homepage } = dep
+ const {
+ name,
+ current,
+ wanted,
+ latest,
+ path,
+ dependent,
+ type,
+ homepage,
+ } = dep
const out = [
path,
name + '@' + wanted,
@@ -252,7 +261,16 @@ function makeParseable (list, opts) {
function makeJSON (list, opts) {
const out = {}
list.forEach(dep => {
- const { name, current, wanted, latest, path, type, dependent, homepage } = dep
+ const {
+ name,
+ current,
+ wanted,
+ latest,
+ path,
+ type,
+ dependent,
+ homepage,
+ } = dep
out[name] = {
current,
wanted,
diff --git a/lib/profile.js b/lib/profile.js
index 50d7ddd7d..a29837c75 100644
--- a/lib/profile.js
+++ b/lib/profile.js
@@ -127,7 +127,8 @@ function get (args) {
})
} else {
const table = new Table()
- Object.keys(cleaned).forEach((k) => table.push({ [ansistyles.bright(k)]: cleaned[k] }))
+ for (const k of Object.keys(cleaned))
+ table.push({ [ansistyles.bright(k)]: cleaned[k] })
output(table.toString())
}
}
diff --git a/lib/repo.js b/lib/repo.js
index 7bd3bd154..2dc3bcb1b 100644
--- a/lib/repo.js
+++ b/lib/repo.js
@@ -36,7 +36,8 @@ const getRepo = async pkg => {
}
const info = hostedFromMani(mani)
- const url = info ? info.browse(mani.repository.directory) : unknownHostedUrl(rurl)
+ const url = info ?
+ info.browse(mani.repository.directory) : unknownHostedUrl(rurl)
if (!url) {
throw Object.assign(new Error('no repository: could not get url'), {
diff --git a/lib/token.js b/lib/token.js
index 8809e4412..98bbd3043 100644
--- a/lib/token.js
+++ b/lib/token.js
@@ -74,16 +74,19 @@ function token (args, cb) {
function generateTokenIds (tokens, minLength) {
const byId = {}
- tokens.forEach((token) => {
+ for (const token of tokens) {
token.id = token.key
for (let ii = minLength; ii < token.key.length; ++ii) {
- if (!tokens.some((ot) => ot !== token && ot.key.slice(0, ii) === token.key.slice(0, ii))) {
+ const match = tokens.some(ot =>
+ ot !== token &&
+ ot.key.slice(0, ii) === token.key.slice(0, ii))
+ if (!match) {
token.id = token.key.slice(0, ii)
break
}
}
byId[token.id] = token
- })
+ }
return byId
}
@@ -136,7 +139,8 @@ function list (args) {
return
}
generateTokenIds(tokens, 6)
- const idWidth = tokens.reduce((acc, token) => Math.max(acc, token.id.length), 0)
+ const idWidth = tokens.reduce((acc, token) =>
+ Math.max(acc, token.id.length), 0)
const table = new Table({
head: ['id', 'token', 'created', 'readonly', 'CIDR whitelist'],
colWidths: [Math.max(idWidth, 2) + 2, 9, 12, 10],
@@ -170,8 +174,8 @@ function rm (args) {
else if (matches.length > 1)
throw new Error(`Token ID "${id}" was ambiguous, a new token may have been created since you last ran \`npm token list\`.`)
else {
- const tokenMatches = tokens.filter((token) => id.indexOf(token.token) === 0)
- if (tokenMatches.length === 0)
+ const tokenMatches = tokens.some(t => id.indexOf(t.token) === 0)
+ if (!tokenMatches)
throw new Error(`Unknown token id or value "${id}".`)
toRemove.push(id)
@@ -212,7 +216,8 @@ function create (args) {
Object.keys(result).forEach((k) => output(k + '\t' + result[k]))
else {
const table = new Table()
- Object.keys(result).forEach((k) => table.push({ [ansistyles.bright(k)]: String(result[k]) }))
+ for (const k of Object.keys(result))
+ table.push({ [ansistyles.bright(k)]: String(result[k]) })
output(table.toString())
}
})
diff --git a/lib/unpublish.js b/lib/unpublish.js
index 1d7601b60..75993af94 100644
--- a/lib/unpublish.js
+++ b/lib/unpublish.js
@@ -93,8 +93,8 @@ async function unpublish (args) {
const { name, version, publishConfig } = manifest
const pkgJsonSpec = npa.resolve(name, version)
-
- res = await otplease(opts, opts => libunpub(pkgJsonSpec, { ...opts, publishConfig }))
+ const optsWithPub = { ...opts, publishConfig }
+ res = await otplease(opts, opts => libunpub(pkgJsonSpec, optsWithPub))
pkgName = name
pkgVersion = version ? `@${version}` : ''
} else {
diff --git a/lib/utils/error-message.js b/lib/utils/error-message.js
index 695b497ab..ac5a935dc 100644
--- a/lib/utils/error-message.js
+++ b/lib/utils/error-message.js
@@ -193,10 +193,14 @@ module.exports = (er) => {
else {
detail.push(['404', 'This package name is not valid, because', ''])
- const errorsArray = (valResult.errors || []).concat(valResult.warnings || [])
- errorsArray.forEach(function (item, idx) {
- detail.push(['404', ' ' + (idx + 1) + '. ' + item])
- })
+ const errorsArray = [
+ ...(valResult.errors || []),
+ ...(valResult.warnings || []),
+ ]
+ errorsArray.forEach((item, idx) => detail.push([
+ '404',
+ ' ' + (idx + 1) + '. ' + item,
+ ]))
}
detail.push(['404', '\nNote that you can also install from a'])
diff --git a/lib/utils/file-exists.js b/lib/utils/file-exists.js
index 3149c0ae5..605472536 100644
--- a/lib/utils/file-exists.js
+++ b/lib/utils/file-exists.js
@@ -3,6 +3,8 @@ const util = require('util')
const stat = util.promisify(fs.stat)
-const fileExists = (file) => stat(file).then((stat) => stat.isFile()).catch(() => false)
+const fileExists = (file) => stat(file)
+ .then((stat) => stat.isFile())
+ .catch(() => false)
module.exports = fileExists
diff --git a/lib/utils/reify-output.js b/lib/utils/reify-output.js
index ed5733487..4abaadc2e 100644
--- a/lib/utils/reify-output.js
+++ b/lib/utils/reify-output.js
@@ -1,7 +1,7 @@
// pass in an arborist object, and it'll output the data about what
// was done, what was audited, etc.
//
-// added 351 packages, removed 132 packages, and audited 13388 packages in 19.157s
+// added ## packages, removed ## packages, and audited ## packages in 19.157s
//
// 1 package is looking for funding
// run `npm fund` for details
diff --git a/lib/view.js b/lib/view.js
index 42ba4b1c1..8af7cf939 100644
--- a/lib/view.js
+++ b/lib/view.js
@@ -196,7 +196,8 @@ const prettyView = async (packument, manifest, opts) => {
name: color.yellow(manifest._npmUser.name),
email: color.cyan(manifest._npmUser.email),
}),
- modified: packument.time ? color.yellow(relativeDate(packument.time[packument.version])) : undefined,
+ modified: !packument.time ? undefined
+ : color.yellow(relativeDate(packument.time[packument.version])),
maintainers: (packument.maintainers || []).map((u) => unparsePerson({
name: color.yellow(u.name),
email: color.cyan(u.email),
@@ -387,8 +388,14 @@ async function printData (data, name, opts) {
if (includeVersions || includeFields || typeof d !== 'string') {
if (opts.json)
msgJson[msgJson.length - 1][f] = d
- else
- d = inspect(d, { showHidden: false, depth: 5, colors: npm.color, maxArrayLength: null })
+ else {
+ d = inspect(d, {
+ showHidden: false,
+ depth: 5,
+ colors: npm.color,
+ maxArrayLength: null,
+ })
+ }
} else if (typeof d === 'string' && opts.json)
d = JSON.stringify(d)