oxc-project/oxc · warning · OxcDiagnostic
Invalid radix parameter, must be an integer between 2 and 36
Error message
Invalid radix parameter, must be an integer between 2 and 36.
What it means
oxlint `eslint/radix`: a radix argument was supplied but its static value cannot be a valid base — the message (radix.rs:26) states it must be an integer between 2 and 36, or a variable that is not `undefined`. Such a call makes `parseInt` return `NaN`, so the rule flags it as a likely typo.
Source
Thrown at crates/oxc_linter/src/rules/eslint/radix.rs:26
use schemars::JsonSchema;
use serde::{Deserialize, Serialize};
use crate::{AstNode, context::LintContext, rule::Rule};
fn missing_parameters(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Missing parameters.")
.with_help("Add parameters for parsing numbers, e.g., `parseInt('10', 10)`.")
.with_label(span)
}
fn missing_radix(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Missing radix parameter.")
.with_help("Add radix parameter `10` for parsing decimal numbers, or specify the appropriate radix for other number formats.")
.with_label(span)
}
fn invalid_radix(span: Span) -> OxcDiagnostic {
OxcDiagnostic::warn("Invalid radix parameter, must be an integer between 2 and 36.")
.with_help("The radix parameter should be an integer between 2 and 36, or a variable that is not `undefined`.")
.with_label(span)
}
// `RadixType` has no effect, it is only here for backward compatibility.
// Without it, the linter will report unknown rule configuration error.
#[derive(Debug, Default, Clone, JsonSchema, Deserialize, Serialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct Radix(RadixType);
#[derive(Debug, Default, Clone, JsonSchema, Deserialize, Serialize)]
#[serde(rename_all = "kebab-case")]
enum RadixType {
/// Always require the radix parameter when using `parseInt()`.
#[default]
Always,
/// Only require the radix parameter when necessary.
AsNeeded,View on GitHub (pinned to e1e7af627c)
Solutions
- Correct the radix to an integer in 2–36: binary 2, octal 8, decimal 10, hex 16.
- If the radix comes from a variable, make sure it is always a valid integer at runtime; the rule only accepts variables it cannot prove invalid.
- Remove an explicit `undefined` second argument — it triggers the same diagnostic.
Example fix
// before const bits = parseInt(bitString, 1); // after const bits = parseInt(bitString, 2);
Defensive patterns
Strategy: validation
Validate before calling
// runtime guard if the radix is variable
function safeParseInt(s, radix) {
if (!Number.isInteger(radix) || radix < 2 || radix > 36) {
throw new RangeError(`Invalid radix ${radix}; must be integer 2-36`);
}
return parseInt(s, radix);
} Type guard
function isValidRadix(r) {
return Number.isInteger(r) && r >= 2 && r <= 36;
} Prevention
- Define radix as named constants (BIN=2, OCT=8, DEC=10, HEX=16) so typos like 1 are obvious.
- Validate variable radices at the boundary with the guard above.
- Never pass an explicit `undefined` second argument.
When it happens
Trigger: `parseInt("11", 1)`, `parseInt("11", 37)`, `parseInt("11", 2.5)`, `parseInt("11", undefined)` — a second argument whose literal value is outside 2–36, non-integral, or explicitly `undefined`.
Common situations: Off-by-one base mistakes (1 for binary instead of 2); passing a constant that was refactored to a bad value; passing `undefined` through from an optional parameter.
Related errors
- Missing parameters.
- Missing radix parameter.
- Empty array binding pattern
- Empty object binding pattern
- Checking inequality with NaN will always return true
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/4c4a3dcfae6c6e74.
Report an issue: GitHub.