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.
Example
❌ Bad:
String someValue = '🙂';
someValue.substring(0, 1); // LINT: Avoid calling '.substring' as it does not support UTF-16 (ex. emojis). This may lead to unexpected results. Try using 'characters.getRange' instead.
✅ Good:
String someValue = '🙂';
someValue.characters.getRange(0, 1);