Skip to content

Commit

Permalink
Merge #81467
Browse files Browse the repository at this point in the history
81467: lint: enable the CODEOWNERS linter on non-clean workdirs r=srosenberg a=knz

Prior to this patch, the linter would bark if there were spurious
files in otherwise-empty unowned directories (e.g. pkg/).

This patch fixes it.

Release note: None

Co-authored-by: Raphael 'kena' Poss <[email protected]>
  • Loading branch information
craig[bot] and knz committed May 19, 2022
2 parents 8facb90 + 1809517 commit fb8e09a
Showing 1 changed file with 38 additions and 13 deletions.
51 changes: 38 additions & 13 deletions pkg/internal/codeowners/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func LintEverythingIsOwned(
".gitignore": {},
"README.md": {},
}
skipGlobs := []string{
"#*#", // editor backup files.
"*~", // editor backup files.
".*", // .DS_Store, vim temp files, etc.
}

// Map of (unowned dir relative to walkRoot) -> (triggering file relative to walkRoot).
// For example, kv/kvserver -> kv/kvserver/foo.go.
Expand All @@ -91,6 +96,7 @@ func LintEverythingIsOwned(
// the file itself as unowned, but most of the time we have
// one owner for the directory and also the failures get less
// noisy by tracking per-directory.
debug("found unowned file: %s", path)
parts := strings.Split(path, string(filepath.Separator))
var ok bool
for i := range parts {
Expand All @@ -102,7 +108,7 @@ func LintEverythingIsOwned(
}
}
if !ok {
debug("unowned: %s", path)
debug("adding unowned: %s", path)
unowned[filepath.Dir(path)] = path
}
}
Expand All @@ -125,20 +131,39 @@ func LintEverythingIsOwned(
return err
}

if _, ok := skip[relPath]; ok {
debug("skipping %s", relPath)
if info.IsDir() {
return filepath.SkipDir
if relPath != "." {
// We only apply filtering to relPath entries that are not ".".
// Directory-level matching for directory a/b is handled when entry "b"
// is matched inside directory "a".

if _, ok := skip[relPath]; ok {
debug("skipping %s", relPath)
if info.IsDir() {
return filepath.SkipDir
}
return nil
}
return nil
}
fname := filepath.Base(relPath)
if _, ok := skip[fname]; ok {
debug("skipping %s", relPath)
if info.IsDir() {
return filepath.SkipDir
for _, g := range skipGlobs {
ok, err := filepath.Match(g, relPath)
if err != nil {
return err
}
if ok {
debug("skipping %s", relPath)
if info.IsDir() {
return filepath.SkipDir
}
return nil
}
}
fname := filepath.Base(relPath)
if _, ok := skip[fname]; ok {
debug("skipping %s", relPath)
if info.IsDir() {
return filepath.SkipDir
}
return nil
}
return nil
}

if info.IsDir() {
Expand Down

0 comments on commit fb8e09a

Please sign in to comment.