Repository: jinxdash/prettier-plugin-rust (language: rust)

Issue:
Bug: Prettier removes trailing `.` in floats
### Input code

```rust
fn main() {
    let x: f32 = 10.0;
    let y: f32 = 10.; // <-- here
}
```


### Output code

```rust
fn main() {
    let x: f32 = 10.0;
    let y: f32 = 10; // <-- here
}
```


### Additional context

Prettier should not remove the trailing `.` for floats because it is a valid syntax. 

The expected format should either be `10.` or `10.0`.


Discussion / hints:

Fix patch:
diff --git a/ext/jinx-rust b/ext/jinx-rust
index acd7385..4342234 160000
--- a/ext/jinx-rust
+++ b/ext/jinx-rust
@@ -1,1 +1,1 @@
-Subproject commit acd7385d17af889e45dd82cdaebcbde23e42ef8c
+Subproject commit 4342234c82fcb25f745b8c89df7c6b42bc414aed
diff --git a/src/format/core.ts b/src/format/core.ts
index 783f88c..674e55e 100644
--- a/src/format/core.ts
+++ b/src/format/core.ts
@@ -286,11 +286,10 @@ export function printCommentsInsideEmptyArray(path: AstPath<Node>) {
 export function printNumber(rawNumber: string) {
 	return rawNumber
 		.toLowerCase()
-		.replace(/^([+-]?[\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3")
-		.replace(/^([+-]?[\d.]+)e[+-]?0+$/, "$1")
-		.replace(/^([+-])?\./, "$10.")
-		.replace(/(\.\d+?)0+(?=e|$)/, "$1")
-		.replace(/\.(?=e|$)/, "");
+		.replace(/^([\d.]+e)(?:\+|(-))?0*(\d)/, "$1$2$3")
+		.replace(/^([\d.]+)e[+-]?0+$/, "$1")
+		.replace(/\.(\d+?)0+(?=e|$)/, ".$1")
+		.replace(/\.(?=e|$)/, ".0");
 }
 
 export function printOnOwnLine(node: Node, printed: Doc) {


Test patch:
diff --git a/tests/output-ext/expressions/literal.f.rs b/tests/output-ext/expressions/literal.f.rs
index ca50e1c..183ced1 100644
--- a/tests/output-ext/expressions/literal.f.rs
+++ b/tests/output-ext/expressions/literal.f.rs
@@ -198,7 +198,7 @@ literal";
 
 0.1;
 (1.1).1;
-1;
+1.0;
 
 0b1;
 0B1;
diff --git a/tests/output/issues/0.f.rs b/tests/output/issues/0.f.rs
index 09cfea6..8c187af 100644
--- a/tests/output/issues/0.f.rs
+++ b/tests/output/issues/0.f.rs
@@ -1096,16 +1096,16 @@ fn main() {
 
 fn main() {
   let dv =
-    (2 * m * l * dtheta * dtheta * theta.sin() +
-      3 * m * g * theta.sin() * theta.cos() +
-      4 * u -
-      4 * b * v) /
-    (4 * (M + m) - 3 * m * theta.cos().powi(2));
+    (2.0 * m * l * dtheta * dtheta * theta.sin() +
+      3.0 * m * g * theta.sin() * theta.cos() +
+      4.0 * u -
+      4.0 * b * v) /
+    (4.0 * (M + m) - 3.0 * m * theta.cos().powi(2));
   let ddtheta =
-    (-3 * m * l * dtheta * dtheta * theta.sin() * theta.cos() -
-      6 * (M + m) * g * theta.sin() -
-      6 * (u - b * v) * theta.cos()) /
-    (4 * l * (m + M) - 3 * m * l * theta.cos().powi(2));
+    (-3.0 * m * l * dtheta * dtheta * theta.sin() * theta.cos() -
+      6.0 * (M + m) * g * theta.sin() -
+      6.0 * (u - b * v) * theta.cos()) /
+    (4.0 * l * (m + M) - 3.0 * m * l * theta.cos().powi(2));
   let V: Array2<_> =
     (((&lq + &vi).mapv(f64::exp) - &q) * mi_minus_mi_t.mapv(f64::cos) -
       ((&lq - &vi).mapv(f64::exp) - &q) * mi_plus_mi_t.mapv(f64::cos)) *
@@ -1160,17 +1160,17 @@ fn main() {
       (
         &iR.t() *
         test_covariance *
-        (-2 * &inv_sq_len_scales_i - 2 * &inv_sq_len_scales_i)
+        (-2.0 * &inv_sq_len_scales_i - 2.0 * &inv_sq_len_scales_i)
       ).sum_axis(Axis(0));
   }
   {
     let dSds: Array2<_> =
       r2 *
         (
-          2 * i2SpW.dot(&m_minus_z.as_column()).dot(&m_minus_z.as_row()) -
+          2.0 * i2SpW.dot(&m_minus_z.as_column()).dot(&m_minus_z.as_row()) -
           Array2::<f64>::eye(D)
         ).dot(&i2SpW) -
-      2 * L * &dLds;
+      2.0 * L * &dLds;
   }
   let f = future::poll_fn(move || {
     match tokio_threadpool::blocking(|| f.poll()).unwrap() {
diff --git a/tests/output/issues/14.f.rs b/tests/output/issues/14.f.rs
new file mode 100644
index 0000000..2b2ee63
--- /dev/null
+++ b/tests/output/issues/14.f.rs
@@ -0,0 +1,2 @@
+[10.0, 10.0, 10.0, 10];
+// source: "../../samples/issues/14.rs"
\ No newline at end of file
diff --git a/tests/samples/issues/14.rs b/tests/samples/issues/14.rs
new file mode 100644
index 0000000..c0d63eb
--- /dev/null
+++ b/tests/samples/issues/14.rs
@@ -0,0 +1,1 @@
+[10.00, 10.0, 10., 10];
\ No newline at end of file