src/content/docs/linter/rules/no-substr.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.8.2` - Diagnostic Category: [`lint/style/noSubstr`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has an [**unsafe**](/linter/#unsafe-fixes) fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`unicorn/prefer-string-slice`](https://github.com/sindresorhus/eslint-plugin-unicorn/blob/main/docs/rules/prefer-string-slice.md){
"linter": {
"rules": {
"style": {
"noSubstr": "error"
}
}
}
}
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();
foo.substring();
foo.slice(beginIndex, endIndex);