oxc-project/oxc · error · OxcDiagnostic
Use `Number.{method_name}` instead of the global `{method_na
Error message
Use `Number.{method_name}` instead of the global `{method_name}` What it means
Diagnostic from the unicorn/prefer-number-properties lint rule. It fires when a deprecated global numeric function or constant is used — e.g. `parseInt`, `parseFloat`, `isNaN`, `isFinite`, `NaN`, `Infinity` (named in the message) — instead of the ES2015+ equivalents on the `Number` namespace (`Number.parseInt`, `Number.isNaN`, `Number.NaN`, ...). The `Number.*` forms avoid implicit global coercion and are the standardized API. It is a lint suggestion, not a runtime error.
Source
Thrown at crates/oxc_linter/src/rules/unicorn/prefer_number_properties.rs:20
AstKind,
ast::{Expression, UnaryExpression, UnaryOperator, match_member_expression},
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_span::{GetSpan, Span};
use schemars::JsonSchema;
use serde::Deserialize;
use crate::{
AstNode,
context::LintContext,
fixer::RuleFixer,
globals::GLOBAL_OBJECT_NAMES,
rule::{DefaultRuleConfig, Rule},
};
fn prefer_number_properties_diagnostic(span: Span, method_name: &str) -> OxcDiagnostic {
OxcDiagnostic::warn(format!("Use `Number.{method_name}` instead of the global `{method_name}`"))
.with_help(format!("Replace it with `Number.{method_name}`"))
.with_label(span)
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct PreferNumberProperties(Box<PreferNumberPropertiesConfig>);
impl std::ops::Deref for PreferNumberProperties {
type Target = PreferNumberPropertiesConfig;
fn deref(&self) -> &Self::Target {
&self.0
}
}
#[derive(Debug, Clone, JsonSchema, Deserialize)]
#[serde(rename_all = "camelCase", default, deny_unknown_fields)]
pub struct PreferNumberPropertiesConfig {View on GitHub (pinned to e1e7af627c)
Solutions
- Replace `parseInt(x, r)` with `Number.parseInt(x, r)`
- Replace `isNaN`/`isFinite` with `Number.isNaN`/`Number.isFinite` (note the stricter, non-coercing semantics)
- Replace bare `NaN`/`Infinity` with `Number.NaN`/`Number.POSITIVE_INFINITY`
- Apply the rule's auto-fix
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at crates/oxc_linter/src/rules/unicorn/prefer_number_properties.rs:20 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20).
Data as JSON: /api/errors/745cb695e640b147.
Report an issue: GitHub.