# oxc/bad-min-max-func

> Disallow `Math.min` and `Math.max` combinations that always give the same result

`Math.min(Math.max(value, low), high)` keeps a value between two limits. If you swap the limits, the result no longer depends on the value. `Math.min(Math.max(value, 100), 0)` is `0` for every `value`, because the inner call is at least `100`.

The rule compares the number literals in a `Math.min` call with those in a `Math.max` call nested directly inside it, or the other way around. Limits that are variables aren't checked.

{/* Generated by src/codegen/lint-rule-docs.ts. Do not edit this section. */}

## Configure

Off by default. To turn it on:

```toml bunfig.toml
[lint.rules]
"oxc/bad-min-max-func" = "error" # or "warn"
```

{/* End of the generated section. */}

## Examples

Reported:

{/* bad {"count": 2} */}
```js
const percent = Math.min(Math.max(input, 100), 0);
const channel = Math.max(255, Math.min(0, red));
```

Not reported:

{/* good */}
```js
const percent = Math.min(Math.max(input, 0), 100);
const channel = Math.max(0, Math.min(255, red));
const page = Math.min(Math.max(requested, first), last);
```
