< Summary - Repometa Coverage

Information
Class: walker
Assembly: repometa
File(s): /home/runner/work/repometa/repometa/walker.go
Line coverage
74%
Covered lines: 40
Uncovered lines: 14
Coverable lines: 54
Total lines: 128
Line coverage: 74%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
walk0%00100%
walkDir0%0072.55%

File(s)

/home/runner/work/repometa/repometa/walker.go

#LineLine coverage
 1package repometa
 2
 3import (
 4  "io/fs"
 5  "os"
 6  "path/filepath"
 7  "sort"
 8)
 9
 10// dirVisit is the payload the walker hands each detector for a single
 11// directory. Files contains only non-directory entries (regular files
 12// and other special entries), sorted lexicographically by name.
 13type dirVisit struct {
 14  abs   string
 15  rel   string
 16  files []fs.DirEntry
 17}
 18
 19type walker struct {
 20  root  string
 21  cfg   options
 22  stats ScanStats
 23}
 24
 25func newWalker(root string, cfg options) *walker {
 26  return &walker{root: root, cfg: cfg}
 27}
 28
 29type visitFunc func(dirVisit)
 30
 3431func (w *walker) walk(visit visitFunc) error {
 3432  return w.walkDir(w.root, ".", 0, visit)
 3433}
 34
 10435func (w *walker) walkDir(abs, rel string, depth int, visit visitFunc) error {
 136  if depth > w.cfg.maxDepth {
 137    w.stats.DepthCapHits++
 138    return nil
 139  }
 1940  if w.stats.DirsVisited >= w.cfg.maxDirs {
 1941    w.stats.DirCapHits++
 1942    return nil
 1943  }
 44
 8445  entries, err := os.ReadDir(abs)
 046  if err != nil {
 047    // A permission error on a subdirectory should not abort the
 048    // whole scan; skip it and continue. Any other error at the root
 049    // bubbles up because Scan already stat'd the root.
 050    if rel == "." {
 051      return err
 052    }
 053    return nil
 54  }
 55
 8456  files := make([]fs.DirEntry, 0, len(entries))
 8457  subdirs := make([]fs.DirEntry, 0)
 8458  for _, e := range entries {
 15759    name := e.Name()
 160    if skipDirs[name] {
 161      continue
 62    }
 7063    if e.IsDir() {
 7064      subdirs = append(subdirs, e)
 7065      continue
 66    }
 167    if e.Type()&fs.ModeSymlink != 0 {
 168      w.stats.SymlinksSkipped++
 169      continue
 70    }
 8571    files = append(files, e)
 72  }
 1673  sort.Slice(files, func(i, j int) bool { return files[i].Name() < files[j].Name() })
 4474  sort.Slice(subdirs, func(i, j int) bool { return subdirs[i].Name() < subdirs[j].Name() })
 75
 8476  w.stats.DirsVisited++
 8477  w.stats.FilesSeen += len(files)
 8478
 8479  visit(dirVisit{abs: abs, rel: rel, files: files})
 8480
 7081  for _, sd := range subdirs {
 082    if sd.Type()&fs.ModeSymlink != 0 {
 083      w.stats.SymlinksSkipped++
 084      continue
 85    }
 7086    childAbs := filepath.Join(abs, sd.Name())
 7087    childRel := sd.Name()
 4388    if rel != "." {
 4389      childRel = filepath.Join(rel, sd.Name())
 4390    }
 091    if err := w.walkDir(childAbs, childRel, depth+1, visit); err != nil {
 092      return err
 093    }
 94  }
 8495  return nil
 96}
 97
 98// skipDirs is the hardcoded set of directory names never descended into.
 99// These are unambiguous ecosystem artifacts / caches / tool state that
 100// would explode the walk time without adding component information.
 101// Names that are commonly legitimate source directories in some
 102// codebases (bin, obj, out, env) are intentionally NOT listed here.
 103var skipDirs = map[string]bool{
 104  ".git":          true,
 105  ".hg":           true,
 106  ".svn":          true,
 107  ".idea":         true,
 108  ".vscode":       true,
 109  ".gradle":       true,
 110  ".mvn":          true,
 111  ".next":         true,
 112  ".nuxt":         true,
 113  ".angular":      true,
 114  ".pytest_cache": true,
 115  ".mypy_cache":   true,
 116  ".ruff_cache":   true,
 117  ".tox":          true,
 118  ".terraform":    true,
 119  ".direnv":       true,
 120  "__pycache__":   true,
 121  "node_modules":  true,
 122  ".venv":         true,
 123  "venv":          true,
 124  "vendor":        true,
 125  "target":        true,
 126  "dist":          true,
 127  "build":         true,
 128}

Methods/Properties

walk
walkDir