menu

prefer-string-slice

Prefer String.slice over the legacy String.substring operation

String.substring swaps reversed bounds and clamps negative bounds, which differs from collection slicing. Instead, you SHOULD use String.slice for the same start-inclusive, end-exclusive convention as arrays.

Review negative or dynamically ordered bounds because slice preserves their direction and interprets negative values from the end.

Reported

1function prefix(text: string, end: isize): string {2    return text.substring(0, end);3}

Accepted

1function prefix(text: string, end: isize): string {2    return text.slice(0, end);3}