Skip to content

Commit 21b3833

Browse files
authored
Stabilize --fmt subcommand (#3301)
1 parent 2e6bdb8 commit 21b3833

6 files changed

Lines changed: 21 additions & 85 deletions

File tree

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,7 +4283,7 @@ Each `justfile` has a canonical formatting with respect to whitespace and
42834283
newlines.
42844284

42854285
You can overwrite the current justfile with a canonically-formatted version
4286-
using the currently-unstable `--fmt` flag:
4286+
using the `--fmt` flag:
42874287

42884288
```console
42894289
$ cat justfile
@@ -4295,15 +4295,18 @@ $ cat justfile
42954295

42964296
some-recipe:
42974297
echo "foo"
4298-
$ just --fmt --unstable
4298+
$ just --fmt
42994299
$ cat justfile
43004300
# A lot of blank lines
43014301

43024302
some-recipe:
43034303
echo "foo"
43044304
```
43054305

4306-
Invoking `just --fmt --check --unstable` runs `--fmt` in check mode. Instead of
4306+
Note that formatting is not covered by any backwards compatibility guarantee
4307+
and is subject to change from time to time.
4308+
4309+
Invoking `just --fmt --check` runs `--fmt` in check mode. Instead of
43074310
overwriting the `justfile`, `just` will exit with an exit code of 0 if it is
43084311
formatted correctly, and will exit with 1 and print a diff if it is not.
43094312

src/subcommand.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -360,23 +360,6 @@ impl Subcommand {
360360
src,
361361
)?;
362362

363-
let unstable = config.unstable
364-
|| ast.items.iter().any(|item| {
365-
matches!(
366-
item,
367-
Item::Set(Set {
368-
value: Setting::Unstable(true),
369-
..
370-
})
371-
)
372-
});
373-
374-
if !unstable {
375-
return Err(Error::UnstableFeature {
376-
unstable_feature: UnstableFeature::FormatSubcommand,
377-
});
378-
}
379-
380363
let formatted = ast
381364
.color_display(config.color.use_color(UseColor::Never))
382365
.to_string();

src/unstable_feature.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use super::*;
22

33
#[derive(Copy, Clone, Debug, PartialEq, Ord, Eq, PartialOrd)]
44
pub(crate) enum UnstableFeature {
5-
FormatSubcommand,
65
LogicalOperators,
76
UserDefinedFunction,
87
WhichFunction,
@@ -11,7 +10,6 @@ pub(crate) enum UnstableFeature {
1110
impl Display for UnstableFeature {
1211
fn fmt(&self, f: &mut Formatter) -> fmt::Result {
1312
match self {
14-
Self::FormatSubcommand => write!(f, "The `--fmt` command is currently unstable."),
1513
Self::LogicalOperators => write!(
1614
f,
1715
"The logical operators `&&` and `||` are currently unstable."

tests/choose.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ fn skip_private_recipes() {
8383
#[test]
8484
fn recipes_in_submodules_can_be_chosen() {
8585
Test::new()
86-
.args(["--unstable", "--choose"])
86+
.arg("--choose")
8787
.env("JUST_CHOOSER", "head -n10")
8888
.write("bar.just", "baz:\n echo BAZ")
8989
.justfile(

tests/format.rs

Lines changed: 8 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,5 @@
11
use super::*;
22

3-
#[test]
4-
fn unstable_not_passed() {
5-
Test::new()
6-
.arg("--fmt")
7-
.justfile("")
8-
.stderr_regex("error: The `--fmt` command is currently unstable..*")
9-
.failure();
10-
}
11-
123
#[test]
134
fn check_without_fmt() {
145
Test::new()
@@ -25,7 +16,6 @@ fn check_without_fmt() {
2516
#[test]
2617
fn check_ok() {
2718
Test::new()
28-
.arg("--unstable")
2919
.arg("--fmt")
3020
.arg("--check")
3121
.justfile(
@@ -50,7 +40,6 @@ fn check_ok() {
5040
#[test]
5141
fn check_found_diff() {
5242
Test::new()
53-
.arg("--unstable")
5443
.arg("--fmt")
5544
.arg("--check")
5645
.justfile("x:=``\n")
@@ -71,7 +60,6 @@ fn check_found_diff() {
7160
#[test]
7261
fn check_found_diff_quiet() {
7362
Test::new()
74-
.arg("--unstable")
7563
.arg("--fmt")
7664
.arg("--check")
7765
.arg("--quiet")
@@ -83,7 +71,6 @@ fn check_found_diff_quiet() {
8371
fn check_diff_color() {
8472
Test::new()
8573
.justfile("x:=``\n")
86-
.arg("--unstable")
8774
.arg("--fmt")
8875
.arg("--check")
8976
.arg("--color")
@@ -93,30 +80,6 @@ fn check_diff_color() {
9380
.failure();
9481
}
9582

96-
#[test]
97-
fn unstable_passed() {
98-
let tmp = tempdir();
99-
100-
let justfile = tmp.path().join("justfile");
101-
102-
fs::write(&justfile, "x := 'hello' ").unwrap();
103-
104-
let output = Command::new(JUST)
105-
.current_dir(tmp.path())
106-
.arg("--fmt")
107-
.arg("--unstable")
108-
.output()
109-
.unwrap();
110-
111-
if !output.status.success() {
112-
eprintln!("{}", String::from_utf8_lossy(&output.stderr));
113-
eprintln!("{}", String::from_utf8_lossy(&output.stdout));
114-
panic!("justfile failed with status: {}", output.status);
115-
}
116-
117-
assert_eq!(fs::read_to_string(&justfile).unwrap(), "x := 'hello'\n");
118-
}
119-
12083
#[test]
12184
fn write_error() {
12285
// skip this test if running as root, since root can write files even if
@@ -132,7 +95,7 @@ fn write_error() {
13295

13396
let test = Test::with_tempdir(tempdir)
13497
.no_justfile()
135-
.args(["--fmt", "--unstable"])
98+
.arg("--fmt")
13699
.stderr_regex(if cfg!(windows) {
137100
r"error: Failed to write justfile to `.*`: Access is denied. \(os error 5\)\n"
138101
} else {
@@ -1438,17 +1401,13 @@ fn multi_argument_attribute() {
14381401
Test::new()
14391402
.justfile(
14401403
"
1441-
set unstable
1442-
14431404
[script('a', 'b', 'c')]
14441405
foo:
14451406
",
14461407
)
14471408
.arg("--dump")
14481409
.stdout(
14491410
"
1450-
set unstable
1451-
14521411
[script('a', 'b', 'c')]
14531412
foo:
14541413
",
@@ -1461,8 +1420,6 @@ fn doc_attribute_suppresses_comment() {
14611420
Test::new()
14621421
.justfile(
14631422
"
1464-
set unstable
1465-
14661423
# COMMENT
14671424
[doc('ATTRIBUTE')]
14681425
foo:
@@ -1471,8 +1428,6 @@ fn doc_attribute_suppresses_comment() {
14711428
.arg("--dump")
14721429
.stdout(
14731430
"
1474-
set unstable
1475-
14761431
# COMMENT
14771432
[doc('ATTRIBUTE')]
14781433
foo:
@@ -1493,10 +1448,7 @@ fn unchanged_justfiles_are_not_written_to_disk() {
14931448
permissions.set_readonly(true);
14941449
fs::set_permissions(&justfile, permissions).unwrap();
14951450

1496-
Test::with_tempdir(tmp)
1497-
.no_justfile()
1498-
.args(["--fmt", "--unstable"])
1499-
.success();
1451+
Test::with_tempdir(tmp).no_justfile().arg("--fmt").success();
15001452
}
15011453

15021454
#[test]
@@ -1656,7 +1608,7 @@ fn arg_attribute_help() {
16561608
#[test]
16571609
fn missing_import_file() {
16581610
Test::new()
1659-
.args(["--unstable", "--fmt", "--check"])
1611+
.args(["--fmt", "--check"])
16601612
.justfile("import 'foo'\n")
16611613
.test_round_trip(false)
16621614
.success();
@@ -1665,7 +1617,7 @@ fn missing_import_file() {
16651617
#[test]
16661618
fn missing_module_file() {
16671619
Test::new()
1668-
.args(["--unstable", "--fmt", "--check"])
1620+
.args(["--fmt", "--check"])
16691621
.justfile("mod foo\n")
16701622
.test_round_trip(false)
16711623
.success();
@@ -1674,7 +1626,7 @@ fn missing_module_file() {
16741626
#[test]
16751627
fn undefined_variable() {
16761628
Test::new()
1677-
.args(["--unstable", "--fmt", "--check"])
1629+
.args(["--fmt", "--check"])
16781630
.justfile(
16791631
"
16801632
foo:
@@ -1688,7 +1640,7 @@ fn undefined_variable() {
16881640
#[test]
16891641
fn indentation_two_spaces() {
16901642
Test::new()
1691-
.args(["--unstable", "--fmt", "--check", "--indentation", " "])
1643+
.args(["--fmt", "--check", "--indentation", " "])
16921644
.justfile("foo:\n echo bar\n")
16931645
.test_round_trip(false)
16941646
.success();
@@ -1697,7 +1649,7 @@ fn indentation_two_spaces() {
16971649
#[test]
16981650
fn indentation_tab() {
16991651
Test::new()
1700-
.args(["--unstable", "--fmt", "--check", "--indentation", "\t"])
1652+
.args(["--fmt", "--check", "--indentation", "\t"])
17011653
.justfile("foo:\n\techo bar\n")
17021654
.test_round_trip(false)
17031655
.success();
@@ -1706,7 +1658,7 @@ fn indentation_tab() {
17061658
#[test]
17071659
fn indentation_check_with_custom() {
17081660
Test::new()
1709-
.args(["--unstable", "--fmt", "--check", "--indentation", " "])
1661+
.args(["--fmt", "--check", "--indentation", " "])
17101662
.justfile("foo:\n echo bar\n")
17111663
.test_round_trip(false)
17121664
.stdout(" foo:\n- echo bar\n+ echo bar\n")

tests/unstable.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@ fn set_unstable_true_with_env_var() {
1616
fn set_unstable_false_with_env_var() {
1717
for val in ["0", "", "false"] {
1818
Test::new()
19-
.justfile("")
20-
.args(["--fmt"])
19+
.justfile("f(a) := a")
20+
.arg("--dump")
2121
.env("JUST_UNSTABLE", val)
22-
.stderr_regex("error: The `--fmt` command is currently unstable.*")
22+
.stderr_regex("error: User-defined functions are currently unstable.*")
2323
.failure();
2424
}
2525
}
2626

2727
#[test]
2828
fn set_unstable_false_with_env_var_unset() {
2929
Test::new()
30-
.justfile("")
31-
.args(["--fmt"])
32-
.stderr_regex("error: The `--fmt` command is currently unstable.*")
30+
.justfile("f(a) := a")
31+
.arg("--dump")
32+
.stderr_regex("error: User-defined functions are currently unstable.*")
3333
.failure();
3434
}
3535

0 commit comments

Comments
 (0)