From 534ad7789e5c61f579f44d782bdd18ea3ff1ee20 Mon Sep 17 00:00:00 2001 From: btea <2356281422@qq.com> Date: Fri, 4 Oct 2024 02:15:15 +0800 Subject: [PATCH] fix: remove unused parameters catch statements (#7795) --- lib/commands/cache.js | 4 ++-- lib/commands/diff.js | 10 +++++----- lib/commands/dist-tag.js | 2 +- lib/commands/doctor.js | 2 +- lib/commands/explain.js | 2 +- lib/commands/init.js | 2 +- lib/commands/install.js | 4 ++-- lib/commands/ls.js | 2 +- lib/commands/repo.js | 2 +- lib/utils/sbom-cyclonedx.js | 4 ++-- lib/utils/sbom-spdx.js | 2 +- 11 files changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/commands/cache.js b/lib/commands/cache.js index 87c70a57dc0ed..45d308a57d0c2 100644 --- a/lib/commands/cache.js +++ b/lib/commands/cache.js @@ -38,7 +38,7 @@ const searchCachePackage = async (path, parsed, cacheKeys) => { try { details = await cacache.get(path, key) packument = jsonParse(details.data) - } catch (_) { + } catch { // if we couldn't parse the packument, abort continue } @@ -131,7 +131,7 @@ class Cache extends BaseCommand { let entry try { entry = await cacache.get(cachePath, key) - } catch (err) { + } catch { log.warn('cache', `Not Found: ${key}`) break } diff --git a/lib/commands/diff.js b/lib/commands/diff.js index 3fa8090a35046..a97eed92c83cb 100644 --- a/lib/commands/diff.js +++ b/lib/commands/diff.js @@ -83,7 +83,7 @@ class Diff extends BaseCommand { try { const { content: pkg } = await pkgJson.normalize(this.prefix) name = pkg.name - } catch (e) { + } catch { log.verbose('diff', 'could not read project dir package.json') } @@ -117,7 +117,7 @@ class Diff extends BaseCommand { try { const { content: pkg } = await pkgJson.normalize(this.prefix) pkgName = pkg.name - } catch (e) { + } catch { log.verbose('diff', 'could not read project dir package.json') noPackageJson = true } @@ -156,7 +156,7 @@ class Diff extends BaseCommand { node = actualTree && actualTree.inventory.query('name', spec.name) .values().next().value - } catch (e) { + } catch { log.verbose('diff', 'failed to load actual install tree') } @@ -230,7 +230,7 @@ class Diff extends BaseCommand { try { const { content: pkg } = await pkgJson.normalize(this.prefix) pkgName = pkg.name - } catch (e) { + } catch { log.verbose('diff', 'could not read project dir package.json') } @@ -265,7 +265,7 @@ class Diff extends BaseCommand { } const arb = new Arborist(opts) actualTree = await arb.loadActual(opts) - } catch (e) { + } catch { log.verbose('diff', 'failed to load actual install tree') } diff --git a/lib/commands/dist-tag.js b/lib/commands/dist-tag.js index 663f0eb44a26a..ba9d6446c869f 100644 --- a/lib/commands/dist-tag.js +++ b/lib/commands/dist-tag.js @@ -182,7 +182,7 @@ class DistTag extends BaseCommand { try { output.standard(`${name}:`) await this.list(npa(name), this.npm.flatOptions) - } catch (err) { + } catch { // set the exitCode directly, but ignore the error // since it will have already been logged by this.list() process.exitCode = 1 diff --git a/lib/commands/doctor.js b/lib/commands/doctor.js index 8fbd49b7ca8bf..64a8423a32fa3 100644 --- a/lib/commands/doctor.js +++ b/lib/commands/doctor.js @@ -246,7 +246,7 @@ class Doctor extends BaseCommand { try { await access(f, mask) - } catch (er) { + } catch { ok = false const msg = `Missing permissions on ${f} (expect: ${maskLabel(mask)})` log.error('doctor', 'checkFilesPermission', msg) diff --git a/lib/commands/explain.js b/lib/commands/explain.js index cb0644304d2b5..1505b4dbf5e9a 100644 --- a/lib/commands/explain.js +++ b/lib/commands/explain.js @@ -109,7 +109,7 @@ class Explain extends ArboristWorkspaceCmd { // otherwise, try to select all matching nodes try { return this.getNodesByVersion(tree, arg) - } catch (er) { + } catch { return [] } } diff --git a/lib/commands/init.js b/lib/commands/init.js index 09e8d8522f7f3..bef54b0e4138d 100644 --- a/lib/commands/init.js +++ b/lib/commands/init.js @@ -192,7 +192,7 @@ class Init extends BaseCommand { // top-level package.json try { statSync(resolve(workspacePath, 'package.json')) - } catch (err) { + } catch { return } diff --git a/lib/commands/install.js b/lib/commands/install.js index 24e5f6819b314..71f4229bb2566 100644 --- a/lib/commands/install.js +++ b/lib/commands/install.js @@ -68,7 +68,7 @@ class Install extends ArboristWorkspaceCmd { const contents = await readdir(join(partialPath, sibling)) const result = (contents.indexOf('package.json') !== -1) return result - } catch (er) { + } catch { return false } } @@ -86,7 +86,7 @@ class Install extends ArboristWorkspaceCmd { } // no matches return [] - } catch (er) { + } catch { return [] // invalid dir: no matching } } diff --git a/lib/commands/ls.js b/lib/commands/ls.js index 417cb1b40d8c2..bc8beb007e809 100644 --- a/lib/commands/ls.js +++ b/lib/commands/ls.js @@ -233,7 +233,7 @@ const isGitNode = (node) => { try { const { type } = npa(node.resolved) return type === 'git' || type === 'hosted' - } catch (err) { + } catch { return false } } diff --git a/lib/commands/repo.js b/lib/commands/repo.js index 3f120c0a3f59f..0bfb2cf962c9b 100644 --- a/lib/commands/repo.js +++ b/lib/commands/repo.js @@ -49,7 +49,7 @@ const unknownHostedUrl = url => { const proto = /(git\+)http:$/.test(protocol) ? 'http:' : 'https:' const path = pathname.replace(/\.git$/, '') return `${proto}//${hostname}${path}` - } catch (e) { + } catch { return null } } diff --git a/lib/utils/sbom-cyclonedx.js b/lib/utils/sbom-cyclonedx.js index 989abea58dae8..f3bab28000953 100644 --- a/lib/utils/sbom-cyclonedx.js +++ b/lib/utils/sbom-cyclonedx.js @@ -94,7 +94,7 @@ const toCyclonedxItem = (node, { packageType }) => { } parsedLicense = parseLicense(license) - } catch (err) { + } catch { parsedLicense = null } @@ -192,7 +192,7 @@ const isGitNode = (node) => { try { const { type } = npa(node.resolved) return type === 'git' || type === 'hosted' - } catch (err) { + } catch { /* istanbul ignore next */ return false } diff --git a/lib/utils/sbom-spdx.js b/lib/utils/sbom-spdx.js index e3af77e10c751..16aed18656764 100644 --- a/lib/utils/sbom-spdx.js +++ b/lib/utils/sbom-spdx.js @@ -173,7 +173,7 @@ const isGitNode = (node) => { try { const { type } = npa(node.resolved) return type === 'git' || type === 'hosted' - } catch (err) { + } catch { /* istanbul ignore next */ return false }