Skip to content

Latest commit

Β 

History

History
35 lines (24 loc) Β· 937 Bytes

File metadata and controls

35 lines (24 loc) Β· 937 Bytes

prefer-flat-math-min-max

πŸ“ Prefer flat Math.min() and Math.max() calls over nested calls.

πŸ’Ό This rule is enabled in the following configs: βœ… recommended, β˜‘οΈ unopinionated.

πŸ”§ This rule is automatically fixable by the --fix CLI option.

Math.min() and Math.max() accept any number of arguments, so nesting the same call is unnecessary.

Examples

// ❌
const biggest = Math.max(Math.max(a, b), c);

// βœ…
const biggest = Math.max(a, b, c);
// ❌
const smallest = Math.min(a, Math.min(b, c));

// βœ…
const smallest = Math.min(a, b, c);
// βœ…
const clamped = Math.max(Math.min(value, upper), lower);