this repo has no description
0
fork

Configure Feed

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

cmd/cue: print paths relative to the current directory in fmt --check

Fixes a bug introduced in https://cuelang.org/cl/1191220 where badly formatted paths
were printed relative to the cue module root instead of
the current working directory.

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

authored by

Noam Dolovich and committed by
Daniel Martí
79ded701 fc836b19

+34 -7
+11 -3
cmd/cue/cmd/fmt.go
··· 18 18 "bytes" 19 19 "fmt" 20 20 "os" 21 + "path/filepath" 21 22 22 23 "cuelang.org/go/cue/ast" 23 24 "cuelang.org/go/cue/build" ··· 121 122 } 122 123 123 124 if check && !bytes.Equal(formatted.Bytes(), original) { 124 - badlyFormattedFiles = append(badlyFormattedFiles, inst.RelPath(file)) 125 + badlyFormattedFiles = append(badlyFormattedFiles, file.Filename) 125 126 } 126 127 } 127 128 } 128 129 129 130 if check && len(badlyFormattedFiles) > 0 { 131 + cwd, _ := os.Getwd() 130 132 stdout := cmd.OutOrStdout() 131 133 for _, f := range badlyFormattedFiles { 132 - if f != "-" { 133 - fmt.Fprintln(stdout, f) 134 + if f == "-" { 135 + continue 136 + } 137 + 138 + relPath, err := filepath.Rel(cwd, f) 139 + if err != nil { 140 + relPath = f 134 141 } 142 + fmt.Fprintln(stdout, relPath) 135 143 } 136 144 os.Exit(1) 137 145 }
+23 -4
cmd/cue/cmd/testdata/script/fmt_check.txtar
··· 1 + cd standalone 2 + 1 3 # succeeds when file is formatted 2 4 exec cue fmt --check formatted.cue 3 5 ··· 18 20 ! exec cue fmt --check - 19 21 ! stdout . 20 22 21 - -- formatted.cue -- 23 + cd ../module 24 + 25 + # files are printed relative to CWD 26 + ! exec cue fmt --check ./... 27 + cmpenv stdout stdout.golden 28 + cd example 29 + ! exec cue fmt --check ./... 30 + cmp stdout stdout.golden 31 + 32 + -- standalone/formatted.cue -- 22 33 foo: "bar" 23 - -- not_formatted.cue -- 34 + -- standalone/not_formatted.cue -- 24 35 foo: "bar" 25 - -- another/not_formatted.cue -- 36 + -- standalone/another/not_formatted.cue -- 26 37 bar: "baz" 27 38 x: 1 28 - -- expected-output -- 39 + -- standalone/expected-output -- 29 40 not_formatted.cue 30 41 another${/}not_formatted.cue 42 + -- module/cue.mod/module.cue -- 43 + module: "example.com" 44 + -- module/stdout.golden -- 45 + example${/}not_formatted.cue 46 + -- module/example/not_formatted.cue -- 47 + foo: "bar" 48 + -- module/example/stdout.golden -- 49 + not_formatted.cue