noSubstr
Summary
Section titled “Summary”- Rule available since:
v1.8.2 - Diagnostic Category:
lint/style/noSubstr - This rule has an unsafe fix.
- The default severity of this rule is information.
- Sources:
- Same as
unicorn/prefer-string-slice
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "style": { "noSubstr": "error" } } }}Description
Section titled “Description”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:
Examples
Section titled “Examples”Invalid
Section titled “Invalid”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);Related links
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.