Skip to content

Commit 5936450

Browse files
committed
cmd/fix: allow fix to load all packages in a directory
Unlike `cue eval`, `cue fix` should load and operate on all cue files in a directory, regardless of whether they belong to the same package or not. Fixes #3405 Signed-off-by: Matthew Sackman <[email protected]> Change-Id: If79c6d019b9496cfefc833d3fa5e5b6a98ae0ade Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1200351 TryBot-Result: CUEcueckoo <[email protected]> Reviewed-by: Daniel Martí <[email protected]> Unity-Result: CUE porcuepine <[email protected]>
1 parent e505402 commit 5936450

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

cmd/cue/cmd/fix.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,9 @@ func runFixAll(cmd *Command, args []string) error {
7474
}
7575

7676
instances := load.Instances(args, &load.Config{
77-
Tests: true,
78-
Tools: true,
77+
Tests: true,
78+
Tools: true,
79+
Package: "*",
7980
})
8081

8182
errs := fix.Instances(instances, opts...)

cmd/cue/cmd/testdata/script/fix.txtar

+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
exec cue fix ./...
2+
# Make sure we fix all files in a directory, even if they're a mix of packages (or no packages).
3+
cmp p/one.cue p/one.cue.fixed
4+
cmp p/two.cue p/two.cue.fixed
5+
# TODO: the following cmp fails because of a bug in fix/fix.go
6+
! cmp p/three.cue p/three.cue.fixed
7+
# TODO: the added imports have unnecessary name-mangling. https://cuelang.org/issue/3408
8+
-- p/one.cue --
9+
package one
10+
11+
out: ["foo"] + ["bar"]
12+
-- p/two.cue --
13+
package two
14+
15+
out: 3 * ["baz"]
16+
-- p/three.cue --
17+
out: ["a"] + ((["a"]*7) + ["gh"])
18+
-- p/one.cue.fixed --
19+
package one
20+
21+
import list6c6973 "list"
22+
23+
out: list6c6973.Concat([["foo"], ["bar"]])
24+
-- p/two.cue.fixed --
25+
package two
26+
27+
import list6c6973 "list"
28+
29+
out: list6c6973.Repeat(["baz"], 3)
30+
-- p/three.cue.fixed --
31+
import list6c6973 "list"
32+
33+
out: list6c6973.Concat([["a"], (list6c6973.Concat([(list6c6973.Repeat(["a"], 7)), ["gh"]]))])

0 commit comments

Comments
 (0)