Skip to content

Commit 5a0f2c7

Browse files
authored
refactor: remove unnecessary 'switch (true)' usage (#1148)
1 parent 388aba2 commit 5a0f2c7

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

packages/plugins/eslint-plugin-react-x/src/rules/no-leaked-conditional-rendering.ts

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,24 +111,19 @@ function inspectVariantTypes(types: ts.Type[]) {
111111
variantTypes.add("nullish");
112112
}
113113
const booleans = types.filter(tsHelpers.isBooleanType);
114+
const boolean0 = booleans[0];
114115
// If incoming type is either "true" or "false", there will be one type
115116
// object with intrinsicName set accordingly
116117
// If incoming type is boolean, there will be two type objects with
117118
// intrinsicName set "true" and "false" each because of ts-api-utils.unionTypeParts()
118-
switch (true) {
119-
case booleans.length === 1 && booleans[0] != null: {
120-
const first = booleans[0];
121-
if (isTrueLiteralType(first)) {
122-
variantTypes.add("truthy boolean");
123-
} else if (isFalseLiteralType(first)) {
124-
variantTypes.add("falsy boolean");
125-
}
126-
break;
127-
}
128-
case booleans.length === 2: {
129-
variantTypes.add("boolean");
130-
break;
119+
if (booleans.length === 1 && boolean0 != null) {
120+
if (isFalseLiteralType(boolean0)) {
121+
variantTypes.add("falsy boolean");
122+
} else if (isTrueLiteralType(boolean0)) {
123+
variantTypes.add("truthy boolean");
131124
}
125+
} else if (booleans.length === 2) {
126+
variantTypes.add("boolean");
132127
}
133128
const strings = types.filter(tsHelpers.isStringType);
134129
if (strings.length > 0) {

0 commit comments

Comments
 (0)