this repo has no description
0
fork

Configure Feed

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

internal/mod/modimports: exclude hidden CUE files

The `modimports` logic should exclude "hidden" CUE files
just as it excludes directories.

For #3795

Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I9219cd58cf7a02adaed5774af71669596849832e
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1211242
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>

+13 -10
+2 -6
cmd/cue/cmd/testdata/script/eval_hidden.txtar
··· 7 7 cmp stdout expect-stdout-underscore 8 8 9 9 # Ensure package eval excludes both for completeness 10 - # TODO fix this 11 - ! exec cue eval . 12 - cmp stderr expect-stderr-pkg 13 - # cmp stdout expect-stdout-pkg 10 + exec cue eval . 11 + cmp stdout expect-stdout-pkg 14 12 15 13 -- .foo.cue -- 16 14 package foo ··· 32 30 b: 42 33 31 -- expect-stdout-pkg -- 34 32 c: 42 35 - -- expect-stderr-pkg -- 36 - found packages "bar" (.bar.cue) and "foo" (.foo.cue) in "."
+11 -1
internal/mod/modimports/modimports.go
··· 105 105 // Directories are never package files, even when their filename ends with ".cue". 106 106 continue 107 107 } 108 + if isHidden(e.Name()) { 109 + continue 110 + } 108 111 pkgName, cont := yieldPackageFile(fsys, path.Join(dir, e.Name()), selectPackage, yield) 109 112 if !cont { 110 113 return ··· 177 180 // in subdirectories. 178 181 for _, entry := range entries { 179 182 if entry.IsDir() { 183 + continue 184 + } 185 + if isHidden(entry.Name()) { 180 186 continue 181 187 } 182 188 fpath := path.Join(fpath, entry.Name()) ··· 190 196 if !entry.IsDir() { 191 197 continue 192 198 } 193 - if name == "cue.mod" || strings.HasPrefix(name, ".") || strings.HasPrefix(name, "_") { 199 + if name == "cue.mod" || isHidden(name) { 194 200 continue 195 201 } 196 202 fpath := path.Join(fpath, name) ··· 260 266 pf.Syntax = syntax 261 267 return syntax.PackageName(), yield(pf, nil) 262 268 } 269 + 270 + func isHidden(name string) bool { 271 + return name == "" || name[0] == '.' || name[0] == '_' 272 + }
-3
internal/mod/modimports/testdata/simple.txtar
··· 1 - TODO fix code so it does not include "hidden" CUE files 2 1 -- want -- 3 2 x.cue "dep1" "dep2:a" "dep2:b" "dep3" 4 3 z.cue 5 - y/.omitted.cue 6 - y/_omitted.cue 7 4 y/y1.cue "dep3" "dep4" 8 5 y/y2.cue 9 6 y/z1.cue