Rules

force-string-empty

Use String.isEmpty and String.isNonEmpty for empty strings.

Purpose and behavior

Use String.isEmpty and String.isNonEmpty for empty strings.

Detects equality and inequality against the empty string on either side. Non-empty string literals and unrelated numeric comparisons are ignored.

Options

No configurable options. Enable with "rules/force-string-empty": "error".

Invalid example

if (s === '') {}

Valid example

if (String.isEmpty(s)) {}

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-string-empty -- reason comment. Examples illustrate this rule alone and may omit imports and declarations.

Source and tests

Enabled by the Effect preset.

force-string-empty.ts · Tests