From f1a2c89d341c43fe17eb52045aebb9d02c0f652f Mon Sep 17 00:00:00 2001 From: sverweij Date: Thu, 21 Nov 2024 21:02:33 +0100 Subject: [PATCH] refactor: addresses small linting issues --- src/cli/utl/io.mjs | 3 +-- src/extract/resolve/external-module-helpers.mjs | 2 +- src/extract/resolve/module-classifiers.mjs | 4 ++-- src/extract/swc/dependency-visitor.mjs | 8 ++------ src/main/rule-set/normalize.mjs | 6 +++--- src/utl/get-extension.mjs | 2 +- 6 files changed, 10 insertions(+), 15 deletions(-) diff --git a/src/cli/utl/io.mjs b/src/cli/utl/io.mjs index 2b037cf75..f7abb25a3 100644 --- a/src/cli/utl/io.mjs +++ b/src/cli/utl/io.mjs @@ -28,10 +28,9 @@ function writeToFile(pOutputTo, pDependencyString) { */ function writeToStdOut(pString, pBufferSize = PIPE_BUFFER_SIZE) { const lNumberOfChunks = Math.ceil(pString.length / pBufferSize); - let lIndex = 0; /* eslint no-plusplus: 0 */ - for (lIndex = 0; lIndex < lNumberOfChunks; lIndex++) { + for (let lIndex = 0; lIndex < lNumberOfChunks; lIndex++) { const lChunkStart = lIndex * pBufferSize; process.stdout.write( pString.substring(lChunkStart, lChunkStart + pBufferSize), diff --git a/src/extract/resolve/external-module-helpers.mjs b/src/extract/resolve/external-module-helpers.mjs index 9f90b1256..1f1a9d44a 100644 --- a/src/extract/resolve/external-module-helpers.mjs +++ b/src/extract/resolve/external-module-helpers.mjs @@ -78,7 +78,7 @@ function bareGetPackageJson(pModuleName, pFileDirectory, pResolveOptions) { try { const lPackageJsonFilename = resolve( join(getPackageRoot(pModuleName), "package.json"), - pFileDirectory ? pFileDirectory : process.cwd(), + pFileDirectory ?? process.cwd(), { ...pResolveOptions, // if a module has exports fields _and_ does not expose package.json diff --git a/src/extract/resolve/module-classifiers.mjs b/src/extract/resolve/module-classifiers.mjs index 9270e6259..e043042f7 100644 --- a/src/extract/resolve/module-classifiers.mjs +++ b/src/extract/resolve/module-classifiers.mjs @@ -150,7 +150,7 @@ function isWorkspaceAliased(pModuleName, pResolvedModuleName, pManifest) { // an object. To prevent the code from borking we check whether it's an array // see https://github.com/sverweij/dependency-cruiser/issues/919 const lWorkspaces = getWorkspacesArray(pManifest?.workspaces); - if (lWorkspaces.length >= 0) { + if (lWorkspaces.length > 0) { // workspaces are an array of globs that match the (sub) workspace // folder itself only. // @@ -193,7 +193,7 @@ function isWorkspaceAliased(pModuleName, pResolvedModuleName, pManifest) { // of the workspace, not the path of the workspace itself. So if it's // in node_modules we need to check against the unresolved modulename. // - // Other then the detection for when symlinks are resolved to their realpath + // Other than the detection for when symlinks are resolved to their realpath // (the if above), this is a 'best effort' detection only for now; there's // guaranteed to be scenarios where this will fail. How often is the // --preserve-symlinks flag used in practice, though? diff --git a/src/extract/swc/dependency-visitor.mjs b/src/extract/swc/dependency-visitor.mjs index eb402107e..2d0de5cc4 100644 --- a/src/extract/swc/dependency-visitor.mjs +++ b/src/extract/swc/dependency-visitor.mjs @@ -41,7 +41,7 @@ function argumentsAreUsable(pArguments) { ["StringLiteral", "TemplateLiteral"].includes( pArguments[0].expression.type, ) && - (!(pArguments[0].expression.type === "TemplateLiteral") || + (pArguments[0].expression.type !== "TemplateLiteral" || isPlaceholderlessTemplateLiteral(pArguments[0])) ); } @@ -250,11 +250,7 @@ export default Visitor // as visitors for some shapes of type annotations aren't completely // implemented yet (1.2.51) pNode can come in as null (also see // comments in accompanying unit test) - if ( - Boolean(pNode) && - Boolean(pNode.typeAnnotation) && - Boolean(pNode.typeAnnotation.argument) - ) + if (pNode && pNode.typeAnnotation && pNode.typeAnnotation.argument) this.lResult.push({ module: pNode.typeAnnotation.argument.value, moduleSystem: "es6", diff --git a/src/main/rule-set/normalize.mjs b/src/main/rule-set/normalize.mjs index ced729f6e..172df714f 100644 --- a/src/main/rule-set/normalize.mjs +++ b/src/main/rule-set/normalize.mjs @@ -16,7 +16,7 @@ const DEFAULT_RULE = "unnamed"; const DEFAULT_SCOPE = "module"; function normalizeSeverity(pSeverity) { - const lSeverity = pSeverity ? pSeverity : DEFAULT_SEVERITY; + const lSeverity = pSeverity ?? DEFAULT_SEVERITY; return VALID_SEVERITIES.test(lSeverity) ? lSeverity : DEFAULT_SEVERITY; } @@ -26,7 +26,7 @@ function normalizeSeverity(pSeverity) { * @returns {string} */ function normalizeName(pRuleName) { - return pRuleName ? pRuleName : DEFAULT_RULE; + return pRuleName ?? DEFAULT_RULE; } /** @@ -34,7 +34,7 @@ function normalizeName(pRuleName) { * @returns {RuleScopeType} */ function normalizeScope(pScope) { - return pScope ? pScope : DEFAULT_SCOPE; + return pScope ?? DEFAULT_SCOPE; } /** diff --git a/src/utl/get-extension.mjs b/src/utl/get-extension.mjs index e025feaaf..e8cc3ef27 100644 --- a/src/utl/get-extension.mjs +++ b/src/utl/get-extension.mjs @@ -1,7 +1,7 @@ // @ts-check import { extname } from "node:path"; -const EXTENSION_RE = /(?(?:(?:\.d\.(?:c|m)?ts)|\.coffee\.md)$)/; +const EXTENSION_RE = /(?(?:(?:\.d\.(?:[cm])?ts)|\.coffee\.md)$)/; /** * Returns the extension of the given file name path.