diff options
author | isaacs <i@izs.me> | 2020-10-23 21:15:35 +0300 |
---|---|---|
committer | isaacs <i@izs.me> | 2020-10-23 21:23:15 +0300 |
commit | 47640eb2c3cd9891e904e3f6bc705b6618096103 (patch) | |
tree | 8b1b635135a5672ed0da4d8e6feade0f9d8fa60d /lib/config.js | |
parent | b737ee99961364827bacf210a3e5ca5d2b7edad2 (diff) |
update lint rules to match @npmcli/arborist
Diffstat (limited to 'lib/config.js')
-rw-r--r-- | lib/config.js | 45 |
1 files changed, 19 insertions, 26 deletions
diff --git a/lib/config.js b/lib/config.js index 21f3ab693..ad8db4ff5 100644 --- a/lib/config.js +++ b/lib/config.js @@ -28,15 +28,14 @@ const cmd = (args, cb) => config(args).then(() => cb()).catch(cb) const completion = (opts, cb) => { const argv = opts.conf.argv.remain - if (argv[1] !== 'config') { + if (argv[1] !== 'config') argv.unshift('config') - } if (argv.length === 2) { const cmds = ['get', 'set', 'delete', 'ls', 'rm', 'edit'] - if (opts.partialWord !== 'l') { + if (opts.partialWord !== 'l') cmds.push('list') - } + return cb(null, cmds) } @@ -44,9 +43,9 @@ const completion = (opts, cb) => { switch (action) { case 'set': // todo: complete with valid values, if possible. - if (argv.length > 3) { + if (argv.length > 3) return cb(null, []) - } + // fallthrough /* eslint no-fallthrough:0 */ case 'get': @@ -95,18 +94,16 @@ const config = async ([action, key, val]) => { } const set = async (key, val) => { - if (key === undefined) { + if (key === undefined) throw UsageError() - } if (val === undefined) { if (key.indexOf('=') !== -1) { const k = key.split('=') key = k.shift() val = k.join('=') - } else { + } else val = '' - } } key = key.trim() @@ -114,28 +111,25 @@ const set = async (key, val) => { npm.log.info('config', 'set %j %j', key, val) const where = npm.flatOptions.global ? 'global' : 'user' npm.config.set(key, val, where) - if (!npm.config.validate(where)) { + if (!npm.config.validate(where)) npm.log.warn('config', 'omitting invalid config values') - } + await npm.config.save(where) } const get = async key => { - if (!key) { + if (!key) return list() - } - if (!publicVar(key)) { + if (!publicVar(key)) throw `The ${key} option is protected, and cannot be retrieved in this way` - } output(npm.config.get(key)) } const del = async key => { - if (!key) { + if (!key) throw UsageError() - } const where = npm.flatOptions.global ? 'global' : 'user' npm.config.delete(key, where) @@ -144,9 +138,8 @@ const del = async key => { const edit = async () => { const { editor: e, global } = npm.flatOptions - if (!e) { + if (!e) throw new Error('No `editor` config or EDITOR environment variable set') - } const where = global ? 'global' : 'user' const file = npm.config.data.get(where).source @@ -199,13 +192,13 @@ const list = async () => { const msg = [] const { long } = npm.flatOptions for (const [where, { data, source }] of npm.config.data.entries()) { - if (where === 'default' && !long) { + if (where === 'default' && !long) continue - } + const keys = Object.keys(data).sort((a, b) => a.localeCompare(b)) - if (!keys.length) { + if (!keys.length) continue - } + msg.push(`; "${where}" config from ${source}`, '') for (const k of keys) { const v = publicVar(k) ? JSON.stringify(data[k]) : '(protected)' @@ -232,9 +225,9 @@ const list = async () => { const listJson = async () => { const publicConf = {} for (const key in npm.config.list[0]) { - if (!publicVar(key)) { + if (!publicVar(key)) continue - } + publicConf[key] = npm.config.get(key) } output(JSON.stringify(publicConf, null, 2)) |