Skip to content

Commit

Permalink
chore(linting): add bin and clean up lib/ls.js
Browse files Browse the repository at this point in the history
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: #3454
Credit: @Ivan12273
Close: #3454
Reviewed-by: @darcyclarke
  • Loading branch information
Ivan12273 authored and wraithgar committed Jun 23, 2021
1 parent 53f81af commit 78da60f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 18 deletions.
23 changes: 10 additions & 13 deletions bin/npx-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -40,7 +40,7 @@ const switches = new Set([
'version',
'v',
'help',
'h'
'h',
])

// things that do take a value
Expand All @@ -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 --
Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)
4 changes: 0 additions & 4 deletions lib/ls.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,11 +145,9 @@ class LS extends ArboristWorkspaceCmd {
dev,
development,
link,
node,
prod,
production,
only,
tree,
}))
.map(mapEdgesToNodes({ seenPaths }))
.concat(appendExtraneousChildren({ node, seenPaths }))
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 78da60f

Please sign in to comment.