Repository: casey/just (rust)

Issue:
Compatibility between `--init` & `--fmt`
The file produced by `--init` should generate a justfile which is formatted as expected by `--fmt`. Currently it is not.

```
❯ just --init
Wrote justfile to `/tmp/justfile`

❯ just --check --unstable --fmt
 default:
-       echo 'Hello, world!'
+    echo 'Hello, world!'
error: Formatted justfile differs from original.

Pull request description:
Improve --init/--fmt compatibility (#1115)
The justfile produced by `--init` should be formatted as expected by `--fmt`.

This fixes #1115.

Patch:
diff --git a/src/subcommand.rs b/src/subcommand.rs
index e6744860..64ba5736 100644
--- a/src/subcommand.rs
+++ b/src/subcommand.rs
@@ -1,6 +1,6 @@
 use crate::common::*;
 
-const INIT_JUSTFILE: &str = "default:\n\techo 'Hello, world!'\n";
+const INIT_JUSTFILE: &str = "default:\n    echo 'Hello, world!'\n";
 
 #[derive(PartialEq, Clone, Debug)]
 pub(crate) enum Subcommand {


Test patch:
diff --git a/tests/init.rs b/tests/init.rs
index 0fc8ce49..27888864 100644
--- a/tests/init.rs
+++ b/tests/init.rs
@@ -1,6 +1,6 @@
 use crate::common::*;
 
-const EXPECTED: &str = "default:\n\techo 'Hello, world!'\n";
+const EXPECTED: &str = "default:\n    echo 'Hello, world!'\n";
 
 #[test]
 fn current_dir() {
@@ -188,3 +188,19 @@ fn justfile_and_working_directory() {
     EXPECTED
   );
 }
+
+#[test]
+fn fmt_compatibility() {
+  let tempdir = Test::new()
+    .no_justfile()
+    .arg("--init")
+    .stderr_regex("Wrote justfile to `.*`\n")
+    .run();
+  Test::with_tempdir(tempdir)
+    .no_justfile()
+    .arg("--unstable")
+    .arg("--check")
+    .arg("--fmt")
+    .status(EXIT_SUCCESS)
+    .run();
+}