Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

Commit

Permalink
internal/gps: add isPreservedNonGoFile
Browse files Browse the repository at this point in the history
Signed-off-by: Ibrahim AshShohail <ibra.sho@gmail.com>
  • Loading branch information
ibrasho committed Aug 11, 2017
1 parent 0213efa commit 49ea538
Showing 1 changed file with 40 additions and 11 deletions.
51 changes: 40 additions & 11 deletions internal/gps/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,24 @@ const (
)

var (
preservedNonGoFiles = []string{
"LICENSE",
"COPYING",
// licenseFilePrefixes is a list of name prefixes for licesnse files.
licenseFilePrefixes = []string{
"license",
"licence",
"copying",
"unlicense",
"copyright",
"copyleft",
}
// legalFileSubstrings contains substrings that are likey part of a legal
// declaration file.
legalFileSubstrings = []string{
"legal",
"notice",
"disclaimer",
"patent",
"third-party",
"thirdparty",
}
)

Expand Down Expand Up @@ -215,22 +230,36 @@ func calculateNonGoFiles(baseDir string) ([]string, error) {
return nil
}

// Ignore preserved non-Go files. We check for prefix incase the file
// has an extension. For example: LICENSE.md.
for _, prefix := range preservedNonGoFiles {
if strings.HasPrefix(info.Name(), prefix) {
return nil
}
if !isPreservedNonGoFile(info.Name()) {
files = append(files, path)
}

files = append(files, path)

return nil
})

return files, err
}

// isPreservedNonGoFile checks if the file name idicates that the file should be
// preserved. It assumes the file is not a Go file (doesn't have a .go suffix).
func isPreservedNonGoFile(name string) bool {
name = strings.ToLower(name)

for _, prefix := range licenseFilePrefixes {
if strings.HasPrefix(name, prefix) {
return true
}
}

for _, substring := range legalFileSubstrings {
if strings.Contains(name, substring) {
return true
}
}

return false
}

// pruneGoTestFiles deletes all Go test files (*_test.go) within baseDirr.
func pruneGoTestFiles(baseDir string, logger *log.Logger) error {
files, err := calculateGoTestFiles(baseDir)
Expand Down

0 comments on commit 49ea538

Please sign in to comment.