コンテンツにスキップ

noSubstr

このコンテンツはまだ日本語訳がありません。

Diagnostic Category: lint/nursery/noSubstr

Since: v1.8.2

Sources:

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/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

foo.slice(beginIndex, endIndex);