avoid-substring
Warns when a String.substring
method is used.
String.substring
does not support UTF-16 which can result in unexpected output when a string contains emojis.
Use package:characters
and characters.getRange
instead.
Additional resources:
Example
❌ Bad:
String someValue = '🙂';
someValue.substring(0, 1); // LINT
✅ Good:
String someValue = '🙂';
someValue.characters.getRange(0, 1);