Skip to content

Commit

Permalink
refactor: addresses small linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Nov 21, 2024
1 parent 09e9e41 commit f1a2c89
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 15 deletions.
3 changes: 1 addition & 2 deletions src/cli/utl/io.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
2 changes: 1 addition & 1 deletion src/extract/resolve/external-module-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/extract/resolve/module-classifiers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
//
Expand Down Expand Up @@ -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?
Expand Down
8 changes: 2 additions & 6 deletions src/extract/swc/dependency-visitor.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
);
}
Expand Down Expand Up @@ -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",
Expand Down
6 changes: 3 additions & 3 deletions src/main/rule-set/normalize.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -26,15 +26,15 @@ function normalizeSeverity(pSeverity) {
* @returns {string}
*/
function normalizeName(pRuleName) {
return pRuleName ? pRuleName : DEFAULT_RULE;
return pRuleName ?? DEFAULT_RULE;
}

/**
* @param {RuleScopeType} pScope?
* @returns {RuleScopeType}
*/
function normalizeScope(pScope) {
return pScope ? pScope : DEFAULT_SCOPE;
return pScope ?? DEFAULT_SCOPE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/utl/get-extension.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @ts-check
import { extname } from "node:path";

const EXTENSION_RE = /(?<extension>(?:(?:\.d\.(?:c|m)?ts)|\.coffee\.md)$)/;
const EXTENSION_RE = /(?<extension>(?:(?:\.d\.(?:[cm])?ts)|\.coffee\.md)$)/;

/**
* Returns the extension of the given file name path.
Expand Down

0 comments on commit f1a2c89

Please sign in to comment.