fix(rome_js_analyze): `noPrecisionLoss` correctly handle 1 digit ints
MODIFY
crates/rome_js_analyze/src/analyzers/nursery/no_precision_loss.rs
crates/rome_js_analyze/src/analyzers/nursery/no_precision_loss.rs
@@ -194,14 +194,19 @@ impl NormalizedNumber<'_> {
}
fn to_scientific(&self) -> String {
+ let fraction = &self.digits[1..];
+ if fraction.is_empty() && self.digits_rest.is_empty() {
+ format!("{}e{}", &self.digits[..1], self.exponent - 1)
+ } else {
format!(
"{}.{}{}e{}",
&self.digits[..1],
- &self.digits[1..],
+ fraction,
self.digits_rest,
self.exponent - 1
)
}
+ }
fn precision(&self) -> usize {
self.digits.len() + self.digits_rest.len()

MODIFY
crates/rome_js_analyze/tests/specs/nursery/noPrecisionLoss/valid.js
crates/rome_js_analyze/tests/specs/nursery/noPrecisionLoss/valid.js
+var x = 1
var x = 12345
var x = 123.456
var x = -123.456

MODIFY
crates/rome_js_analyze/tests/specs/nursery/noPrecisionLoss/valid.js.snap
crates/rome_js_analyze/tests/specs/nursery/noPrecisionLoss/valid.js.snap
---
source: crates/rome_js_analyze/tests/spec_tests.rs
+assertion_line: 92
expression: valid.js
---
# Input
```js
+var x = 1
var x = 12345
var x = 123.456
var x = -123.456

fix(rome_js_analyze): `noPrecisionLoss` correctly handle 1 digit ints (#4087)