The rule prefer-string-slice
claims in it's documentation:
String#substr() and String#substring() are the two lesser known legacy ways to slice a string. It's better to use String#slice() as it's a more popular option [...]
While I can find proof for that statement for String#substr()
, I can't seem to find any for String#substring()
. Especially the "more popular" part is confusing to me. Was there any survey made about this? I was not able to find any. If there was, there should be a link to give more weight to this argument.
Unlike others, this rule feels very arbitrary in its reasoning why one should use it. I'd suggest a more thoughtful explanation here.
One suggestion, that came up in a discussion with a colleague, is to double down on the "Array counterpart" point:
[...] that has a consistent Array counterpart.
The argument should be that strings are simply arrays of characters and thus can be treated like them (spread, index accessor, ...). This makes it much easier to make good arguments in favor of using this rule in projects. This could lead to an increase of adaptability (although I doubt it).
I'm not against this rule as is. My reasoning for this issue comes from a (previously mentioned) discussion with a colleague who questioned the integration of the rule. I've sent him the rules documentation as they usually have pretty good descriptions of why you should (or shouldn't) adapt them. They pointed out the missing source for statements made which I had to agree with.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too