noConstantMathMinMaxClamp
¥Summary
-
规则生效日期:
v1.7.0¥Rule available since:
v1.7.0 -
诊断类别:
lint/correctness/noConstantMathMinMaxClamp¥Diagnostic Category:
lint/correctness/noConstantMathMinMaxClamp -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "correctness": { "noConstantMathMinMaxClamp": "error" } } }}¥Description
禁止使用 Math.min 和 Math.max 来限制结果本身为常数的值。
¥Disallow the use of Math.min and Math.max to clamp a value where the result itself is constant.
¥Examples
¥Invalid
Math.min(0, Math.max(100, x));code-block.js:1:1 lint/correctness/noConstantMathMinMaxClamp FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This Math.min/Math.max combination leads to a constant result.
> 1 │ Math.min(0, Math.max(100, x));
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ It always evaluates to 0.
> 1 │ Math.min(0, Math.max(100, x));
│ ^
2 │
ℹ Unsafe fix: Swap 0 with 100.
1 │ - Math.min(0,·Math.max(100,·x));
1 │ + Math.min(100,·Math.max(0,·x));
2 2 │
Math.max(100, Math.min(0, x));code-block.js:1:1 lint/correctness/noConstantMathMinMaxClamp FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This Math.min/Math.max combination leads to a constant result.
> 1 │ Math.max(100, Math.min(0, x));
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2 │
ℹ It always evaluates to 100.
> 1 │ Math.max(100, Math.min(0, x));
│ ^^^
2 │
ℹ Unsafe fix: Swap 100 with 0.
1 │ - Math.max(100,·Math.min(0,·x));
1 │ + Math.max(0,·Math.min(100,·x));
2 2 │
¥Valid
Math.min(100, Math.max(0, x));¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号