{"record":{"id":"efef8efa5a29482b","repo":"oxc-project/oxc","slug":"use-prefix-name-literals-instead-of-parseint","errorCode":null,"errorMessage":"Use {prefix_name} literals instead of parseInt().","messagePattern":"Use (.+?) literals instead of parseInt\\(\\)\\.","errorType":"validation","errorClass":"OxcDiagnostic","httpStatus":null,"severity":"warning","filePath":"crates/oxc_linter/src/rules/eslint/prefer_numeric_literals.rs","lineNumber":18,"sourceCode":"use oxc_ast::{\n    AstKind,\n    ast::{\n        Argument, CallExpression, Expression, IdentifierReference, MemberExpression,\n        StaticMemberExpression,\n    },\n};\nuse oxc_diagnostics::OxcDiagnostic;\nuse oxc_macros::declare_oxc_lint;\nuse oxc_span::Span;\n\nuse crate::{\n    AstNode, ast_util::get_symbol_id_of_variable, context::LintContext, rule::Rule,\n    utils::pad_fix_with_token_boundary,\n};\n\nfn prefer_numeric_literals_diagnostic(span: Span, prefix_name: &str) -> OxcDiagnostic {\n    OxcDiagnostic::warn(format!(\"Use {prefix_name} literals instead of parseInt().\"))\n        .with_label(span)\n}\n\n#[derive(Debug, Default, Clone)]\npub struct PreferNumericLiterals;\n\nfn radix_map(base: &str) -> Option<(&'static str, &'static str)> {\n    match base {\n        \"2\" => Some((\"binary\", \"0b\")),\n        \"8\" => Some((\"octal\", \"0o\")),\n        \"16\" => Some((\"hexadecimal\", \"0x\")),\n        _ => None,\n    }\n}\n\ndeclare_oxc_lint!(\n    /// ### What it does\n    ///","sourceCodeStart":1,"sourceCodeEnd":36,"githubUrl":"https://github.com/oxc-project/oxc/blob/e1e7af627c8843ab64044ed466b128fcc21a035b/crates/oxc_linter/src/rules/eslint/prefer_numeric_literals.rs#L1-L36","documentation":"Diagnostic from the oxlint `prefer-numeric-literals` rule. It flags `parseInt(str, radix)` calls where the string is a numeric literal in base 2, 8, or 16, and asks you to use the matching numeric literal prefix (prefer_numeric_literals.rs:18-21). The radix map in the same file maps 2 to binary `0b`, 8 to octal `0o`, and 16 to hexadecimal `0x`, which fills the `{prefix_name}` placeholder.","triggerScenarios":"Enable the rule and write `parseInt(\"1111101110\", 2)`, `parseInt(\"755\", 8)`, or `parseInt(\"1F\", 16)` with a literal string and one of the mapped radixes. The rule checks that `parseInt` resolves to the global (get_symbol_id_of_variable is imported to rule out shadowed bindings).","commonSituations":"Code translating constants from specs (file permissions `0755`, colors `0xFF`, bitmasks) written via parseInt; copied snippets; configs enabling the rule during modernization passes. Note the string must be a static literal — `parseInt(userInput, 16)` stays valid and unflagged.","solutions":["Replace with a prefixed literal: `parseInt(\"755\", 8)` becomes `0o755`; `parseInt(\"10\", 2)` becomes `0b10`; `parseInt(\"FF\", 16)` becomes `0xff` (auto-fixable).","Keep parseInt for genuinely dynamic strings — only literal arguments are reported.","Disable the rule if you deliberately show radix conversion in teaching/test code.","Verify the target runtime supports 0b/0o literals (ES2015+)."],"exampleFix":"// before\nconst mask = parseInt(\"11111111\", 2);\n\n// after\nconst mask = 0b11111111;","handlingStrategy":"validation","validationCode":"// only literal radix strings are flagged — keep dynamic input on parseInt\nconst isStaticLiteral = (s) => /^['\"][0-9a-fA-F]+['\"]$/.test(s); // guard codemod input","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Write radix constants as literals directly: 0b, 0o, 0x prefixes.","Reserve parseInt for runtime-computed strings.","Confirm ES2015+ support in your build targets before migrating."],"tags":["oxlint","eslint","modernization","numbers","es2015"],"backgroundTag":"eslint-prefer-numeric-literals","analyzedSha":"e1e7af627c8843ab64044ed466b128fcc21a035b","analyzedAt":"2026-08-20T07:01:07.079Z","contentChangedAt":"2026-08-20T07:01:07.079Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}