Rules
force-predicate
Replace direct null, undefined and typeof comparisons with predicates.
Purpose and behavior
Replace direct null, undefined and typeof comparisons with predicates.
Recognizes null/undefined equality checks and supported typeof string comparisons. Numeric comparisons are ignored. When prefer-is-nullish is enabled too, choose Predicate.isNullish or isNotNullish unless distinguishing null and undefined is required.
Options
No configurable options. Enable with "rules/force-predicate": "error".
Invalid example
if (typeof x === 'string') {}Valid example
if (Predicate.isString(x)) {}Fixes and exceptions
This rule reports diagnostics without an automatic fix. Rewrite the code deliberately rather than guessing its intended semantics.
For a genuine boundary exception, use an oxlint-disable-next-line rules/force-predicate -- reason comment. Examples illustrate this rule alone and may omit imports and declarations.
Source and tests
Enabled by the Effect preset.