useTrimStartEnd
诊断类别:lint/nursery/useTrimStartEnd
¥Diagnostic Category: lint/nursery/useTrimStartEnd
自从:v1.9.0
¥Since: v1.9.0
来源:
¥Sources:
强制使用 String.trimStart()
和 String.trimEnd()
而不是 String.trimLeft()
和 String.trimRight()
。
¥Enforce the use of String.trimStart()
and String.trimEnd()
over String.trimLeft()
and String.trimRight()
.
虽然 String.trimLeft()
和 String.trimRight()
是 String.trimStart()
和 String.trimEnd()
的别名,但仅使用后一对可确保一致性,并且更适合其与方向无关的措辞。
¥While String.trimLeft()
and String.trimRight()
are aliases for String.trimStart()
and String.trimEnd()
,
only using the latter pair ensures consistency and is preferable for their direction-independent wording.
请注意,String.trimStart()
和 String.trimEnd()
方法不接受任何参数。传递给这些方法的任何参数都将被忽略。有关更多详细信息,请参阅 MDN 文档:
¥Note that String.trimStart()
and String.trimEnd()
methods do not take any parameters. Any arguments passed to these methods will be ignored.
See the MDN documentation for more details:
¥Examples
¥Invalid
code-block.js:1:17 lint/nursery/useTrimStartEnd FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Use trimStart instead of trimLeft.
> 1 │ const foo = bar.trimLeft();
│ ^^^^^^^^
2 │
ℹ trimLeft is an alias for trimStart.
ℹ Safe fix: Replace trimLeft with trimStart.
1 │ - const·foo·=·bar.trimLeft();
1 │ + const·foo·=·bar.trimStart();
2 2 │
code-block.js:1:17 lint/nursery/useTrimStartEnd FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Use trimEnd instead of trimRight.
> 1 │ const foo = bar.trimRight();
│ ^^^^^^^^^
2 │
ℹ trimRight is an alias for trimEnd.
ℹ Safe fix: Replace trimRight with trimEnd.
1 │ - const·foo·=·bar.trimRight();
1 │ + const·foo·=·bar.trimEnd();
2 2 │
¥Valid
¥Related links