Aller au contenu

noSubstr

Ce contenu n’est pas encore disponible dans votre langue.

Enforce the use of String.slice() over String.substr() and String.substring().

String.slice() is preferred over String.substr() and String.substring() because it is a more popular option with clearer behavior, and it has a consistent counterpart in arrays.

Note that String.substr, String.substring and String.slice are not identical when arguments are passed. For detailed differences, refer to the MDN documentation:

foo.substr();
code-block.js:1:5 lint/style/noSubstr  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid using substr and consider using slice instead.

> 1 │ foo.substr();
^^^^^^
2 │

slice is more commonly used and has a less surprising behavior.

See MDN web docs for more details.

Unsafe fix: Use .slice() instead.

1 - foo.substr();
1+ foo.slice();
2 2

foo.substring();
code-block.js:1:5 lint/style/noSubstr  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Avoid using substring and consider using slice instead.

> 1 │ foo.substring();
^^^^^^^^^
2 │

slice is more commonly used and has a less surprising behavior.

See MDN web docs for more details.

Unsafe fix: Use .slice() instead.

1 - foo.substring();
1+ foo.slice();
2 2

foo.slice(beginIndex, endIndex);
biome.json
{
"linter": {
"rules": {
"style": {
"noSubstr": "error"
}
}
}
}