Skip to main content

no-string-length-0

💼 This rule is enabled in the ✅ recommended config.

Disallows checking for empty strings via the length method in favor of direct comparison to an empty string.

💭 This rule requires type information.

This is helpful since the latter is shorter and easier to read.

Rule Details​

// Bad
declare const foo: string;
if (foo.length === 0) {
}

// Good
declare const foo: string;
if (foo === "") {
}

Options​

This rule is not configurable.

Resources​