this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cmd/cue: print relative paths in fmt --check

For an improved user experience, this changes the `cue fmt --check`
command to print relative paths when badly formatted files are found.
Previously absolute paths were printed.

Signed-off-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
Change-Id: I2364f1b57b77a2cbbe1fde32bd95256ddffd2dad
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1191220
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>

authored by

Noam Dolovich and committed by
Daniel Martí
fc836b19 b40ccea2

+9 -8
+4 -3
cmd/cue/cmd/fmt.go
··· 16 16 17 17 import ( 18 18 "bytes" 19 - "cuelang.org/go/internal/source" 20 19 "fmt" 21 - "github.com/spf13/cobra" 22 20 "os" 23 21 24 22 "cuelang.org/go/cue/ast" ··· 28 26 "cuelang.org/go/cue/load" 29 27 "cuelang.org/go/cue/token" 30 28 "cuelang.org/go/internal/encoding" 29 + "cuelang.org/go/internal/source" 31 30 "cuelang.org/go/tools/fix" 31 + 32 + "github.com/spf13/cobra" 32 33 ) 33 34 34 35 func newFmtCmd(c *Command) *cobra.Command { ··· 120 121 } 121 122 122 123 if check && !bytes.Equal(formatted.Bytes(), original) { 123 - badlyFormattedFiles = append(badlyFormattedFiles, file.Filename) 124 + badlyFormattedFiles = append(badlyFormattedFiles, inst.RelPath(file)) 124 125 } 125 126 } 126 127 }
+5 -5
cmd/cue/cmd/testdata/script/fmt_check.txtar
··· 5 5 exec cue fmt --check - 6 6 7 7 # fails and displays non formatted files 8 - ! exec cue fmt --check not_formatted.cue another_not_formatted.cue 8 + ! exec cue fmt --check not_formatted.cue another/not_formatted.cue 9 9 cmpenv stdout expected-output 10 10 11 11 # files are not modified with --check 12 12 # running twice returns the same file list 13 - ! exec cue fmt --check not_formatted.cue another_not_formatted.cue 13 + ! exec cue fmt --check not_formatted.cue another/not_formatted.cue 14 14 cmpenv stdout expected-output 15 15 16 16 # stdin fails with no output ··· 22 22 foo: "bar" 23 23 -- not_formatted.cue -- 24 24 foo: "bar" 25 - -- another_not_formatted.cue -- 25 + -- another/not_formatted.cue -- 26 26 bar: "baz" 27 27 x: 1 28 28 -- expected-output -- 29 - $WORK${/}another_not_formatted.cue 30 - $WORK${/}not_formatted.cue 29 + not_formatted.cue 30 + another${/}not_formatted.cue