From 78da60ffefcfd457a4432ce1492ee7b53d854450 Mon Sep 17 00:00:00 2001 From: Ivan Date: Tue, 22 Jun 2021 13:55:18 -0500 Subject: [PATCH] chore(linting): add bin and clean up lib/ls.js This adds linting checking to our bin directory, fixes the linting errors that generated, and cleans up lib/ls.js to remove unused variables. PR-URL: https://github.com/npm/cli/pull/3454 Credit: @Ivan12273 Close: #3454 Reviewed-by: @darcyclarke --- bin/npx-cli.js | 23 ++++++++++------------- lib/ls.js | 4 ---- package.json | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/bin/npx-cli.js b/bin/npx-cli.js index a495090c64c78..7a3fb39837d27 100755 --- a/bin/npx-cli.js +++ b/bin/npx-cli.js @@ -10,18 +10,18 @@ process.argv.splice(2, 0, 'exec') const removedSwitches = new Set([ 'always-spawn', 'ignore-existing', - 'shell-auto-fallback' + 'shell-auto-fallback', ]) const removedOpts = new Set([ 'npm', 'node-arg', - 'n' + 'n', ]) const removed = new Set([ ...removedSwitches, - ...removedOpts + ...removedOpts, ]) const { definitions, shorthands } = require('../lib/utils/config/index.js') @@ -40,7 +40,7 @@ const switches = new Set([ 'version', 'v', 'help', - 'h' + 'h', ]) // things that do take a value @@ -55,7 +55,7 @@ const opts = new Set([ 'shell', 'npm', 'node-arg', - 'n' + 'n', ]) // break out of loop when we find a positional argument or -- @@ -65,9 +65,9 @@ let i let sawRemovedFlags = false for (i = 3; i < process.argv.length; i++) { const arg = process.argv[i] - if (arg === '--') { + if (arg === '--') break - } else if (/^-/.test(arg)) { + else if (/^-/.test(arg)) { const [key, ...v] = arg.replace(/^-+/, '').split('=') switch (key) { @@ -87,9 +87,8 @@ for (i = 3; i < process.argv.length; i++) { // resolve shorthands and run again if (shorthands[key] && !removed.has(key)) { const a = [...shorthands[key]] - if (v.length) { + if (v.length) a.push(v.join('=')) - } process.argv.splice(i, 1, ...a) i-- continue @@ -110,9 +109,8 @@ for (i = 3; i < process.argv.length; i++) { if (removed.has(key)) { // also remove the value for the cut key. process.argv.splice(i + 1, 1) - } else { + } else i++ - } } } else { // found a positional arg, put -- in front of it, and we're done @@ -121,8 +119,7 @@ for (i = 3; i < process.argv.length; i++) { } } -if (sawRemovedFlags) { +if (sawRemovedFlags) console.error('See `npm help exec` for more information') -} cli(process) diff --git a/lib/ls.js b/lib/ls.js index f146928a96b41..c8d84651e2113 100644 --- a/lib/ls.js +++ b/lib/ls.js @@ -145,11 +145,9 @@ class LS extends ArboristWorkspaceCmd { dev, development, link, - node, prod, production, only, - tree, })) .map(mapEdgesToNodes({ seenPaths })) .concat(appendExtraneousChildren({ node, seenPaths })) @@ -392,11 +390,9 @@ const filterByEdgesTypes = ({ dev, development, link, - node, prod, production, only, - tree, }) => { // filter deps by type, allows for: `npm ls --dev`, `npm ls --prod`, // `npm ls --link`, `npm ls --only=dev`, etc diff --git a/package.json b/package.json index 58ac5d7f8c6c8..41015f44dc880 100644 --- a/package.json +++ b/package.json @@ -212,7 +212,7 @@ "sudotest:nocleanup": "sudo NO_TEST_CLEANUP=1 npm run test --", "posttest": "npm run lint", "eslint": "eslint", - "lint": "npm run eslint -- test/lib test/bin lib scripts docs smoke-tests", + "lint": "npm run eslint -- test/lib test/bin bin lib scripts docs smoke-tests", "lintfix": "npm run lint -- --fix", "prelint": "rimraf test/npm_cache*", "resetdeps": "bash scripts/resetdeps.sh",