noConstantMathMinMaxClamp
Ce contenu n’est pas encore disponible dans votre langue.
Diagnostic Category: lint/correctness/noConstantMathMinMaxClamp
Since: v1.7.0
Sources:
- Same as:
min_max
Disallow the use of Math.min
and Math.max
to clamp a value where the result itself is constant.
Examples
Section titled ExamplesInvalid
Section titled Invalidcode-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 │
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 │