{"record":{"id":"425c9ed7d2040212","repo":"oxc-project/oxc","slug":"prefer-math-min-and-math-max-over-ternarie","errorCode":null,"errorMessage":"Prefer `Math.min()` and `Math.max()` over ternaries for simple comparisons.","messagePattern":"Prefer `Math\\.min\\(\\)` and `Math\\.max\\(\\)` over ternaries for simple comparisons\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_math_min_max.rs","lineNumber":12,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{BinaryExpression, BinaryOperator, Expression},\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, rule::Rule, utils::is_same_expression};\n\nfn prefer_math_min_max_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\n        \"Prefer `Math.min()` and `Math.max()` over ternaries for simple comparisons.\",\n    )\n    .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferMathMinMax;\n\n#[derive(Debug)]\nenum TypeOptions {\n    Min,\n    Max,\n    Unknown,\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///","sourceCodeStart":1,"sourceCodeEnd":30,"githubUrl":"https://github.com/oxc-project/oxc/blob/36ec0ef2bae567d1a8413ada2fe795f1af1f2785/crates/oxc_linter/src/rules/unicorn/prefer_math_min_max.rs#L1-L30","documentation":"Emitted by run of the unicorn prefer-math-min-max rule when it sees a conditional (ternary or if/else) that just clamps one variable relative to another — a min/max pattern. The guard flags re-implementations of Math.min/Math.max that are slower and less readable.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_math_min_max.rs:12 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace the ternary with Math.min(a, b) or Math.max(a, b)","Use Math.max(lower, Math.min(upper, value)) for clamping"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"36ec0ef2bae567d1a8413ada2fe795f1af1f2785","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}