Skip to content

Commit

Permalink
refactor: simplifies a few boolean expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
sverweij committed Dec 7, 2024
1 parent 8595b73 commit 7bcabe7
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/enrich/derive/reachable.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@ function shouldAddReaches(pRule, pModule) {
}

function hasCapturingGroups(pRule) {
const lCapturingGroupPlaceholderRe = "\\$[0-9]+";
const lCapturingGroupPlaceholderRe = /\$[0-9]+/;

return Boolean(
(pRule?.to?.path ?? "").match(lCapturingGroupPlaceholderRe) ||
(pRule?.to?.pathNot ?? "").match(lCapturingGroupPlaceholderRe),
return (
lCapturingGroupPlaceholderRe.test(pRule?.to?.path ?? "") ||
lCapturingGroupPlaceholderRe.test(pRule?.to?.pathNot ?? "")
);
}
function shouldAddReachable(pRule, pModuleTo, pGraph) {
Expand Down
6 changes: 2 additions & 4 deletions src/extract/acorn/estree-helpers.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ function isStringLiteral(pArgument) {

function firstArgumentIsAString(pArgumentsNode) {
return (
Boolean(pArgumentsNode) &&
pArgumentsNode[0] &&
isStringLiteral(pArgumentsNode[0])
pArgumentsNode && pArgumentsNode[0] && isStringLiteral(pArgumentsNode[0])
);
}

Expand All @@ -20,7 +18,7 @@ function isPlaceholderLessTemplateLiteral(pArgument) {

function firstArgumentIsATemplateLiteral(pArgumentsNode) {
return (
Boolean(pArgumentsNode) &&
pArgumentsNode &&
pArgumentsNode[0] &&
isPlaceholderLessTemplateLiteral(pArgumentsNode[0])
);
Expand Down
2 changes: 1 addition & 1 deletion src/extract/acorn/extract-amd-deps.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ function extractRegularAMDDependencies(pNode, pDependencies) {
.filter((pArgument) => pArgument.type === "ArrayExpression")
.forEach((pArgument) =>
pArgument.elements.forEach((pElement) => {
if (Boolean(pElement.value) && typeof pElement.value === "string") {
if (pElement.value && typeof pElement.value === "string") {
pDependencies.push({
module: pElement.value,
moduleSystem: "amd",
Expand Down
3 changes: 1 addition & 2 deletions src/graph-utl/consolidate-modules.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ function mergeModule(pLeftModule, pRightModule) {
.concat(pRightModule?.rules ?? [])
.sort(compareRules),
valid: pLeftModule.valid && pRightModule.valid,
consolidated:
Boolean(pLeftModule.consolidated) || Boolean(pRightModule.consolidated),
consolidated: pLeftModule.consolidated || pRightModule.consolidated,
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/report/dot/theming.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { has, get } from "#utl/object-util.mjs";
function matchesRE(pValue, pRE) {
const lMatchResult = pValue.match && pValue.match(pRE);

return Boolean(lMatchResult) && lMatchResult.length > 0;
return lMatchResult && lMatchResult.length > 0;
}

function matchesCriterion(pModuleKey, pCriterion) {
Expand Down
2 changes: 1 addition & 1 deletion src/report/text.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function toFlatModuleDependencies(pModule, pModulesInFocus, pHighlightFocused) {
return pModule.dependencies.map((pDependency) => ({
from: {
name: pModule.source,
highlight: pHighlightFocused && Boolean(pModule.matchesFocus),
highlight: pHighlightFocused && pModule.matchesFocus,
},
to: {
name: pDependency.resolved,
Expand Down

0 comments on commit 7bcabe7

Please sign in to comment.