Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions crates/oxc_linter/src/rules/eslint/no_loss_of_precision.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::borrow::Cow;

use cow_utils::CowUtils;
use oxc_ast::{ast::NumericLiteral, AstKind};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
Expand Down Expand Up @@ -182,16 +183,9 @@ impl<'a> RawNum<'a> {
}

impl NoLossOfPrecision {
fn get_raw<'a>(node: &'a NumericLiteral) -> Cow<'a, str> {
if node.raw.contains('_') {
Cow::Owned(node.raw.replace('_', ""))
} else {
Cow::Borrowed(node.raw)
}
}

fn not_base_ten_loses_precision(node: &'_ NumericLiteral) -> bool {
let raw = Self::get_raw(node).to_uppercase();
let raw = node.raw.cow_replace('_', "");
let raw = raw.cow_to_uppercase();
#[allow(clippy::cast_possible_truncation, clippy::cast_sign_loss)]
// AST always store number as f64, need a cast to format in bin/oct/hex
let value = node.value as u64;
Expand All @@ -206,7 +200,7 @@ impl NoLossOfPrecision {
}

fn base_ten_loses_precision(node: &'_ NumericLiteral) -> bool {
let raw = Self::get_raw(node);
let raw = node.raw.cow_replace('_', "");
let Some(raw) = Self::normalize(&raw) else {
return true;
};
Expand Down