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.

The rule reports equality and inequality comparisons with an empty string on either side. The rule ignores non-empty string literals and numeric comparisons.

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 provides no automatic fix. Rewrite the code to preserve its intended behavior.

For a boundary exception, use oxlint-disable-next-line rules/force-string-empty -- reason. Examples cover this rule only and may omit imports or declarations.

Source and tests

Enabled by the Effect preset.

force-string-empty.ts · Tests