{"record":{"id":"25eeb00b9579a5cf","repo":"oxc-project/oxc","slug":"prefer-over-math-pow","errorCode":null,"errorMessage":"Prefer `**` over `Math.pow`.","messagePattern":"Prefer `\\*\\*` over `Math\\.pow`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/prefer_exponentiation_operator.rs","lineNumber":16,"sourceCode":"use oxc_ast::{AstKind, ast::Expression, match_member_expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\nuse oxc_syntax::precedence::{GetPrecedence, Precedence};\n\nuse crate::{\n    AstNode, ast_util::is_method_call, context::LintContext, globals::GLOBAL_OBJECT_NAMES,\n    rule::Rule, utils::get_precedence,\n};\n\n#[derive(Debug, Default, Clone)]\npub struct PreferExponentiationOperator;\n\nfn prefer_exponentian_operator_diagnostic(span: Span) -> OxcDiagnostic {\n    OxcDiagnostic::warn(\"Prefer `**` over `Math.pow`.\")\n        .with_help(\"Replace `Math.pow(a, b)` with `a ** b`.\")\n        .with_label(span)\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Disallow the use of `Math.pow` in favor of the `**` operator.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// Introduced in ES2016, the infix exponentiation operator `**` is an alternative for the\n    /// standard `Math.pow` function. Infix notation is considered to be more readable and thus more\n    /// preferable than the function notation.\n    ///\n    /// ### Examples\n    ///\n    /// Examples of **incorrect** code for this rule:","sourceCodeStart":1,"sourceCodeEnd":34,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/prefer_exponentiation_operator.rs#L1-L34","documentation":"Diagnostic from the oxlint `prefer-exponentiation-operator` rule. It flags calls to `Math.pow(a, b)` and recommends the ES2016 infix operator `a ** b` (prefer_exponentiation_operator.rs:16-20). The rule recognizes `Math.pow` accessed via any global object name (GLOBAL_OBJECT_NAMES is imported in the file) so `window.Math.pow` is also caught.","triggerScenarios":"Enable the rule and write `Math.pow(x, 2)`, `globalThis.Math.pow(2, n)`, or `Math.pow(a + b, 2)` in JS/TS. Auto-fix applies where precedence allows (the file imports precedence helpers to decide safe parenthesization).","commonSituations":"Code written before ES2016 or targeting old runtimes; snippets copied from older docs; transpiled output; cases like `Math.pow(-x, 2)` or nested exponents where the fixer must add parentheses to preserve precedence — these may be reported without a fix.","solutions":["Replace the call: `Math.pow(a, b)` becomes `a ** b` (run `oxlint --fix`).","Parenthesize compound bases/exponents to keep precedence explicit: `Math.pow(a + b, 2)` becomes `(a + b) ** 2`.","If you must support pre-2016 runtimes without transpilation, disable the rule for those files.","Inline-disable for numeric-edge test fixtures that intentionally exercise Math.pow."],"exampleFix":"// before\nconst area = Math.pow(radius, 2);\n\n// after\nconst area = radius ** 2;","handlingStrategy":"validation","validationCode":"// no config for this rule — verify target runtime supports ** (ES2015+)\n// engines in package.json: { \"node\": \">=16\" }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Prefer `a ** b` over `Math.pow(a, b)` in new code.","Parenthesize compound operands to keep precedence explicit for the fixer and readers.","Check browserslist/engines before enabling if you support old runtimes."],"tags":["oxlint","eslint","es2016","math","modernization"],"backgroundTag":"eslint-prefer-exponentiation-operator","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"}