Skip to content

Commit 0c92069

Browse files
committed
consistent-boolean-name: Simplify promised type handling
Fixes #3622
1 parent 45a024b commit 0c92069

2 files changed

Lines changed: 8 additions & 20 deletions

File tree

rules/consistent-boolean-name.js

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import {isRegExp} from 'node:util/types';
22
import {findVariable, getPropertyName} from '@eslint-community/eslint-utils';
33
import {renameVariable} from './fix/index.js';
4-
import {combineBooleanStates, getPromisedTypeBooleanState, getTypeBooleanState} from './utils/get-type-boolean-state.js';
4+
import {combineBooleanStates, getTypeBooleanState} from './utils/get-type-boolean-state.js';
55
import resolveVariableName from './utils/resolve-variable-name.js';
66
import {getBooleanWrapperVariableState} from './utils/get-boolean-wrapper-variable-state.js';
77
import {
@@ -677,16 +677,16 @@ function getPromisedTypeInformationBooleanState(node, context, allowNullish = tr
677677
return unknown;
678678
}
679679

680-
return nonNullableType.isUnion()
681-
? getPossiblyPromisedTypeBooleanState(nonNullableType, checker, allowNullish)
682-
: getPromisedTypeBooleanState(nonNullableType, checker);
680+
return getPossiblyPromisedTypeBooleanState(nonNullableType, checker, allowNullish);
683681
} catch {
684682
return unknown;
685683
}
686684
}
687685

688686
function getPossiblyPromisedTypeBooleanState(type, checker, allowNullish) {
689-
const awaitedType = checker.getAwaitedType(type);
687+
const awaitedType = type.isUnion()
688+
? checker.getAwaitedType(type)
689+
: checker.getPromisedTypeOfPromise(type);
690690
if (!awaitedType) {
691691
return unknown;
692692
}
@@ -1796,21 +1796,7 @@ function getAsyncFunctionTypeInformationBooleanState(node, context, allowNullish
17961796
return unknown;
17971797
}
17981798

1799-
if (nonNullableReturnType.isUnion()) {
1800-
return getPossiblyPromisedTypeBooleanState(nonNullableReturnType, checker, allowNullish);
1801-
}
1802-
1803-
const promisedType = checker.getPromisedTypeOfPromise(nonNullableReturnType);
1804-
if (!promisedType) {
1805-
return unknown;
1806-
}
1807-
1808-
const nonNullableType = checker.getNonNullableType(promisedType);
1809-
if (!allowNullish && nonNullableType !== promisedType) {
1810-
return unknown;
1811-
}
1812-
1813-
return getTypeBooleanState(nonNullableType, checker, new Set(), false);
1799+
return getPossiblyPromisedTypeBooleanState(nonNullableReturnType, checker, allowNullish);
18141800
}));
18151801
} catch {
18161802
return unknown;

test/consistent-boolean-name.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,8 +1589,10 @@ test({
15891589
'declare const completed: () => boolean | Promise<boolean> | undefined;',
15901590
'declare const isReady: () => boolean | Promise<boolean> | undefined;',
15911591
'declare const isAvailable: (() => boolean | Promise<boolean>) | undefined;',
1592+
'declare const available: (() => boolean | Promise<boolean>) | undefined;',
15921593
'type MaybePromise<T> = T | Promise<T> | undefined;',
15931594
'declare const hasAccess: () => MaybePromise<boolean>;',
1595+
'declare const access: () => MaybePromise<boolean>;',
15941596
].join(' '),
15951597
}),
15961598
typeAware({

0 commit comments

Comments
 (0)