Skip to content

Commit b33c760

Browse files
sandersnruyadorno
authored andcommitted
Remove unused arguments on various function calls
I checked cli's code with Typescript using the tsconfig below. The compiler found a few arguments that are not used, so I removed them. In the case of `npm whoami`, it is clearer that it ignores its `args` and instead relies on `npm.flatOptions`. ```json { "compilerOptions": { "moduleResolution": "node", "module": "commonjs", "resolveJsonModule": true, "target": "es2019", "noImplicitAny": false, "noImplicitThis": true, "strict": true, "maxNodeModuleJsDepth": 0, "noEmit": true, "allowJs": true, "checkJs": true, "types": ["node"], "lib": ["esnext"] }, "include": ["lib"] } ``` PR-URL: #2766 Credit: @sandersn Close: #2766 Reviewed-by: @nlf, @ruyadorno, @Matausi29
1 parent c8b73db commit b33c760

File tree

6 files changed

+15
-19
lines changed

6 files changed

+15
-19
lines changed

lib/access.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const usageUtil = require('./utils/usage.js')
1010
const getIdentity = require('./utils/get-identity.js')
1111

1212
const usage = usageUtil(
13-
'npm access',
13+
'access',
1414
'npm access public [<package>]\n' +
1515
'npm access restricted [<package>]\n' +
1616
'npm access grant <read-only|read-write> <scope:team> [<package>]\n' +

lib/ls.js

+2-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const usage = usageUtil(
3131

3232
const cmd = (args, cb) => ls(args).then(() => cb()).catch(cb)
3333

34-
const initTree = async ({ arb, args, json }) => {
34+
const initTree = async ({ arb, args }) => {
3535
const tree = await arb.loadActual()
3636
tree[_include] = args.length === 0
3737
tree[_depth] = 0
@@ -252,7 +252,6 @@ const augmentNodesWithMetadata = ({
252252
args,
253253
currentDepth,
254254
nodeResult,
255-
parseable,
256255
seenNodes,
257256
}) => (node) => {
258257
// if the original edge was a deduped dep, treeverse will fail to
@@ -285,7 +284,7 @@ const augmentNodesWithMetadata = ({
285284
// _filteredBy is used to apply extra color info to the item that
286285
// was used in args in order to filter
287286
node[_filteredBy] = node[_include] =
288-
filterByPositionalArgs(args, { node: seenNodes.get(node.path), seenNodes })
287+
filterByPositionalArgs(args, { node: seenNodes.get(node.path) })
289288
// _depth keeps track of how many levels deep tree traversal currently is
290289
// so that we can `npm ls --depth=1`
291290
node[_depth] = currentDepth + 1
@@ -389,8 +388,6 @@ const ls = async (args) => {
389388
const tree = await initTree({
390389
arb,
391390
args,
392-
global,
393-
json,
394391
})
395392

396393
const seenItems = new Set()
@@ -436,7 +433,6 @@ const ls = async (args) => {
436433
args,
437434
currentDepth: node[_depth],
438435
nodeResult,
439-
parseable,
440436
seenNodes,
441437
}))
442438
},

lib/npm.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ const npm = module.exports = new class extends EventEmitter {
193193
this.title = tokrev ? 'npm token revoke' + (this.argv[2] ? ' ***' : '')
194194
: ['npm', ...this.argv].join(' ')
195195

196-
this.color = setupLog(this.config, this)
196+
this.color = setupLog(this.config)
197197
process.env.COLOR = this.color ? '1' : '0'
198198

199199
cleanUpLogFiles(this.cache, this.config.get('logs-max'), log.warn)

lib/profile.js

+4-3
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,10 @@ const readUserInfo = require('./utils/read-user-info.js')
1414
const usageUtil = require('./utils/usage.js')
1515

1616
const usage = usageUtil(
17-
'npm profile enable-2fa [auth-only|auth-and-writes]\n',
18-
'npm profile disable-2fa\n',
19-
'npm profile get [<key>]\n',
17+
'profile',
18+
'npm profile enable-2fa [auth-only|auth-and-writes]\n' +
19+
'npm profile disable-2fa\n' +
20+
'npm profile get [<key>]\n' +
2021
'npm profile set <key> <value>'
2122
)
2223

lib/whoami.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ const output = require('./utils/output.js')
33
const getIdentity = require('./utils/get-identity.js')
44
const usageUtil = require('./utils/usage.js')
55

6-
const cmd = (args, cb) => whoami(args).then(() => cb()).catch(cb)
6+
const cmd = (args, cb) => whoami().then(() => cb()).catch(cb)
77

88
const usage = usageUtil('whoami', 'npm whoami [--registry <registry>]\n(just prints username according to given registry)')
99

10-
const whoami = async ([spec]) => {
10+
const whoami = async () => {
1111
const opts = npm.flatOptions
12-
const username = await getIdentity(opts, spec)
12+
const username = await getIdentity(opts)
1313
output(opts.json ? JSON.stringify(username) : username)
1414
}
1515

tap-snapshots/test-lib-utils-npm-usage.js-TAP.test.js

+4-5
Original file line numberDiff line numberDiff line change
@@ -393,11 +393,10 @@ All commands:
393393
394394
prefix npm prefix [-g]
395395
396-
profile npm profile disable-2fa
397-
398-
399-
common options: npm profile get [<key>]
400-
396+
profile npm profile enable-2fa [auth-only|auth-and-writes]
397+
npm profile disable-2fa
398+
npm profile get [<key>]
399+
npm profile set <key> <value>
401400
402401
prune npm prune [[<@scope>/]<pkg>...] [--production]
403402

0 commit comments

Comments
 (0)