noSubstr
Diagnostic Category: lint/nursery/noSubstr
Since: v1.8.2
Sources:
- Same as: 
unicorn/prefer-string-slice 
Description
Section titled DescriptionEnforce 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 ExamplesInvalid
Section titled Invalidfoo.substr();code-block.js:1:5 lint/nursery/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/nursery/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 │   
  
Valid
Section titled Validfoo.slice(beginIndex, endIndex);How to configure
Section titled How to configure{  "linter": {    "rules": {      "nursery": {        "noSubstr": "error"      }    }  }}