Skip to content

Commit ec2f839

Browse files
Nogglingodinr
authored andcommitted
refactor: improve readability by adding braces to conditional statements and using array for path construction
1 parent 54e06ee commit ec2f839

7 files changed

Lines changed: 40 additions & 12 deletions

File tree

packages/plugins/context-navigation/src/guard-handlers/consume-own-nav-token.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import type { OwnNavigationTokens } from '../apply-navigation';
2121
*/
2222
export function consumeOwnNavToken(currentURL: URL, ownNavTokens: OwnNavigationTokens): boolean {
2323
const normalized = normalizePath(currentURL);
24+
2425
// Token present — this navigation was plugin-initiated; consume it and signal the caller to bail.
2526
if (ownNavTokens.has(normalized)) {
2627
ownNavTokens.delete(normalized);

packages/plugins/context-navigation/src/guard-handlers/handle-push-mode-guard.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,21 @@ export function handlePushModeGuard(
3535

3636
// Resolve the active context and adapter — both are required to fall back.
3737
const activeContext = appModules.context.currentContext;
38+
3839
// No active context to fall back to — nothing to do.
39-
if (!activeContext) return;
40+
if (!activeContext) {
41+
return;
42+
}
43+
4044
const adapter = resolveAdapter(
4145
{ appKey, appContext: appModules.context, routingStrategy, currentURL },
4246
deps.config.adapters,
4347
);
48+
4449
// No adapter matched — plugin is not responsible for this app's URL shape.
45-
if (!adapter) return;
50+
if (!adapter) {
51+
return;
52+
}
4653

4754
log(`URL guard: URL has context [${urlContextId}] for [${appKey}] — setting context from URL`);
4855

packages/plugins/context-navigation/src/guard-handlers/handle-replace-mode-guard.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,21 @@ export function handleReplaceModeGuard(
2929

3030
// Resolve the active context and adapter for re-encoding.
3131
const activeContext = appModules.context.currentContext;
32+
3233
// No active context to re-encode — nothing to correct.
33-
if (!activeContext) return;
34+
if (!activeContext) {
35+
return;
36+
}
37+
3438
const adapter = resolveAdapter(
3539
{ appKey, appContext: appModules.context, routingStrategy, currentURL },
3640
deps.config.adapters,
3741
);
42+
3843
// No adapter matched — plugin is not responsible for this app's URL shape.
39-
if (!adapter) return;
44+
if (!adapter) {
45+
return;
46+
}
4047

4148
log(`URL guard: context missing from URL, re-applying for [${appKey}]`);
4249
// Always replace when correcting URL drift. The URL has no context segment

packages/plugins/context-navigation/src/helpers/resolve-adapter.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export function resolveAdapter(
2323
for (const entry of adapters) {
2424
const adapter = typeof entry === 'function' ? entry(ctx) : entry.canHandle(ctx) ? entry : null;
2525
// Return the first adapter that can handle this context
26-
if (adapter) return adapter;
26+
if (adapter) {
27+
return adapter;
28+
}
2729
}
2830
return null;
2931
}

packages/plugins/context-navigation/src/utils/url/build-app-route.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
* @returns The constructed app route path string.
99
*/
1010
export const buildAppRoute = (appKey: string, contextId?: string, rest?: string): string => {
11-
let path = `/apps/${appKey}`;
11+
let path = [`/apps/${appKey}`];
1212

1313
// Context segment is optional — omitted when no context is actively selected
14-
if (contextId) path += `/${contextId}`;
14+
if (contextId) path.push(`${contextId}`);
1515

1616
// Preserve any sub-route depth that exists beyond the context segment
17-
if (rest) path += `/${rest}`;
17+
if (rest) path.push(`${rest}`);
1818

19-
return path;
19+
return path.join('/');
2020
};

packages/plugins/context-navigation/src/utils/url/build-context-url-for-strategy.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,11 @@ export const buildContextUrlForStrategy = (
3939

4040
// Path routing embeds the context id directly in the URL structure
4141
const match = parseAppRoute(path);
42+
4243
// Path is not a recognised app route — return it unchanged
43-
if (!match) return path;
44+
if (!match) {
45+
return path;
46+
}
47+
4448
return buildAppRoute(match.appKey, contextId ?? undefined);
4549
};

packages/plugins/context-navigation/src/utils/url/parse-app-route.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,18 @@ export const parseAppRoute = (pathname: string): AppRouteMatch | undefined => {
3939

4040
const normalized = pathname.replace(/\/+$/, '') || '/';
4141
const result = APP_ROUTE_PATTERN.exec({ pathname: normalized });
42+
4243
// Pathname does not match the /apps/:appKey pattern
43-
if (!result) return undefined;
44+
if (!result) {
45+
return undefined;
46+
}
47+
4448
const { appKey, contextId, rest } = result.pathname.groups;
49+
4550
// Guard against an empty appKey capture group (malformed pattern match)
46-
if (!appKey) return undefined;
51+
if (!appKey) {
52+
return undefined;
53+
}
4754
return {
4855
appKey,
4956
contextId: contextId || undefined,

0 commit comments

Comments
 (0)