Skip to content

Commit a92d310

Browse files
Edu93Jerisaacs
authored andcommitted
Add max-len to lint rules
PR-URL: #2361 Credit: @Edu93Jer Close: #2361 Reviewed-by: @isaacs EDIT(@isaacs): amended to match some of the fixes to our current style conventions
1 parent be4a090 commit a92d310

16 files changed

Lines changed: 88 additions & 30 deletions

.eslintrc.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@
6767
"key-spacing": ["error", { "beforeColon": false, "afterColon": true }],
6868
"keyword-spacing": ["error", { "before": true, "after": true }],
6969
"lines-between-class-members": ["error", "always", { "exceptAfterSingleLine": true }],
70+
"max-len": ["error", 80, {
71+
"ignoreUrls": true,
72+
"ignoreComments": false,
73+
"ignoreRegExpLiterals": true,
74+
"ignoreStrings": true,
75+
"ignoreTemplateLiterals": true
76+
}],
7077
"new-cap": ["error", { "newIsCap": true, "capIsNew": false, "properties": true }],
7178
"new-parens": "error",
7279
"no-array-constructor": "error",

lib/deprecate.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ const completion = (opts, cb) => {
2525
return libaccess.lsPackages(username, npm.flatOptions).then((packages) => {
2626
return Object.keys(packages)
2727
.filter((name) => packages[name] === 'write' &&
28-
(opts.conf.argv.remain.length === 0 || name.startsWith(opts.conf.argv.remain[0]))
28+
(opts.conf.argv.remain.length === 0 ||
29+
name.startsWith(opts.conf.argv.remain[0]))
2930
)
3031
})
3132
}).then((list) => cb(null, list), (err) => cb(err))

lib/doctor.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ const getLatestNodejsVersion = async () => {
5959
if (lts && semver.gt(version, maxLTS))
6060
maxLTS = version
6161

62-
if (semver.satisfies(version, currentRange) && semver.gt(version, maxCurrent))
62+
if (semver.satisfies(version, currentRange) &&
63+
semver.gt(version, maxCurrent))
6364
maxCurrent = version
6465
}
6566
const recommended = semver.gt(maxCurrent, maxLTS) ? maxCurrent : maxLTS
@@ -175,7 +176,12 @@ const verifyCachedFiles = async () => {
175176
tracker.info('verifyCachedFiles', 'Verifying the npm cache')
176177
try {
177178
const stats = await cacache.verify(npm.flatOptions.cache)
178-
const { badContentCount, reclaimedCount, missingContent, reclaimedSize } = stats
179+
const {
180+
badContentCount,
181+
reclaimedCount,
182+
missingContent,
183+
reclaimedSize,
184+
} = stats
179185
if (badContentCount || reclaimedCount || missingContent) {
180186
if (badContentCount)
181187
tracker.warn('verifyCachedFiles', `Corrupted content removed: ${badContentCount}`)

lib/init.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ const init = async args => {
4141
}
4242
}
4343
npm.config.set('package', [])
44+
const newArgs = [packageName, ...args.slice(1)]
4445
return new Promise((res, rej) => {
45-
npm.commands.exec([packageName, ...args.slice(1)], er => er ? rej(er) : res())
46+
npm.commands.exec(newArgs, er => er ? rej(er) : res())
4647
})
4748
}
4849

lib/npm.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ require('graceful-fs').gracefulify(require('fs'))
1313

1414
const procLogListener = require('./utils/proc-log-listener.js')
1515

16-
const hasOwnProperty = (obj, key) => Object.prototype.hasOwnProperty.call(obj, key)
16+
const hasOwnProperty = (obj, key) =>
17+
Object.prototype.hasOwnProperty.call(obj, key)
1718

1819
// the first time `npm.commands.xyz` is loaded, it gets added
1920
// to the cmds object, so we don't have to load it again.

lib/outdated.js

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ async function outdated_ (tree, deps, opts) {
167167
}
168168
} catch (err) {
169169
// silently catch and ignore ETARGET, E403 &
170-
// E404 errors, deps are just skipped
170+
// E404 errors, deps are just skipped {
171171
if (!(
172172
err.code === 'ETARGET' ||
173173
err.code === 'E403' ||
@@ -234,7 +234,16 @@ function makePretty (dep, opts) {
234234
// <fullpath>:<name@wanted>:<name@installed>:<name@latest>:<dependedby>
235235
function makeParseable (list, opts) {
236236
return list.map(dep => {
237-
const { name, current, wanted, latest, path, dependent, type, homepage } = dep
237+
const {
238+
name,
239+
current,
240+
wanted,
241+
latest,
242+
path,
243+
dependent,
244+
type,
245+
homepage,
246+
} = dep
238247
const out = [
239248
path,
240249
name + '@' + wanted,
@@ -252,7 +261,16 @@ function makeParseable (list, opts) {
252261
function makeJSON (list, opts) {
253262
const out = {}
254263
list.forEach(dep => {
255-
const { name, current, wanted, latest, path, type, dependent, homepage } = dep
264+
const {
265+
name,
266+
current,
267+
wanted,
268+
latest,
269+
path,
270+
type,
271+
dependent,
272+
homepage,
273+
} = dep
256274
out[name] = {
257275
current,
258276
wanted,

lib/profile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ function get (args) {
127127
})
128128
} else {
129129
const table = new Table()
130-
Object.keys(cleaned).forEach((k) => table.push({ [ansistyles.bright(k)]: cleaned[k] }))
130+
for (const k of Object.keys(cleaned))
131+
table.push({ [ansistyles.bright(k)]: cleaned[k] })
131132
output(table.toString())
132133
}
133134
}

lib/repo.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@ const getRepo = async pkg => {
3636
}
3737

3838
const info = hostedFromMani(mani)
39-
const url = info ? info.browse(mani.repository.directory) : unknownHostedUrl(rurl)
39+
const url = info ?
40+
info.browse(mani.repository.directory) : unknownHostedUrl(rurl)
4041

4142
if (!url) {
4243
throw Object.assign(new Error('no repository: could not get url'), {

lib/token.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,19 @@ function token (args, cb) {
7474

7575
function generateTokenIds (tokens, minLength) {
7676
const byId = {}
77-
tokens.forEach((token) => {
77+
for (const token of tokens) {
7878
token.id = token.key
7979
for (let ii = minLength; ii < token.key.length; ++ii) {
80-
if (!tokens.some((ot) => ot !== token && ot.key.slice(0, ii) === token.key.slice(0, ii))) {
80+
const match = tokens.some(ot =>
81+
ot !== token &&
82+
ot.key.slice(0, ii) === token.key.slice(0, ii))
83+
if (!match) {
8184
token.id = token.key.slice(0, ii)
8285
break
8386
}
8487
}
8588
byId[token.id] = token
86-
})
89+
}
8790
return byId
8891
}
8992

@@ -136,7 +139,8 @@ function list (args) {
136139
return
137140
}
138141
generateTokenIds(tokens, 6)
139-
const idWidth = tokens.reduce((acc, token) => Math.max(acc, token.id.length), 0)
142+
const idWidth = tokens.reduce((acc, token) =>
143+
Math.max(acc, token.id.length), 0)
140144
const table = new Table({
141145
head: ['id', 'token', 'created', 'readonly', 'CIDR whitelist'],
142146
colWidths: [Math.max(idWidth, 2) + 2, 9, 12, 10],
@@ -170,8 +174,8 @@ function rm (args) {
170174
else if (matches.length > 1)
171175
throw new Error(`Token ID "${id}" was ambiguous, a new token may have been created since you last ran \`npm token list\`.`)
172176
else {
173-
const tokenMatches = tokens.filter((token) => id.indexOf(token.token) === 0)
174-
if (tokenMatches.length === 0)
177+
const tokenMatches = tokens.some(t => id.indexOf(t.token) === 0)
178+
if (!tokenMatches)
175179
throw new Error(`Unknown token id or value "${id}".`)
176180

177181
toRemove.push(id)
@@ -212,7 +216,8 @@ function create (args) {
212216
Object.keys(result).forEach((k) => output(k + '\t' + result[k]))
213217
else {
214218
const table = new Table()
215-
Object.keys(result).forEach((k) => table.push({ [ansistyles.bright(k)]: String(result[k]) }))
219+
for (const k of Object.keys(result))
220+
table.push({ [ansistyles.bright(k)]: String(result[k]) })
216221
output(table.toString())
217222
}
218223
})

lib/unpublish.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ async function unpublish (args) {
9393

9494
const { name, version, publishConfig } = manifest
9595
const pkgJsonSpec = npa.resolve(name, version)
96-
97-
res = await otplease(opts, opts => libunpub(pkgJsonSpec, { ...opts, publishConfig }))
96+
const optsWithPub = { ...opts, publishConfig }
97+
res = await otplease(opts, opts => libunpub(pkgJsonSpec, optsWithPub))
9898
pkgName = name
9999
pkgVersion = version ? `@${version}` : ''
100100
} else {

0 commit comments

Comments
 (0)