Skip to content

Commit bd2ae5d

Browse files
wraithgarlukekarrys
authored andcommitted
fix: linting
In preparation for @npmcli/[email protected]
1 parent d54f031 commit bd2ae5d

29 files changed

+535
-524
lines changed

lib/commands/audit.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,11 +178,12 @@ class VerifySignatures {
178178
let name = edge.name
179179
try {
180180
name = npa(edge.spec).subSpec.name
181-
} catch (_) {
181+
} catch {
182+
// leave it as edge.name
182183
}
183184
try {
184185
return npa(`${name}@${edge.spec}`)
185-
} catch (_) {
186+
} catch {
186187
// Skip packages with invalid spec
187188
}
188189
}

lib/commands/edit.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,16 @@ class Edit extends BaseCommand {
5858
}
5959
const [bin, ...args] = this.npm.config.get('editor').split(/\s+/)
6060
const editor = cp.spawn(bin, [...args, dir], { stdio: 'inherit' })
61-
editor.on('exit', (code) => {
61+
editor.on('exit', async (code) => {
6262
if (code) {
6363
return reject(new Error(`editor process exited with code: ${code}`))
6464
}
65-
this.npm.exec('rebuild', [dir]).catch(reject).then(resolve)
65+
try {
66+
await this.npm.exec('rebuild', [dir])
67+
} catch (err) {
68+
reject(err)
69+
}
70+
resolve()
6671
})
6772
})
6873
})

lib/commands/org.js

Lines changed: 64 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class Org extends BaseCommand {
5050
})
5151
}
5252

53-
set (org, user, role, opts) {
53+
async set (org, user, role, opts) {
5454
role = role || 'developer'
5555
if (!org) {
5656
throw new Error('First argument `orgname` is required.')
@@ -67,27 +67,26 @@ class Org extends BaseCommand {
6767
)
6868
}
6969

70-
return liborg.set(org, user, role, opts).then(memDeets => {
71-
if (opts.json) {
72-
this.npm.output(JSON.stringify(memDeets, null, 2))
73-
} else if (opts.parseable) {
74-
this.npm.output(['org', 'orgsize', 'user', 'role'].join('\t'))
75-
this.npm.output(
76-
[memDeets.org.name, memDeets.org.size, memDeets.user, memDeets.role].join('\t')
77-
)
78-
} else if (!this.npm.silent) {
79-
this.npm.output(
80-
`Added ${memDeets.user} as ${memDeets.role} to ${memDeets.org.name}. You now have ${
70+
const memDeets = await liborg.set(org, user, role, opts)
71+
if (opts.json) {
72+
this.npm.output(JSON.stringify(memDeets, null, 2))
73+
} else if (opts.parseable) {
74+
this.npm.output(['org', 'orgsize', 'user', 'role'].join('\t'))
75+
this.npm.output(
76+
[memDeets.org.name, memDeets.org.size, memDeets.user, memDeets.role].join('\t')
77+
)
78+
} else if (!this.npm.silent) {
79+
this.npm.output(
80+
`Added ${memDeets.user} as ${memDeets.role} to ${memDeets.org.name}. You now have ${
8181
memDeets.org.size
8282
} member${memDeets.org.size === 1 ? '' : 's'} in this org.`
83-
)
84-
}
83+
)
84+
}
8585

86-
return memDeets
87-
})
86+
return memDeets
8887
}
8988

90-
rm (org, user, opts) {
89+
async rm (org, user, opts) {
9190
if (!org) {
9291
throw new Error('First argument `orgname` is required.')
9392
}
@@ -96,68 +95,62 @@ class Org extends BaseCommand {
9695
throw new Error('Second argument `username` is required.')
9796
}
9897

99-
return liborg
100-
.rm(org, user, opts)
101-
.then(() => {
102-
return liborg.ls(org, opts)
103-
})
104-
.then(roster => {
105-
user = user.replace(/^[~@]?/, '')
106-
org = org.replace(/^[~@]?/, '')
107-
const userCount = Object.keys(roster).length
108-
if (opts.json) {
109-
this.npm.output(
110-
JSON.stringify({
111-
user,
112-
org,
113-
userCount,
114-
deleted: true,
115-
})
116-
)
117-
} else if (opts.parseable) {
118-
this.npm.output(['user', 'org', 'userCount', 'deleted'].join('\t'))
119-
this.npm.output([user, org, userCount, true].join('\t'))
120-
} else if (!this.npm.silent) {
121-
this.npm.output(
122-
`Successfully removed ${user} from ${org}. You now have ${userCount} member${
123-
userCount === 1 ? '' : 's'
124-
} in this org.`
125-
)
126-
}
127-
})
98+
await liborg.rm(org, user, opts)
99+
const roster = await liborg.ls(org, opts)
100+
user = user.replace(/^[~@]?/, '')
101+
org = org.replace(/^[~@]?/, '')
102+
const userCount = Object.keys(roster).length
103+
if (opts.json) {
104+
this.npm.output(
105+
JSON.stringify({
106+
user,
107+
org,
108+
userCount,
109+
deleted: true,
110+
})
111+
)
112+
} else if (opts.parseable) {
113+
this.npm.output(['user', 'org', 'userCount', 'deleted'].join('\t'))
114+
this.npm.output([user, org, userCount, true].join('\t'))
115+
} else if (!this.npm.silent) {
116+
this.npm.output(
117+
`Successfully removed ${user} from ${org}. You now have ${userCount} member${
118+
userCount === 1 ? '' : 's'
119+
} in this org.`
120+
)
121+
}
128122
}
129123

130-
ls (org, user, opts) {
124+
async ls (org, user, opts) {
131125
if (!org) {
132126
throw new Error('First argument `orgname` is required.')
133127
}
134128

135-
return liborg.ls(org, opts).then(roster => {
136-
if (user) {
137-
const newRoster = {}
138-
if (roster[user]) {
139-
newRoster[user] = roster[user]
140-
}
141-
142-
roster = newRoster
129+
let roster = await liborg.ls(org, opts)
130+
if (user) {
131+
const newRoster = {}
132+
if (roster[user]) {
133+
newRoster[user] = roster[user]
143134
}
144-
if (opts.json) {
145-
this.npm.output(JSON.stringify(roster, null, 2))
146-
} else if (opts.parseable) {
147-
this.npm.output(['user', 'role'].join('\t'))
148-
Object.keys(roster).forEach(user => {
149-
this.npm.output([user, roster[user]].join('\t'))
135+
136+
roster = newRoster
137+
}
138+
if (opts.json) {
139+
this.npm.output(JSON.stringify(roster, null, 2))
140+
} else if (opts.parseable) {
141+
this.npm.output(['user', 'role'].join('\t'))
142+
Object.keys(roster).forEach(user => {
143+
this.npm.output([user, roster[user]].join('\t'))
144+
})
145+
} else if (!this.npm.silent) {
146+
const table = new Table({ head: ['user', 'role'] })
147+
Object.keys(roster)
148+
.sort()
149+
.forEach(user => {
150+
table.push([user, roster[user]])
150151
})
151-
} else if (!this.npm.silent) {
152-
const table = new Table({ head: ['user', 'role'] })
153-
Object.keys(roster)
154-
.sort()
155-
.forEach(user => {
156-
table.push([user, roster[user]])
157-
})
158-
this.npm.output(table.toString())
159-
}
160-
})
152+
this.npm.output(table.toString())
153+
}
161154
}
162155
}
163156
module.exports = Org

lib/commands/outdated.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ class Outdated extends ArboristWorkspaceCmd {
196196
try {
197197
alias = npa(edge.spec).subSpec
198198
} catch (err) {
199+
// ignore errors, no alias
199200
}
200201
const spec = npa(alias ? alias.name : edge.name)
201202
const node = edge.to || edge

lib/commands/token.js

Lines changed: 20 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -140,32 +140,27 @@ class Token extends BaseCommand {
140140
const cidr = conf.cidr
141141
const readonly = conf.readOnly
142142

143-
return readUserInfo
144-
.password()
145-
.then(password => {
146-
const validCIDR = this.validateCIDRList(cidr)
147-
log.info('token', 'creating')
148-
return pulseTillDone.withPromise(
149-
otplease(this.npm, conf, conf => {
150-
return profile.createToken(password, readonly, validCIDR, conf)
151-
})
152-
)
153-
})
154-
.then(result => {
155-
delete result.key
156-
delete result.updated
157-
if (conf.json) {
158-
this.npm.output(JSON.stringify(result))
159-
} else if (conf.parseable) {
160-
Object.keys(result).forEach(k => this.npm.output(k + '\t' + result[k]))
161-
} else {
162-
const table = new Table()
163-
for (const k of Object.keys(result)) {
164-
table.push({ [chalk.bold(k)]: String(result[k]) })
165-
}
166-
this.npm.output(table.toString())
167-
}
143+
const password = await readUserInfo.password()
144+
const validCIDR = this.validateCIDRList(cidr)
145+
log.info('token', 'creating')
146+
const result = await pulseTillDone.withPromise(
147+
otplease(this.npm, conf, conf => {
148+
return profile.createToken(password, readonly, validCIDR, conf)
168149
})
150+
)
151+
delete result.key
152+
delete result.updated
153+
if (conf.json) {
154+
this.npm.output(JSON.stringify(result))
155+
} else if (conf.parseable) {
156+
Object.keys(result).forEach(k => this.npm.output(k + '\t' + result[k]))
157+
} else {
158+
const table = new Table()
159+
for (const k of Object.keys(result)) {
160+
table.push({ [chalk.bold(k)]: String(result[k]) })
161+
}
162+
this.npm.output(table.toString())
163+
}
169164
}
170165

171166
config () {

lib/npm.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class Npm extends EventEmitter {
112112
// this is async but we dont await it, since its ok if it doesnt
113113
// finish before the command finishes running. it uses command and argv
114114
// so it must be initiated here, after the command name is set
115+
// eslint-disable-next-line promise/catch-or-return
115116
updateNotifier(this).then((msg) => (this.updateNotification = msg))
116117

117118
// Options are prefixed by a hyphen-minus (-, \u2d).
@@ -173,16 +174,15 @@ class Npm extends EventEmitter {
173174

174175
async load () {
175176
if (!this.#loadPromise) {
176-
this.#loadPromise = this.time('npm:load', () => this[_load]().catch(er => er).then((er) => {
177-
this.loadErr = er
178-
if (!er) {
179-
if (this.config.get('force')) {
180-
log.warn('using --force', 'Recommended protections disabled.')
181-
}
182-
} else {
177+
this.#loadPromise = this.time('npm:load', async () => {
178+
await this[_load]().catch((er) => {
179+
this.loadErr = er
183180
throw er
181+
})
182+
if (this.config.get('force')) {
183+
log.warn('using --force', 'Recommended protections disabled.')
184184
}
185-
}))
185+
})
186186
}
187187
return this.#loadPromise
188188
}
@@ -229,7 +229,9 @@ class Npm extends EventEmitter {
229229
const node = this.time('npm:load:whichnode', () => {
230230
try {
231231
return which.sync(process.argv[0])
232-
} catch {} // TODO should we throw here?
232+
} catch {
233+
// TODO should we throw here?
234+
}
233235
})
234236

235237
if (node && node.toUpperCase() !== process.execPath.toUpperCase()) {

lib/utils/queryable.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,9 @@ const setter = ({ data, key, value, force }) => {
148148
let maybeIndex = Number.NaN
149149
try {
150150
maybeIndex = Number(_key)
151-
} catch (err) {}
151+
} catch {
152+
// leave it NaN
153+
}
152154
if (!Number.isNaN(maybeIndex)) {
153155
_key = maybeIndex
154156
}

scripts/dependency-graph.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ const iterate = function (node, dependedBy, annotations, onlyOurs) {
168168

169169
main().then(() => {
170170
process.exit(0)
171+
return 0
171172
}).catch(err => {
172173
console.error(err)
173174
process.exit(1)
175+
return 1
174176
})

test/lib/commands/shrinkwrap.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ t.formatSnapshot = obj =>
1313
(k, v) => {
1414
try {
1515
return JSON.parse(v)
16-
} catch {}
16+
} catch {
17+
// leave invalid JSON as a string
18+
}
1719
return v
1820
},
1921
2

workspaces/arborist/bin/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ for (const file of commandFiles) {
9999
if (bin.loglevel !== 'silent') {
100100
console[process.exitCode ? 'error' : 'log'](r)
101101
}
102+
return r
102103
})
103104
}
104105
}

0 commit comments

Comments
 (0)