{"record":{"id":"c3dba950698a1f4f","repo":"oxc-project/oxc","slug":"prefer-math-good-method-x-over-bad-method","errorCode":null,"errorMessage":"Prefer `Math.{good_method}(x)` over `{bad_method}`","messagePattern":"Prefer `Math\\.(.+?)\\(x\\)` over `(.+?)`","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_modern_math_apis.rs","lineNumber":23,"sourceCode":"use oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\nuse oxc_syntax::operator::BinaryOperator;\n\nuse crate::{\n    AstNode, ast_util::is_method_call, context::LintContext, rule::Rule, utils::is_same_expression,\n};\n\nfn prefer_math_abs(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `Math.abs(x)` over alternatives\").with_label(span)\n}\n\nfn prefer_math_hypot(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `Math.hypot(…)` over alternatives\").with_label(span)\n}\n\nfn prefer_math_log_n(span: Span, good_method: &str, bad_method: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Prefer `Math.{good_method}(x)` over `{bad_method}`\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferModernMathApis;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Checks for usage of legacy patterns for mathematical operations.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Modern JavaScript provides more concise and readable alternatives to legacy patterns.\n    ///\n    /// Currently, the following cases are checked:\n    ///  - Prefer `Math.log10(x)` over alternatives\n    ///  - Prefer `Math.hypot(…)` over alternatives","sourceCodeStart":5,"sourceCodeEnd":41,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_modern_math_apis.rs#L5-L41","documentation":"Diagnostic from the unicorn/prefer-modern-math-apis lint rule. It fires when a logarithm is computed in a base other than e via division or exponent tricks, e.g. `Math.log(x) / Math.LN2` or `Math.log(x) / Math.log(base)`; the dedicated methods `Math.log2(x)` and `Math.log10(x)` (named as `good_method` in the message) are direct, more accurate, and clearer. The flagged input is the divided-log expression. It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_modern_math_apis.rs:23 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace `Math.log(x) / Math.LN2` with `Math.log2(x)`","Replace `Math.log(x) / Math.log(10)` (or `/ Math.LN10`) with `Math.log10(x)`","Apply the rule's auto-fix"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}