Skip to content

Commit 5ea4aec

Browse files
committed
change variables to generalize
1 parent 8a19819 commit 5ea4aec

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

src/rules/use-client.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -146,10 +146,10 @@ const create = Components.detect(
146146
}
147147

148148
function getBinaryBranchExecutedOnServer(node: BinaryExpression): {
149-
isWindowCheck: boolean;
149+
isGlobalClientPropertyCheck: boolean;
150150
serverBranch: Rule.Node | null;
151151
} {
152-
const isWindowCheck =
152+
const isGlobalClientPropertyCheck =
153153
node.left?.type === "UnaryExpression" &&
154154
node.left.operator === "typeof" &&
155155
node.left.argument?.type === "Identifier" &&
@@ -160,14 +160,14 @@ const create = Components.detect(
160160

161161
let serverBranch = null;
162162

163-
if (!isWindowCheck) {
164-
return { isWindowCheck, serverBranch };
163+
if (!isGlobalClientPropertyCheck) {
164+
return { isGlobalClientPropertyCheck, serverBranch };
165165
}
166166

167167
//@ts-expect-error
168168
const { parent } = node;
169169
if (!parent) {
170-
return { isWindowCheck, serverBranch };
170+
return { isGlobalClientPropertyCheck, serverBranch };
171171
}
172172

173173
if (node.operator === "===") {
@@ -184,7 +184,7 @@ const create = Components.detect(
184184
: null;
185185
}
186186

187-
return { isWindowCheck, serverBranch };
187+
return { isGlobalClientPropertyCheck, serverBranch };
188188
}
189189

190190
const isNodePartOfSafelyExecutedServerBranch = (
@@ -287,24 +287,24 @@ const create = Components.detect(
287287
const name = node.name;
288288
// @ts-expect-error
289289
if (undeclaredReferences.has(name) && browserOnlyGlobals.has(name)) {
290-
// find the nearest binary expression so we can see if this instance of window is being used in a `typeof window === undefined`-like check
290+
// find the nearest binary expression so we can see if this instance is being used in a `typeof window === undefined`-like check
291291
const binaryExpressionNode = findFirstParentOfType(
292292
node,
293293
"BinaryExpression"
294294
) as BinaryExpression | null;
295295
if (binaryExpressionNode) {
296-
const { isWindowCheck, serverBranch } =
296+
const { isGlobalClientPropertyCheck, serverBranch } =
297297
getBinaryBranchExecutedOnServer(binaryExpressionNode);
298-
// if this instance isn't part of a window check we report it
299-
if (!isWindowCheck) {
298+
// if this instance isn't part of a server check we report it
299+
if (!isGlobalClientPropertyCheck) {
300300
instances.push(name);
301301
reportMissingDirective("addUseClientBrowserAPI", node);
302-
} else if (isWindowCheck && serverBranch) {
303-
// if it is part of a window check, we don't report it and we save the server branch so we can check if future window instances are a part of the branch of code safely executed on the server
302+
} else if (isGlobalClientPropertyCheck && serverBranch) {
303+
// if it is part of a check, we don't report it and we save the server branch so we can check if future instances are a part of the branch of code safely executed on the server
304304
serverBranches.add(serverBranch);
305305
}
306306
} else {
307-
// if the window usage isn't part of the binary expression, we check to see if it's part of a safely checked server branch and report if not
307+
// if the usage isn't part of the binary expression, we check to see if it's part of a safely checked server branch and report if not
308308
if (!isNodePartOfSafelyExecutedServerBranch(node)) {
309309
instances.push(name);
310310
reportMissingDirective("addUseClientBrowserAPI", node);

0 commit comments

Comments
 (0)