{"record":{"id":"84527c9342123d93","repo":"oxc-project/oxc","slug":"prefer-replacement","errorCode":null,"errorMessage":"Prefer `{replacement}`.","messagePattern":"Prefer `(.+?)`\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"error","filePath":"crates/oxc_linter/src/rules/unicorn/prefer_number_coercion.rs","lineNumber":9,"sourceCode":"use oxc_ast::{AstKind, ast::Expression};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::{GetSpan, Span};\n\nuse crate::{AstNode, context::LintContext, rule::Rule};\n\nfn prefer_number_coercion_diagnostic(span: Span, replacement: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Prefer `{replacement}`.\"))\n        .with_help(format!(\"Replace this call with `{replacement}`.\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferNumberCoercion;\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///\n    /// Prefer `Number()` over `parseFloat()` and base-10 `parseInt()`.\n    ///\n    /// ### Why is this bad?\n    ///\n    /// `parseFloat()` and `parseInt()` parse numeric prefixes and ignore trailing text.\n    /// `Number()` parses the full input, which better matches intent when coercing values.\n    ///\n    /// ### Examples","sourceCodeStart":1,"sourceCodeEnd":27,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/unicorn/prefer_number_coercion.rs#L1-L27","documentation":"Diagnostic from the unicorn/prefer-number-coercion lint rule. It fires when a numeric conversion is done through a slower or less clear path — e.g. `parseInt(x)` for non-string inputs, `parseFloat` where a plain coercion suffices, `+x`-style tricks, or `Number.parseInt`-wrapped coercion — and the message names the preferred replacement (`Number(x)` or `Number.parseInt/parseFloat(x)`). It is a lint suggestion, not a runtime error.","triggerScenarios":"Thrown at crates/oxc_linter/src/rules/unicorn/prefer_number_coercion.rs:9 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Replace the flagged call with the `replacement` named in the message (typically `Number(x)` or `Number.parseInt(x, 10)`)","Pass a radix to `Number.parseInt` when parsing strings","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"}